t6120: demonstrate weakness in disjoint-root handling

Commit 30b1c7ad9d (describe: don't abort too early when searching tags,
2020-02-26) tried to fix a problem that happens when there are disjoint
histories: to accurately compare the counts for different tags, we need
to keep walking the history longer in order to find a common base.

But its fix misses a case: we may still bail early if we hit the
max_candidates limit, producing suboptimal output. You can see this in
action by adding "--candidates=2" to the tests; we'll stop traversing as
soon as we see the second tag and will produce the wrong answer. I hit
this in practice while trying to teach git-describe not to keep looking
for candidates after we've seen all tags in the repo (effectively adding
--candidates=2, since these toy repos have only two tags each).

This is probably fixable by continuing to walk after hitting the
max-candidates limit, all the way down to a common ancestor of all
candidates. But it's not clear in practice what the preformance
implications would be (it would depend on how long the branches that
hold the candidates are).

So I'm punting on that for now, but I'd like to adjust the tests to be
more resilient, and to document the findings. So this patch:

  1. Adds an extra tag at the bottom of history. This shouldn't change
     the output, but does mean we are more resilient to low values of
     --candidates (e.g., if we start reducing it to the total number of
     tags). This is arguably closer to the real world anyway, where
     you're not going to have just 2 tags, but an arbitrarily long
     history going back in time, possibly with multiple irrelevant tags
     in it (I called the new tag "H" here for "history").

  2. Run the same tests with --candidates=2, which shows that even with
     the current code they can fail if we end the traversal early. That
     leaves a trail for anybody interested in trying to improve the
     behavior.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2024-11-06 16:16:58 -05:00
committed by Junio C Hamano
parent 8f8d6eee53
commit d0e52c1728

View File

@ -19,6 +19,7 @@ TEST_PASSES_SANITIZE_LEAK=true
check_describe () {
indir= &&
outcome=success &&
while test $# != 0
do
case "$1" in
@ -26,6 +27,9 @@ check_describe () {
indir="$2"
shift
;;
--expect-failure)
outcome=failure
;;
*)
break
;;
@ -36,7 +40,7 @@ check_describe () {
expect="$1"
shift
describe_opts="$@"
test_expect_success "describe $describe_opts" '
test_expect_${outcome} "describe $describe_opts" '
git ${indir:+ -C "$indir"} describe $describe_opts >raw &&
sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&
echo "$expect" >expect &&
@ -617,7 +621,7 @@ test_expect_success 'name-rev --annotate-stdin works with commitGraph' '
# B
# o
# \
# H \
# o-----o---o----x
# A
#
@ -627,6 +631,7 @@ test_expect_success 'setup: describe commits with disjoint bases' '
cd disjoint1 &&
echo o >> file && git add file && git commit -m o &&
git tag H -a -m H &&
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 &&
@ -639,8 +644,9 @@ test_expect_success 'setup: describe commits with disjoint bases' '
'
check_describe -C disjoint1 "A-3-gHASH" HEAD
check_describe -C disjoint1 --expect-failure "A-3-gHASH" --candidates=2 HEAD
# B
# H B
# o---o---o------------.
# \
# o---o---x
@ -658,6 +664,7 @@ test_expect_success 'setup: describe commits with disjoint bases 2' '
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 &&
git tag H -a -m H &&
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 main -m x
@ -665,6 +672,7 @@ test_expect_success 'setup: describe commits with disjoint bases 2' '
'
check_describe -C disjoint2 "B-3-gHASH" HEAD
check_describe -C disjoint2 --expect-failure "B-3-gHASH" --candidates=2 HEAD
test_expect_success 'setup misleading taggerdates' '
GIT_COMMITTER_DATE="2006-12-12 12:31" git tag -a -m "another tag" newer-tag-older-commit unique-file~1