Skip to content

Commit 55088ac

Browse files
tamirdgitster
authored andcommitted
describe: limit default ref iteration to tags
Without --all, git describe ignores refs outside refs/tags/. Commit 8a5a188 (Avoid accessing non-tag refs in git-describe unless --all is requested, 2008-02-24) moved this check ahead of object lookup. That avoided loading objects for irrelevant refs, but the backend still has to yield every ref before get_name() can reject it. Pass refs/tags/ to the iterator so the backend can avoid visiting those refs in the first place. The new perf test creates 10,000 unrelated packed refs. It measures: git describe --exact-match HEAD The runtime drops from 0.03(0.01+0.01) to 0.02(0.00+0.00). In a repository with 120,532 refs but only 330 tags, the same command went from 171.7 ms to 9.9 ms. Signed-off-by: Tamir Duberstein <tamird@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 94f0577 commit 55088ac

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

builtin/describe.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ int cmd_describe(int argc,
740740
return ret;
741741
}
742742

743+
if (!all)
744+
for_each_ref_opts.prefix = "refs/tags/";
745+
743746
hashmap_init(&names, commit_name_neq, NULL, 0);
744747
refs_for_each_ref_ext(get_main_ref_store(the_repository),
745748
get_name, NULL, &for_each_ref_opts);

t/perf/p6100-describe.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ test_perf 'describe HEAD with one tag' '
2727
git describe --match=new HEAD
2828
'
2929

30+
test_expect_success 'set up many unrelated refs' '
31+
ref_count=10000 &&
32+
git tag -m tip tip HEAD &&
33+
test_seq -f "create refs/heads/describe-perf/%05d HEAD" $ref_count |
34+
git update-ref --stdin &&
35+
git pack-refs --all
36+
'
37+
38+
test_perf 'describe exact tag with many unrelated refs' '
39+
git describe --exact-match HEAD
40+
'
41+
3042
test_done

0 commit comments

Comments
 (0)