Skip to content

Commit 5142340

Browse files
committed
Merge branch 'jk/describe-perf' into seen
"git describe" optimization. * jk/describe-perf: describe: split "found all tags" and max_candidates logic
2 parents befc29a + db16286 commit 5142340

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

builtin/describe.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,8 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
369369

370370
seen_commits++;
371371

372-
if (match_cnt == max_candidates) {
372+
if (match_cnt == max_candidates ||
373+
match_cnt == hashmap_get_size(&names)) {
373374
gave_up_on = c;
374375
break;
375376
}
@@ -669,8 +670,6 @@ int cmd_describe(int argc,
669670
NULL);
670671
if (!hashmap_get_size(&names) && !always)
671672
die(_("No names found, cannot describe anything."));
672-
if (hashmap_get_size(&names) < max_candidates)
673-
max_candidates = hashmap_get_size(&names);
674673

675674
if (argc == 0) {
676675
if (broken) {

t/t6120-describe.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,4 +715,14 @@ test_expect_success 'describe --broken --dirty with a file with changed stat' '
715715
)
716716
'
717717

718+
test_expect_success '--always with no refs falls back to commit hash' '
719+
git rev-parse HEAD >expect &&
720+
git describe --no-abbrev --always --match=no-such-tag >actual &&
721+
test_cmp expect actual
722+
'
723+
724+
test_expect_success '--exact-match does not show --always fallback' '
725+
test_must_fail git describe --exact-match --always
726+
'
727+
718728
test_done

0 commit comments

Comments
 (0)