Skip to content

Commit bc84f38

Browse files
committed
t6099, t6600: add side-exhaustion regression tests
Add t6099 to test the case where multiple merge-base candidates exist and one is an ancestor of another. This exercises the side-exhaustion optimization in paint_down_to_common together with the remove_redundant safety net in get_merge_bases_many_0. Add a mixed finite/INFINITY test to t6600 where one tip is outside the commit-graph (INFINITY generation) and the other is inside. This exercises the region transition: the walk starts in the INFINITY region where side-exhaustion is disabled, then crosses into the finite region where it can fire. Signed-off-by: Kristofer Karlsson <krka@spotify.com>
1 parent 30c11f9 commit bc84f38

3 files changed

Lines changed: 108 additions & 0 deletions

File tree

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ integration_tests = [
786786
't6041-bisect-submodule.sh',
787787
't6050-replace.sh',
788788
't6060-merge-index.sh',
789+
't6099-merge-base-side-exhaustion.sh',
789790
't6100-rev-list-in-order.sh',
790791
't6101-rev-parse-parents.sh',
791792
't6102-rev-list-unexpected-objects.sh',
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/sh
2+
3+
test_description='merge-base with ancestor among merge-base candidates
4+
5+
Test that merge-base --all correctly handles cases where
6+
multiple merge-base candidates exist and one is an ancestor
7+
of another. The side-exhaustion optimization in
8+
paint_down_to_common may exit before STALE propagation
9+
removes the ancestor, but remove_redundant catches it.
10+
11+
Graph shape (parents are below children):
12+
13+
A ----------- X
14+
|\ /|
15+
| B---------/ |
16+
| | |
17+
e2 \ f2
18+
| | |
19+
e1 d1 f1
20+
\ | /
21+
\ | /
22+
\| /
23+
C
24+
25+
A and X are the two tips.
26+
B and C are both reachable from A and X.
27+
B reaches C through d1.
28+
Only B should appear in merge-base --all output.
29+
'
30+
31+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
32+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
33+
34+
TEST_PASSES_SANITIZE_LEAK=true
35+
. ./test-lib.sh
36+
37+
test_expect_success 'setup ancestor merge-base candidate' '
38+
test_commit C &&
39+
40+
git checkout -b d-chain HEAD &&
41+
test_commit d1 &&
42+
test_commit B &&
43+
44+
git checkout -b e-path C &&
45+
test_commit e1 &&
46+
test_commit e2 &&
47+
48+
git checkout -b f-path C &&
49+
test_commit f1 &&
50+
test_commit f2 &&
51+
52+
git checkout -b branch-A e-path &&
53+
test_merge A B &&
54+
55+
git checkout -b branch-X f-path &&
56+
test_merge X B &&
57+
58+
git commit-graph write --reachable
59+
'
60+
61+
test_expect_success 'merge-base --all excludes ancestor candidate' '
62+
git rev-parse B >expected &&
63+
git merge-base --all A X >actual &&
64+
test_cmp expected actual
65+
'
66+
67+
test_expect_success 'merge-base (single) finds shallowest' '
68+
git rev-parse B >expected &&
69+
git merge-base A X >actual &&
70+
test_cmp expected actual
71+
'
72+
73+
# Without commit-graph: generation numbers are INFINITY,
74+
# side-exhaustion optimization does not fire.
75+
test_expect_success 'merge-base --all without commit-graph' '
76+
rm -f .git/objects/info/commit-graph &&
77+
git rev-parse B >expected &&
78+
git merge-base --all A X >actual &&
79+
test_cmp expected actual
80+
'
81+
82+
test_done

t/t6600-test-reach.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,31 @@ test_expect_success 'get_merge_bases_many:infinity-both-sides' '
297297
test_all_modes get_merge_bases_many
298298
'
299299

300+
test_expect_success 'setup mixed finite/INFINITY topology' '
301+
# Create a commit outside all saved commit-graph files so it always
302+
# has INFINITY generation, while its parent (ps-X) is in the graph
303+
# with a finite generation. Use the ps-* orphan topology so we do
304+
# not pollute the grid-based rev-list tests.
305+
git checkout ps-X &&
306+
test_commit pm-INF
307+
'
308+
309+
test_expect_success 'get_merge_bases_many:mixed-finite-infinity' '
310+
# One tip (pm-INF) is outside the commit-graph with INFINITY
311+
# generation; the other (ps-B) is in the graph with finite
312+
# generation. The walk starts in the INFINITY region and crosses
313+
# into the finite region where side-exhaustion can fire.
314+
cat >input <<-\EOF &&
315+
A:pm-INF
316+
X:ps-B
317+
EOF
318+
{
319+
echo "get_merge_bases_many(A,X):" &&
320+
git rev-parse ps-X
321+
} >expect &&
322+
test_all_modes get_merge_bases_many
323+
'
324+
300325
test_expect_success 'reduce_heads' '
301326
cat >input <<-\EOF &&
302327
X:commit-1-10

0 commit comments

Comments
 (0)