Merge branch 'be/describe-multiroot'

"git describe" in a repository with multiple root commits sometimes
gave up looking for the best tag to describe a given commit with
too early, which has been adjusted.

* be/describe-multiroot:
  describe: don't abort too early when searching tags
This commit is contained in:
Junio C Hamano 2020-03-05 10:43:04 -08:00
commit f3ccd9f0d9
2 changed files with 69 additions and 4 deletions

View File

@ -376,12 +376,26 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
if (!(c->object.flags & t->flag_within))
t->depth++;
}
/* Stop if last remaining path already covered by best candidate(s) */
if (annotated_cnt && !list) {
int best_depth = INT_MAX;
unsigned best_within = 0;
for (cur_match = 0; cur_match < match_cnt; cur_match++) {
struct possible_tag *t = &all_matches[cur_match];
if (t->depth < best_depth) {
best_depth = t->depth;
best_within = t->flag_within;
} else if (t->depth == best_depth) {
best_within |= t->flag_within;
}
}
if ((c->object.flags & best_within) == best_within) {
if (debug)
fprintf(stderr, _("finished search at %s\n"),
oid_to_hex(&c->object.oid));
break;
}
}
while (parents) {
struct commit *p = parents->item;
parse_commit(p);

View File

@ -479,4 +479,55 @@ test_expect_success 'name-rev covers all conditions while looking at parents' '
)
'
# B
# o
# \
# o-----o---o----x
# A
#
test_expect_success 'describe commits with disjoint bases' '
git init disjoint1 &&
(
cd disjoint1 &&
echo o >> file && git add file && git commit -m o &&
echo A >> file && git add file && git commit -m A &&
git tag A -a -m A &&
echo o >> file && git add file && git commit -m o &&
git checkout --orphan branch && rm file &&
echo B > file2 && git add file2 && git commit -m B &&
git tag B -a -m B &&
git merge --no-ff --allow-unrelated-histories master -m x &&
check_describe "A-3-*" HEAD
)
'
# B
# o---o---o------------.
# \
# o---o---x
# A
#
test_expect_success 'describe commits with disjoint bases 2' '
git init disjoint2 &&
(
cd disjoint2 &&
echo A >> file && git add file && GIT_COMMITTER_DATE="2020-01-01 18:00" git commit -m A &&
git tag A -a -m A &&
echo o >> file && git add file && GIT_COMMITTER_DATE="2020-01-01 18:01" git commit -m o &&
git checkout --orphan branch &&
echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:00" git commit -m o &&
echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o &&
echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B &&
git tag B -a -m B &&
git merge --no-ff --allow-unrelated-histories master -m x &&
check_describe "B-3-*" HEAD
)
'
test_done