Skip to content

Commit 748b8d6

Browse files
NanthRgitster
authored andcommitted
describe: enable sparse index for describe
git describe compares the index with the working tree when (and only when) it is run with the "--dirty" flag. This is done by the run_diff_index() function. The function has been made aware of the sparse-index in the series that led to 8d2c373 (Merge branch 'ld/sparse-diff-blame', 2021-12-21). Hence we can just set the requires-full-index to false for "describe". Performance metrics Test HEAD~1 HEAD ------------------------------------------------------------------------------------------------- 2000.2: git describe --dirty (full-v3) 0.08(0.09+0.01) 0.08(0.06+0.03) +0.0% 2000.3: git describe --dirty (full-v4) 0.09(0.07+0.03) 0.08(0.05+0.04) -11.1% 2000.4: git describe --dirty (sparse-v3) 0.88(0.82+0.06) 0.02(0.01+0.05) -97.7% 2000.5: git describe --dirty (sparse-v4) 0.68(0.60+0.08) 0.02(0.02+0.04) -97.1% 2000.6: echo >>new && git describe --dirty (full-v3) 0.08(0.04+0.05) 0.08(0.05+0.04) +0.0% 2000.7: echo >>new && git describe --dirty (full-v4) 0.08(0.07+0.03) 0.08(0.05+0.04) +0.0% 2000.8: echo >>new && git describe --dirty (sparse-v3) 0.75(0.69+0.07) 0.02(0.03+0.03) -97.3% 2000.9: echo >>new && git describe --dirty (sparse-v4) 0.81(0.73+0.09) 0.02(0.01+0.05) -97.5% Signed-off-by: Raghul Nanth A <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8d90352 commit 748b8d6

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

builtin/describe.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
654654
int fd, result;
655655

656656
setup_work_tree();
657+
prepare_repo_settings(the_repository);
658+
the_repository->settings.command_requires_full_index = 0;
657659
repo_read_index(the_repository);
658660
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
659661
NULL, NULL, NULL);

t/perf/p2000-sparse-operations.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ test_expect_success 'setup repo and indexes' '
4343
done &&
4444
4545
git sparse-checkout init --cone &&
46+
git tag -a v1.0 -m "Final" &&
4647
git sparse-checkout set $SPARSE_CONE &&
4748
git checkout -b wide $OLD_COMMIT &&
4849
@@ -125,5 +126,7 @@ test_perf_on_all git checkout-index -f --all
125126
test_perf_on_all git update-index --add --remove $SPARSE_CONE/a
126127
test_perf_on_all "git rm -f $SPARSE_CONE/a && git checkout HEAD -- $SPARSE_CONE/a"
127128
test_perf_on_all git grep --cached --sparse bogus -- "f2/f1/f1/*"
129+
test_perf_on_all git describe --dirty
130+
test_perf_on_all 'echo >>new && git describe --dirty'
128131

129132
test_done

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,31 @@ test_expect_success 'sparse-index is not expanded: stash' '
15141514
ensure_not_expanded stash pop
15151515
'
15161516

1517+
test_expect_success 'describe tested on all' '
1518+
init_repos &&
1519+
1520+
# Add tag to be read by describe
1521+
1522+
run_on_all git tag -a v1.0 -m "Version 1" &&
1523+
test_all_match git describe --dirty &&
1524+
run_on_all rm g &&
1525+
test_all_match git describe --dirty
1526+
'
1527+
1528+
1529+
test_expect_success 'sparse-index is not expanded: describe' '
1530+
init_repos &&
1531+
1532+
# Add tag to be read by describe
1533+
1534+
git -C sparse-index tag -a v1.0 -m "Version 1" &&
1535+
1536+
ensure_not_expanded describe --dirty &&
1537+
echo "test" >>sparse-index/g &&
1538+
ensure_not_expanded describe --dirty &&
1539+
ensure_not_expanded describe
1540+
'
1541+
15171542
test_expect_success 'sparse index is not expanded: diff' '
15181543
init_repos &&
15191544

0 commit comments

Comments
 (0)