mirror of
https://github.com/git-for-windows/git.git
synced 2026-06-14 15:01:15 -05:00
describe: limit default ref iteration to tags
Without --all, git describe ignores refs outside refs/tags/. Commit
8a5a1884e9 (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>
This commit is contained in:
committed by
Junio C Hamano
parent
94f057755b
commit
55088ac8a4
@@ -740,6 +740,9 @@ int cmd_describe(int argc,
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!all)
|
||||
for_each_ref_opts.prefix = "refs/tags/";
|
||||
|
||||
hashmap_init(&names, commit_name_neq, NULL, 0);
|
||||
refs_for_each_ref_ext(get_main_ref_store(the_repository),
|
||||
get_name, NULL, &for_each_ref_opts);
|
||||
|
||||
@@ -27,4 +27,16 @@ test_perf 'describe HEAD with one tag' '
|
||||
git describe --match=new HEAD
|
||||
'
|
||||
|
||||
test_expect_success 'set up many unrelated refs' '
|
||||
ref_count=10000 &&
|
||||
git tag -m tip tip HEAD &&
|
||||
test_seq -f "create refs/heads/describe-perf/%05d HEAD" $ref_count |
|
||||
git update-ref --stdin &&
|
||||
git pack-refs --all
|
||||
'
|
||||
|
||||
test_perf 'describe exact tag with many unrelated refs' '
|
||||
git describe --exact-match HEAD
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Reference in New Issue
Block a user