]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5324-split-commit-graph.sh
Start the 2.46 cycle
[thirdparty/git.git] / t / t5324-split-commit-graph.sh
CommitLineData
135a7123
DS
1#!/bin/sh
2
3test_description='split commit graph'
da09e7af
JK
4
5TEST_PASSES_SANITIZE_LEAK=true
135a7123 6. ./test-lib.sh
6cf61d0d 7. "$TEST_DIRECTORY"/lib-chunk.sh
135a7123
DS
8
9GIT_TEST_COMMIT_GRAPH=0
d5b873c8 10GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
135a7123
DS
11
12test_expect_success 'setup repo' '
13 git init &&
14 git config core.commitGraph true &&
31b1de6a 15 git config gc.writeCommitGraph false &&
135a7123
DS
16 infodir=".git/objects/info" &&
17 graphdir="$infodir/commit-graphs" &&
82d5aeb1 18 test_oid_cache <<-EOM
e8b63005
AK
19 shallow sha1:2132
20 shallow sha256:2436
82d5aeb1 21
e8b63005
AK
22 base sha1:1408
23 base sha256:1528
665d70ad
DS
24
25 oid_version sha1:1
26 oid_version sha256:2
82d5aeb1 27 EOM
135a7123
DS
28'
29
30graph_read_expect() {
31 NUM_BASE=0
32 if test ! -z $2
33 then
34 NUM_BASE=$2
35 fi
3b0199d4
DS
36 OPTIONS=
37 if test -z "$3"
38 then
39 OPTIONS=" read_generation_data"
40 fi
135a7123 41 cat >expect <<- EOF
e8b63005 42 header: 43475048 1 $(test_oid oid_version) 4 $NUM_BASE
135a7123 43 num_commits: $1
e8b63005 44 chunks: oid_fanout oid_lookup commit_metadata generation_data
3b0199d4 45 options:$OPTIONS
135a7123 46 EOF
4bd0593e 47 test-tool read-graph >output &&
135a7123
DS
48 test_cmp expect output
49}
50
f4d62847
TB
51test_expect_success POSIXPERM 'tweak umask for modebit tests' '
52 umask 022
53'
54
135a7123
DS
55test_expect_success 'create commits and write commit-graph' '
56 for i in $(test_seq 3)
57 do
58 test_commit $i &&
59 git branch commits/$i || return 1
60 done &&
61 git commit-graph write --reachable &&
62 test_path_is_file $infodir/commit-graph &&
63 graph_read_expect 3
64'
65
66graph_git_two_modes() {
a046aa38
ÆAB
67 git ${2:+ -C "$2"} -c core.commitGraph=true $1 >output &&
68 git ${2:+ -C "$2"} -c core.commitGraph=false $1 >expect &&
135a7123
DS
69 test_cmp expect output
70}
71
72graph_git_behavior() {
73 MSG=$1
74 BRANCH=$2
75 COMPARE=$3
a046aa38 76 DIR=$4
135a7123 77 test_expect_success "check normal git operations: $MSG" '
a046aa38
ÆAB
78 graph_git_two_modes "log --oneline $BRANCH" "$DIR" &&
79 graph_git_two_modes "log --topo-order $BRANCH" "$DIR" &&
80 graph_git_two_modes "log --graph $COMPARE..$BRANCH" "$DIR" &&
81 graph_git_two_modes "branch -vv" "$DIR" &&
82 graph_git_two_modes "merge-base -a $BRANCH $COMPARE" "$DIR"
135a7123
DS
83 '
84}
85
86graph_git_behavior 'graph exists' commits/3 commits/1
87
88verify_chain_files_exist() {
89 for hash in $(cat $1/commit-graph-chain)
90 do
91 test_path_is_file $1/graph-$hash.graph || return 1
92 done
93}
94
95test_expect_success 'add more commits, and write a new base graph' '
96 git reset --hard commits/1 &&
97 for i in $(test_seq 4 5)
98 do
99 test_commit $i &&
100 git branch commits/$i || return 1
101 done &&
102 git reset --hard commits/2 &&
103 for i in $(test_seq 6 10)
104 do
105 test_commit $i &&
106 git branch commits/$i || return 1
107 done &&
108 git reset --hard commits/2 &&
109 git merge commits/4 &&
110 git branch merge/1 &&
111 git reset --hard commits/4 &&
112 git merge commits/6 &&
113 git branch merge/2 &&
114 git commit-graph write --reachable &&
115 graph_read_expect 12
116'
117
c523035c
DS
118test_expect_success 'fork and fail to base a chain on a commit-graph file' '
119 test_when_finished rm -rf fork &&
120 git clone . fork &&
121 (
122 cd fork &&
123 rm .git/objects/info/commit-graph &&
124 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
125 test_commit new-commit &&
126 git commit-graph write --reachable --split &&
127 test_path_is_file $graphdir/commit-graph-chain &&
128 test_line_count = 1 $graphdir/commit-graph-chain &&
129 verify_chain_files_exist $graphdir
130 )
131'
132
135a7123
DS
133test_expect_success 'add three more commits, write a tip graph' '
134 git reset --hard commits/3 &&
135 git merge merge/1 &&
136 git merge commits/5 &&
137 git merge merge/2 &&
138 git branch merge/3 &&
139 git commit-graph write --reachable --split &&
140 test_path_is_missing $infodir/commit-graph &&
141 test_path_is_file $graphdir/commit-graph-chain &&
142 ls $graphdir/graph-*.graph >graph-files &&
143 test_line_count = 2 graph-files &&
144 verify_chain_files_exist $graphdir
145'
146
147graph_git_behavior 'split commit-graph: merge 3 vs 2' merge/3 merge/2
148
149test_expect_success 'add one commit, write a tip graph' '
150 test_commit 11 &&
151 git branch commits/11 &&
152 git commit-graph write --reachable --split &&
153 test_path_is_missing $infodir/commit-graph &&
154 test_path_is_file $graphdir/commit-graph-chain &&
155 ls $graphdir/graph-*.graph >graph-files &&
156 test_line_count = 3 graph-files &&
157 verify_chain_files_exist $graphdir
158'
159
160graph_git_behavior 'three-layer commit-graph: commit 11 vs 6' commits/11 commits/6
161
1771be90
DS
162test_expect_success 'add one commit, write a merged graph' '
163 test_commit 12 &&
164 git branch commits/12 &&
165 git commit-graph write --reachable --split &&
166 test_path_is_file $graphdir/commit-graph-chain &&
167 test_line_count = 2 $graphdir/commit-graph-chain &&
168 ls $graphdir/graph-*.graph >graph-files &&
8d84097f 169 test_line_count = 2 graph-files &&
1771be90
DS
170 verify_chain_files_exist $graphdir
171'
172
173graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6
174
c523035c
DS
175test_expect_success 'create fork and chain across alternate' '
176 git clone . fork &&
177 (
178 cd fork &&
179 git config core.commitGraph true &&
180 rm -rf $graphdir &&
181 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
182 test_commit 13 &&
183 git branch commits/13 &&
184 git commit-graph write --reachable --split &&
185 test_path_is_file $graphdir/commit-graph-chain &&
186 test_line_count = 3 $graphdir/commit-graph-chain &&
187 ls $graphdir/graph-*.graph >graph-files &&
188 test_line_count = 1 graph-files &&
189 git -c core.commitGraph=true rev-list HEAD >expect &&
190 git -c core.commitGraph=false rev-list HEAD >actual &&
16110c93
DS
191 test_cmp expect actual &&
192 test_commit 14 &&
193 git commit-graph write --reachable --split --object-dir=.git/objects/ &&
194 test_line_count = 3 $graphdir/commit-graph-chain &&
195 ls $graphdir/graph-*.graph >graph-files &&
196 test_line_count = 1 graph-files
c523035c
DS
197 )
198'
199
a046aa38
ÆAB
200if test -d fork
201then
202 graph_git_behavior 'alternate: commit 13 vs 6' commits/13 origin/commits/6 "fork"
203fi
c523035c 204
c2bc6e6a
DS
205test_expect_success 'test merge stragety constants' '
206 git clone . merge-2 &&
207 (
208 cd merge-2 &&
209 git config core.commitGraph true &&
210 test_line_count = 2 $graphdir/commit-graph-chain &&
211 test_commit 14 &&
212 git commit-graph write --reachable --split --size-multiple=2 &&
213 test_line_count = 3 $graphdir/commit-graph-chain
214
215 ) &&
216 git clone . merge-10 &&
217 (
218 cd merge-10 &&
219 git config core.commitGraph true &&
220 test_line_count = 2 $graphdir/commit-graph-chain &&
221 test_commit 14 &&
222 git commit-graph write --reachable --split --size-multiple=10 &&
223 test_line_count = 1 $graphdir/commit-graph-chain &&
224 ls $graphdir/graph-*.graph >graph-files &&
225 test_line_count = 1 graph-files
226 ) &&
227 git clone . merge-10-expire &&
228 (
229 cd merge-10-expire &&
230 git config core.commitGraph true &&
231 test_line_count = 2 $graphdir/commit-graph-chain &&
232 test_commit 15 &&
b09b785c
DS
233 touch $graphdir/to-delete.graph $graphdir/to-keep.graph &&
234 test-tool chmtime =1546362000 $graphdir/to-delete.graph &&
235 test-tool chmtime =1546362001 $graphdir/to-keep.graph &&
236 git commit-graph write --reachable --split --size-multiple=10 \
237 --expire-time="2019-01-01 12:00 -05:00" &&
c2bc6e6a 238 test_line_count = 1 $graphdir/commit-graph-chain &&
b09b785c
DS
239 test_path_is_missing $graphdir/to-delete.graph &&
240 test_path_is_file $graphdir/to-keep.graph &&
c2bc6e6a
DS
241 ls $graphdir/graph-*.graph >graph-files &&
242 test_line_count = 3 graph-files
243 ) &&
244 git clone --no-hardlinks . max-commits &&
245 (
246 cd max-commits &&
247 git config core.commitGraph true &&
248 test_line_count = 2 $graphdir/commit-graph-chain &&
249 test_commit 16 &&
250 test_commit 17 &&
251 git commit-graph write --reachable --split --max-commits=1 &&
252 test_line_count = 1 $graphdir/commit-graph-chain &&
253 ls $graphdir/graph-*.graph >graph-files &&
254 test_line_count = 1 graph-files
255 )
256'
257
ba41112a
DS
258test_expect_success 'remove commit-graph-chain file after flattening' '
259 git clone . flatten &&
260 (
261 cd flatten &&
262 test_line_count = 2 $graphdir/commit-graph-chain &&
263 git commit-graph write --reachable &&
264 test_path_is_missing $graphdir/commit-graph-chain &&
265 ls $graphdir >graph-files &&
266 test_line_count = 0 graph-files
267 )
268'
269
3da4b609
DS
270corrupt_file() {
271 file=$1
272 pos=$2
273 data="${3:-\0}"
5b15eb39 274 chmod a+w "$file" &&
3da4b609
DS
275 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
276}
277
278test_expect_success 'verify hashes along chain, even in shallow' '
279 git clone --no-hardlinks . verify &&
280 (
281 cd verify &&
282 git commit-graph verify &&
283 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
82d5aeb1 284 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
3da4b609
DS
285 test_must_fail git commit-graph verify --shallow 2>test_err &&
286 grep -v "^+" test_err >err &&
6789275d 287 test_grep "incorrect checksum" err
3da4b609
DS
288 )
289'
290
5f259197
JK
291test_expect_success 'verify notices chain slice which is bogus (base)' '
292 git clone --no-hardlinks . verify-chain-bogus-base &&
293 (
294 cd verify-chain-bogus-base &&
295 git commit-graph verify &&
296 base_file=$graphdir/graph-$(sed -n 1p $graphdir/commit-graph-chain).graph &&
297 echo "garbage" >$base_file &&
298 test_must_fail git commit-graph verify 2>test_err &&
299 grep -v "^+" test_err >err &&
300 grep "commit-graph file is too small" err
301 )
302'
303
304test_expect_success 'verify notices chain slice which is bogus (tip)' '
305 git clone --no-hardlinks . verify-chain-bogus-tip &&
306 (
307 cd verify-chain-bogus-tip &&
308 git commit-graph verify &&
309 tip_file=$graphdir/graph-$(sed -n 2p $graphdir/commit-graph-chain).graph &&
310 echo "garbage" >$tip_file &&
311 test_must_fail git commit-graph verify 2>test_err &&
312 grep -v "^+" test_err >err &&
313 grep "commit-graph file is too small" err
314 )
315'
316
3da4b609
DS
317test_expect_success 'verify --shallow does not check base contents' '
318 git clone --no-hardlinks . verify-shallow &&
319 (
320 cd verify-shallow &&
321 git commit-graph verify &&
322 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
4169d896 323 corrupt_file "$base_file" 1500 "\01" &&
3da4b609
DS
324 git commit-graph verify --shallow &&
325 test_must_fail git commit-graph verify 2>test_err &&
326 grep -v "^+" test_err >err &&
6789275d 327 test_grep "incorrect checksum" err
3da4b609
DS
328 )
329'
330
331test_expect_success 'warn on base graph chunk incorrect' '
332 git clone --no-hardlinks . base-chunk &&
333 (
334 cd base-chunk &&
335 git commit-graph verify &&
336 base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
82d5aeb1 337 corrupt_file "$base_file" $(test_oid base) "\01" &&
5f259197 338 test_must_fail git commit-graph verify --shallow 2>test_err &&
3da4b609 339 grep -v "^+" test_err >err &&
6789275d 340 test_grep "commit-graph chain does not match" err
3da4b609
DS
341 )
342'
343
2d45710c
JK
344test_expect_success 'verify after commit-graph-chain corruption (base)' '
345 git clone --no-hardlinks . verify-chain-base &&
3da4b609 346 (
2d45710c
JK
347 cd verify-chain-base &&
348 corrupt_file "$graphdir/commit-graph-chain" 30 "G" &&
47d06bb0 349 test_must_fail git commit-graph verify 2>test_err &&
3da4b609 350 grep -v "^+" test_err >err &&
6789275d 351 test_grep "invalid commit-graph chain" err &&
2d45710c 352 corrupt_file "$graphdir/commit-graph-chain" 30 "A" &&
47d06bb0 353 test_must_fail git commit-graph verify 2>test_err &&
2d45710c 354 grep -v "^+" test_err >err &&
6789275d 355 test_grep "unable to find all commit-graph files" err
2d45710c
JK
356 )
357'
358
359test_expect_success 'verify after commit-graph-chain corruption (tip)' '
360 git clone --no-hardlinks . verify-chain-tip &&
361 (
362 cd verify-chain-tip &&
363 corrupt_file "$graphdir/commit-graph-chain" 70 "G" &&
5f259197 364 test_must_fail git commit-graph verify 2>test_err &&
2d45710c 365 grep -v "^+" test_err >err &&
a8e23947 366 test_grep "invalid commit-graph chain" err &&
2d45710c 367 corrupt_file "$graphdir/commit-graph-chain" 70 "A" &&
5f259197 368 test_must_fail git commit-graph verify 2>test_err &&
3da4b609 369 grep -v "^+" test_err >err &&
a8e23947 370 test_grep "unable to find all commit-graph files" err
3da4b609
DS
371 )
372'
373
7754a565
JK
374test_expect_success 'verify notices too-short chain file' '
375 git clone --no-hardlinks . verify-chain-short &&
376 (
377 cd verify-chain-short &&
378 git commit-graph verify &&
379 echo "garbage" >$graphdir/commit-graph-chain &&
380 test_must_fail git commit-graph verify 2>test_err &&
381 grep -v "^+" test_err >err &&
382 grep "commit-graph chain file too small" err
383 )
384'
385
5b15eb39
DS
386test_expect_success 'verify across alternates' '
387 git clone --no-hardlinks . verify-alt &&
388 (
389 cd verify-alt &&
390 rm -rf $graphdir &&
391 altdir="$(pwd)/../.git/objects" &&
392 echo "$altdir" >.git/objects/info/alternates &&
393 git commit-graph verify --object-dir="$altdir/" &&
394 test_commit extra &&
395 git commit-graph write --reachable --split &&
396 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
4169d896 397 corrupt_file "$tip_file" 1500 "\01" &&
5b15eb39
DS
398 test_must_fail git commit-graph verify --shallow 2>test_err &&
399 grep -v "^+" test_err >err &&
a8e23947 400 test_grep "incorrect checksum" err
5b15eb39
DS
401 )
402'
403
6cf61d0d
JK
404test_expect_success 'reader bounds-checks base-graph chunk' '
405 git clone --no-hardlinks . corrupt-base-chunk &&
406 (
407 cd corrupt-base-chunk &&
408 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
409 corrupt_chunk_file "$tip_file" BASE clear 01020304 &&
410 git -c core.commitGraph=false log >expect.out &&
411 git -c core.commitGraph=true log >out 2>err &&
412 test_cmp expect.out out &&
413 grep "commit-graph base graphs chunk is too small" err
5b15eb39
DS
414 )
415'
416
e2017c48
DS
417test_expect_success 'add octopus merge' '
418 git reset --hard commits/10 &&
419 git merge commits/3 commits/4 &&
420 git branch merge/octopus &&
421 git commit-graph write --reachable --split &&
73716122 422 git commit-graph verify --progress 2>err &&
9281cd07
TB
423 test_line_count = 1 err &&
424 grep "Verifying commits in commit graph: 100% (18/18)" err &&
6789275d 425 test_grep ! warning err &&
e2017c48
DS
426 test_line_count = 3 $graphdir/commit-graph-chain
427'
428
429graph_git_behavior 'graph exists' merge/octopus commits/12
430
a09c1301
DS
431test_expect_success 'split across alternate where alternate is not split' '
432 git commit-graph write --reachable &&
433 test_path_is_file .git/objects/info/commit-graph &&
434 cp .git/objects/info/commit-graph . &&
435 git clone --no-hardlinks . alt-split &&
436 (
437 cd alt-split &&
31b1de6a 438 rm -f .git/objects/info/commit-graph &&
a09c1301
DS
439 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
440 test_commit 18 &&
441 git commit-graph write --reachable --split &&
442 test_line_count = 1 $graphdir/commit-graph-chain
443 ) &&
444 test_cmp commit-graph .git/objects/info/commit-graph
445'
446
fdbde82f
TB
447test_expect_success '--split=no-merge always writes an incremental' '
448 test_when_finished rm -rf a b &&
449 rm -rf $graphdir $infodir/commit-graph &&
450 git reset --hard commits/2 &&
451 git rev-list HEAD~1 >a &&
452 git rev-list HEAD >b &&
453 git commit-graph write --split --stdin-commits <a &&
454 git commit-graph write --split=no-merge --stdin-commits <b &&
455 test_line_count = 2 $graphdir/commit-graph-chain
456'
457
8a6ac287
TB
458test_expect_success '--split=replace replaces the chain' '
459 rm -rf $graphdir $infodir/commit-graph &&
460 git reset --hard commits/3 &&
461 git rev-list -1 HEAD~2 >a &&
462 git rev-list -1 HEAD~1 >b &&
463 git rev-list -1 HEAD >c &&
464 git commit-graph write --split=no-merge --stdin-commits <a &&
465 git commit-graph write --split=no-merge --stdin-commits <b &&
466 git commit-graph write --split=no-merge --stdin-commits <c &&
467 test_line_count = 3 $graphdir/commit-graph-chain &&
468 git commit-graph write --stdin-commits --split=replace <b &&
469 test_path_is_missing $infodir/commit-graph &&
470 test_path_is_file $graphdir/commit-graph-chain &&
471 ls $graphdir/graph-*.graph >graph-files &&
472 test_line_count = 1 graph-files &&
473 verify_chain_files_exist $graphdir &&
474 graph_read_expect 2
475'
476
b78a556a
TB
477test_expect_success ULIMIT_FILE_DESCRIPTORS 'handles file descriptor exhaustion' '
478 git init ulimit &&
479 (
480 cd ulimit &&
481 for i in $(test_seq 64)
482 do
483 test_commit $i &&
6861ac80 484 run_with_limited_open_files test_might_fail git commit-graph write \
b78a556a
TB
485 --split=no-merge --reachable || return 1
486 done
487 )
488'
489
f4d62847
TB
490while read mode modebits
491do
492 test_expect_success POSIXPERM "split commit-graph respects core.sharedrepository $mode" '
493 rm -rf $graphdir $infodir/commit-graph &&
494 git reset --hard commits/1 &&
495 test_config core.sharedrepository "$mode" &&
496 git commit-graph write --split --reachable &&
497 ls $graphdir/graph-*.graph >graph-files &&
498 test_line_count = 1 graph-files &&
499 echo "$modebits" >expect &&
500 test_modebits $graphdir/graph-*.graph >actual &&
45a4365c
TB
501 test_cmp expect actual &&
502 test_modebits $graphdir/commit-graph-chain >actual &&
f4d62847
TB
503 test_cmp expect actual
504 '
505done <<\EOF
5060666 -r--r--r--
5070600 -r--------
508EOF
509
4f364405
TB
510test_expect_success '--split=replace with partial Bloom data' '
511 rm -rf $graphdir $infodir/commit-graph &&
512 git reset --hard commits/3 &&
513 git rev-list -1 HEAD~2 >a &&
514 git rev-list -1 HEAD~1 >b &&
515 git commit-graph write --split=no-merge --stdin-commits --changed-paths <a &&
516 git commit-graph write --split=no-merge --stdin-commits <b &&
517 git commit-graph write --split=replace --stdin-commits --changed-paths <c &&
518 ls $graphdir/graph-*.graph >graph-files &&
519 test_line_count = 1 graph-files &&
520 verify_chain_files_exist $graphdir
521'
522
150f1157
DS
523test_expect_success 'prevent regression for duplicate commits across layers' '
524 git init dup &&
150f1157 525 git -C dup commit --allow-empty -m one &&
85102ac7 526 git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err &&
6789275d 527 test_grep "attempting to write a commit-graph" err &&
150f1157
DS
528 git -C dup commit-graph write --split=no-merge --reachable &&
529 git -C dup commit --allow-empty -m two &&
530 git -C dup commit-graph write --split=no-merge --reachable &&
531 git -C dup commit --allow-empty -m three &&
532 git -C dup commit-graph write --split --reachable &&
533 git -C dup commit-graph verify
534'
535
1fdc383c
AK
536NUM_FIRST_LAYER_COMMITS=64
537NUM_SECOND_LAYER_COMMITS=16
538NUM_THIRD_LAYER_COMMITS=7
539NUM_FOURTH_LAYER_COMMITS=8
540NUM_FIFTH_LAYER_COMMITS=16
541SECOND_LAYER_SEQUENCE_START=$(($NUM_FIRST_LAYER_COMMITS + 1))
542SECOND_LAYER_SEQUENCE_END=$(($SECOND_LAYER_SEQUENCE_START + $NUM_SECOND_LAYER_COMMITS - 1))
543THIRD_LAYER_SEQUENCE_START=$(($SECOND_LAYER_SEQUENCE_END + 1))
544THIRD_LAYER_SEQUENCE_END=$(($THIRD_LAYER_SEQUENCE_START + $NUM_THIRD_LAYER_COMMITS - 1))
545FOURTH_LAYER_SEQUENCE_START=$(($THIRD_LAYER_SEQUENCE_END + 1))
546FOURTH_LAYER_SEQUENCE_END=$(($FOURTH_LAYER_SEQUENCE_START + $NUM_FOURTH_LAYER_COMMITS - 1))
547FIFTH_LAYER_SEQUENCE_START=$(($FOURTH_LAYER_SEQUENCE_END + 1))
548FIFTH_LAYER_SEQUENCE_END=$(($FIFTH_LAYER_SEQUENCE_START + $NUM_FIFTH_LAYER_COMMITS - 1))
549
550# Current split graph chain:
551#
552# 16 commits (No GDAT)
553# ------------------------
554# 64 commits (GDAT)
555#
556test_expect_success 'setup repo for mixed generation commit-graph-chain' '
557 graphdir=".git/objects/info/commit-graphs" &&
558 test_oid_cache <<-EOF &&
559 oid_version sha1:1
560 oid_version sha256:2
561 EOF
562 git init mixed &&
563 (
564 cd mixed &&
565 git config core.commitGraph true &&
566 git config gc.writeCommitGraph false &&
567 for i in $(test_seq $NUM_FIRST_LAYER_COMMITS)
568 do
569 test_commit $i &&
570 git branch commits/$i || return 1
571 done &&
702110aa 572 git -c commitGraph.generationVersion=2 commit-graph write --reachable --split &&
1fdc383c
AK
573 graph_read_expect $NUM_FIRST_LAYER_COMMITS &&
574 test_line_count = 1 $graphdir/commit-graph-chain &&
575 for i in $(test_seq $SECOND_LAYER_SEQUENCE_START $SECOND_LAYER_SEQUENCE_END)
576 do
577 test_commit $i &&
578 git branch commits/$i || return 1
579 done &&
702110aa 580 git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge &&
1fdc383c
AK
581 test_line_count = 2 $graphdir/commit-graph-chain &&
582 test-tool read-graph >output &&
583 cat >expect <<-EOF &&
584 header: 43475048 1 $(test_oid oid_version) 4 1
585 num_commits: $NUM_SECOND_LAYER_COMMITS
586 chunks: oid_fanout oid_lookup commit_metadata
c78c7a95 587 options:
1fdc383c
AK
588 EOF
589 test_cmp expect output &&
590 git commit-graph verify &&
591 cat $graphdir/commit-graph-chain
592 )
593'
594
595# The new layer will be added without generation data chunk as it was not
596# present on the layer underneath it.
597#
598# 7 commits (No GDAT)
599# ------------------------
600# 16 commits (No GDAT)
601# ------------------------
602# 64 commits (GDAT)
603#
604test_expect_success 'do not write generation data chunk if not present on existing tip' '
605 git clone mixed mixed-no-gdat &&
606 (
607 cd mixed-no-gdat &&
608 for i in $(test_seq $THIRD_LAYER_SEQUENCE_START $THIRD_LAYER_SEQUENCE_END)
609 do
610 test_commit $i &&
611 git branch commits/$i || return 1
612 done &&
613 git commit-graph write --reachable --split=no-merge &&
614 test_line_count = 3 $graphdir/commit-graph-chain &&
615 test-tool read-graph >output &&
616 cat >expect <<-EOF &&
617 header: 43475048 1 $(test_oid oid_version) 4 2
618 num_commits: $NUM_THIRD_LAYER_COMMITS
619 chunks: oid_fanout oid_lookup commit_metadata
c78c7a95 620 options:
1fdc383c
AK
621 EOF
622 test_cmp expect output &&
623 git commit-graph verify
624 )
625'
626
627# Number of commits in each layer of the split-commit graph before merge:
628#
629# 8 commits (No GDAT)
630# ------------------------
631# 7 commits (No GDAT)
632# ------------------------
633# 16 commits (No GDAT)
634# ------------------------
635# 64 commits (GDAT)
636#
637# The top two layers are merged and do not have generation data chunk as layer below them does
638# not have generation data chunk.
639#
640# 15 commits (No GDAT)
641# ------------------------
642# 16 commits (No GDAT)
643# ------------------------
644# 64 commits (GDAT)
645#
646test_expect_success 'do not write generation data chunk if the topmost remaining layer does not have generation data chunk' '
647 git clone mixed-no-gdat mixed-merge-no-gdat &&
648 (
649 cd mixed-merge-no-gdat &&
650 for i in $(test_seq $FOURTH_LAYER_SEQUENCE_START $FOURTH_LAYER_SEQUENCE_END)
651 do
652 test_commit $i &&
653 git branch commits/$i || return 1
654 done &&
655 git commit-graph write --reachable --split --size-multiple 1 &&
656 test_line_count = 3 $graphdir/commit-graph-chain &&
657 test-tool read-graph >output &&
658 cat >expect <<-EOF &&
659 header: 43475048 1 $(test_oid oid_version) 4 2
660 num_commits: $(($NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS))
661 chunks: oid_fanout oid_lookup commit_metadata
c78c7a95 662 options:
1fdc383c
AK
663 EOF
664 test_cmp expect output &&
665 git commit-graph verify
666 )
667'
668
669# Number of commits in each layer of the split-commit graph before merge:
670#
671# 16 commits (No GDAT)
672# ------------------------
673# 15 commits (No GDAT)
674# ------------------------
675# 16 commits (No GDAT)
676# ------------------------
677# 64 commits (GDAT)
678#
679# The top three layers are merged and has generation data chunk as the topmost remaining layer
680# has generation data chunk.
681#
682# 47 commits (GDAT)
683# ------------------------
684# 64 commits (GDAT)
685#
686test_expect_success 'write generation data chunk if topmost remaining layer has generation data chunk' '
687 git clone mixed-merge-no-gdat mixed-merge-gdat &&
688 (
689 cd mixed-merge-gdat &&
690 for i in $(test_seq $FIFTH_LAYER_SEQUENCE_START $FIFTH_LAYER_SEQUENCE_END)
691 do
692 test_commit $i &&
693 git branch commits/$i || return 1
694 done &&
695 git commit-graph write --reachable --split --size-multiple 1 &&
696 test_line_count = 2 $graphdir/commit-graph-chain &&
697 test-tool read-graph >output &&
698 cat >expect <<-EOF &&
699 header: 43475048 1 $(test_oid oid_version) 5 1
700 num_commits: $(($NUM_SECOND_LAYER_COMMITS + $NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS + $NUM_FIFTH_LAYER_COMMITS))
701 chunks: oid_fanout oid_lookup commit_metadata generation_data
3b0199d4 702 options: read_generation_data
1fdc383c
AK
703 EOF
704 test_cmp expect output
705 )
706'
707
708test_expect_success 'write generation data chunk when commit-graph chain is replaced' '
709 git clone mixed mixed-replace &&
710 (
711 cd mixed-replace &&
712 git commit-graph write --reachable --split=replace &&
713 test_path_is_file $graphdir/commit-graph-chain &&
714 test_line_count = 1 $graphdir/commit-graph-chain &&
715 verify_chain_files_exist $graphdir &&
716 graph_read_expect $(($NUM_FIRST_LAYER_COMMITS + $NUM_SECOND_LAYER_COMMITS)) &&
717 git commit-graph verify
718 )
719'
720
135a7123 721test_done