Skip to content

Commit d0e52c1

Browse files
peffgitster
authored andcommitted
t6120: demonstrate weakness in disjoint-root handling
Commit 30b1c7a (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f8d6ee commit d0e52c1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

t/t6120-describe.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ TEST_PASSES_SANITIZE_LEAK=true
1919

2020
check_describe () {
2121
indir= &&
22+
outcome=success &&
2223
while test $# != 0
2324
do
2425
case "$1" in
2526
-C)
2627
indir="$2"
2728
shift
2829
;;
30+
--expect-failure)
31+
outcome=failure
32+
;;
2933
*)
3034
break
3135
;;
@@ -36,7 +40,7 @@ check_describe () {
3640
expect="$1"
3741
shift
3842
describe_opts="$@"
39-
test_expect_success "describe $describe_opts" '
43+
test_expect_${outcome} "describe $describe_opts" '
4044
git ${indir:+ -C "$indir"} describe $describe_opts >raw &&
4145
sed -e "s/-g[0-9a-f]*\$/-gHASH/" <raw >actual &&
4246
echo "$expect" >expect &&
@@ -617,7 +621,7 @@ test_expect_success 'name-rev --annotate-stdin works with commitGraph' '
617621

618622
# B
619623
# o
620-
# \
624+
# H \
621625
# o-----o---o----x
622626
# A
623627
#
@@ -627,6 +631,7 @@ test_expect_success 'setup: describe commits with disjoint bases' '
627631
cd disjoint1 &&
628632
629633
echo o >> file && git add file && git commit -m o &&
634+
git tag H -a -m H &&
630635
echo A >> file && git add file && git commit -m A &&
631636
git tag A -a -m A &&
632637
echo o >> file && git add file && git commit -m o &&
@@ -639,8 +644,9 @@ test_expect_success 'setup: describe commits with disjoint bases' '
639644
'
640645

641646
check_describe -C disjoint1 "A-3-gHASH" HEAD
647+
check_describe -C disjoint1 --expect-failure "A-3-gHASH" --candidates=2 HEAD
642648

643-
# B
649+
# H B
644650
# o---o---o------------.
645651
# \
646652
# o---o---x
@@ -658,13 +664,15 @@ test_expect_success 'setup: describe commits with disjoint bases 2' '
658664
git checkout --orphan branch &&
659665
echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:00" git commit -m o &&
660666
echo o >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:01" git commit -m o &&
667+
git tag H -a -m H &&
661668
echo B >> file2 && git add file2 && GIT_COMMITTER_DATE="2020-01-01 15:02" git commit -m B &&
662669
git tag B -a -m B &&
663670
git merge --no-ff --allow-unrelated-histories main -m x
664671
)
665672
'
666673

667674
check_describe -C disjoint2 "B-3-gHASH" HEAD
675+
check_describe -C disjoint2 --expect-failure "B-3-gHASH" --candidates=2 HEAD
668676

669677
test_expect_success 'setup misleading taggerdates' '
670678
GIT_COMMITTER_DATE="2006-12-12 12:31" git tag -a -m "another tag" newer-tag-older-commit unique-file~1

0 commit comments

Comments
 (0)