t6600: add test cases for side-exhaustion edge cases

Add test cases to t6600-test-reach.sh that exercise edge cases in the
side-exhaustion optimization for paint_down_to_common():

 - in_merge_bases_many:self: commit is both A and one of the X inputs
 - get_merge_bases_many:duplicate-twos: duplicate entries in X list
 - get_merge_bases_many:pending-stale: STALE transition on an
   already-painted commit (ps-* diamond topology)
 - get_merge_bases_many:infinity-both-sides: both tips outside the
   commit-graph with non-monotonic dates (pi-* topology)

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Kristofer Karlsson <krka@spotify.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren
2026-08-06 10:59:34 +00:00
committed by Junio C Hamano
parent 2a980753f3
commit 9e2b8ea70e

View File

@@ -85,6 +85,61 @@ test_expect_success 'setup' '
git branch -f skew-P2 "$skew_P2" &&
git tag skew-M2 "$skew_M2" &&
# Build a small side topology to exercise the (PARENT1|PARENT2) ->
# (PARENT1|PARENT2|STALE) transition in paint_down_to_common(); the
# 10x10 grid above does not exercise it because no merge-base candidate
# there is a descendant of another, so STALE never reaches a
# still-pending candidate.
#
# ps-X
# /|\
# / | \
# ps-Z ps-B ps-W
# | / \ |
# | / \ |
# |/ \|
# ps-T1 ps-T2
#
# where ps-T1=merge(ps-Z,ps-B), ps-T2=merge(ps-W,ps-B), so
# merge-base(ps-T1,ps-T2) = ps-B. During the walk, ps-X transitions
# to (PARENT1|PARENT2) via ps-Z and ps-W before ps-B is dequeued;
# then the STALE-walk from ps-B transitions ps-X to
# (PARENT1|PARENT2|STALE).
git checkout --orphan ps-orphan &&
test_commit ps-X &&
git checkout -b ps-B-br ps-X && test_commit ps-B &&
git checkout -b ps-Z-br ps-X && test_commit ps-Z &&
git checkout -b ps-W-br ps-X && test_commit ps-W &&
git checkout -b ps-T1 ps-Z &&
git merge --no-ff -m ps-T1 ps-B &&
git checkout -b ps-T2 ps-W &&
git merge --no-ff -m ps-T2 ps-B &&
# Build a side topology that lives entirely outside the half
# commit-graph and has non-monotonic commit dates, to exercise the
# INFINITY-gate in paint_down_to_common. With both tips outside
# the graph, generation is INFINITY and the queue falls back to
# commit-date order, which here is non-monotonic.
#
# pi-X (date 500, PARENT1 tip) --> pi-P, pi-D
# pi-D (date 480) --> pi-C
# pi-C (date 200) --> pi-B
# pi-B (date 100, PARENT2 tip) --> pi-P
# pi-P (date 450, root)
#
# merge-base(pi-X, pi-B) = pi-B (it is an ancestor of pi-X and is
# itself one of the queried tips).
git checkout --orphan pi-orphan &&
test_commit --date "@450 +0000" pi-P &&
test_commit --date "@100 +0000" pi-B &&
test_commit --date "@200 +0000" pi-C &&
test_commit --date "@480 +0000" pi-D &&
GIT_AUTHOR_DATE="@500 +0000" GIT_COMMITTER_DATE="@500 +0000" \
git commit-tree -p pi-D -p pi-P -m pi-X pi-D^{tree} >pi-X-oid &&
pi_x="$(cat pi-X-oid)" &&
git branch -f pi-X-br "$pi_x" &&
git tag pi-X "$pi_x" &&
git commit-graph write --reachable &&
mv .git/objects/info/commit-graph commit-graph-full &&
chmod u+w commit-graph-full &&
@@ -182,6 +237,16 @@ test_expect_success 'in_merge_bases_many:miss-heuristic' '
test_all_modes in_merge_bases_many
'
test_expect_success 'in_merge_bases_many:self' '
cat >input <<-\EOF &&
A:commit-6-8
X:commit-5-9
X:commit-6-8
EOF
echo "in_merge_bases_many(A,X):1" >expect &&
test_all_modes in_merge_bases_many
'
test_expect_success 'is_descendant_of:hit' '
cat >input <<-\EOF &&
A:commit-5-7
@@ -219,6 +284,51 @@ test_expect_success 'get_merge_bases_many' '
test_all_modes get_merge_bases_many
'
test_expect_success 'get_merge_bases_many:duplicate-twos' '
cat >input <<-\EOF &&
A:commit-5-7
X:commit-4-8
X:commit-4-8
X:commit-6-6
X:commit-6-6
X:commit-8-3
EOF
{
echo "get_merge_bases_many(A,X):" &&
git rev-parse commit-5-6 \
commit-4-7 | sort
} >expect &&
test_all_modes get_merge_bases_many
'
test_expect_success 'get_merge_bases_many:pending-stale' '
# Exercises the (PARENT1|PARENT2) -> (...|STALE) transition path in
# paint_down_to_common(). See the topology comment in the setup test.
cat >input <<-\EOF &&
A:ps-T1
X:ps-T2
EOF
{
echo "get_merge_bases_many(A,X):" &&
git rev-parse ps-B
} >expect &&
test_all_modes get_merge_bases_many
'
test_expect_success 'get_merge_bases_many:infinity-both-sides' '
# Exercises the push-time INFINITY-gate in paint_down_to_common(). See
# the pi-* topology comment in the setup test.
cat >input <<-\EOF &&
A:pi-X
X:pi-B
EOF
{
echo "get_merge_bases_many(A,X):" &&
git rev-parse pi-B
} >expect &&
test_all_modes get_merge_bases_many
'
test_expect_success 'reduce_heads' '
cat >input <<-\EOF &&
X:commit-1-10