3 test_description
='split commit graph'
6 GIT_TEST_COMMIT_GRAPH
=0
7 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS
=0
9 test_expect_success
'setup repo' '
11 git config core.commitGraph true &&
12 git config gc.writeCommitGraph false &&
13 infodir=".git/objects/info" &&
14 graphdir="$infodir/commit-graphs" &&
36 OPTIONS
=" read_generation_data"
39 header: 43475048 1 $(test_oid oid_version) 4 $NUM_BASE
41 chunks: oid_fanout oid_lookup commit_metadata generation_data
44 test-tool read-graph
>output
&&
45 test_cmp expect output
48 test_expect_success POSIXPERM
'tweak umask for modebit tests' '
52 test_expect_success
'create commits and write commit-graph' '
53 for i in $(test_seq 3)
56 git branch commits/$i || return 1
58 git commit-graph write --reachable &&
59 test_path_is_file $infodir/commit-graph &&
63 graph_git_two_modes
() {
64 git
${2:+ -C "$2"} -c core.commitGraph
=true
$1 >output
&&
65 git
${2:+ -C "$2"} -c core.commitGraph
=false
$1 >expect
&&
66 test_cmp expect output
69 graph_git_behavior
() {
74 test_expect_success
"check normal git operations: $MSG" '
75 graph_git_two_modes "log --oneline $BRANCH" "$DIR" &&
76 graph_git_two_modes "log --topo-order $BRANCH" "$DIR" &&
77 graph_git_two_modes "log --graph $COMPARE..$BRANCH" "$DIR" &&
78 graph_git_two_modes "branch -vv" "$DIR" &&
79 graph_git_two_modes "merge-base -a $BRANCH $COMPARE" "$DIR"
83 graph_git_behavior
'graph exists' commits
/3 commits
/1
85 verify_chain_files_exist
() {
86 for hash in $
(cat $1/commit-graph-chain
)
88 test_path_is_file
$1/graph-
$hash.graph ||
return 1
92 test_expect_success
'add more commits, and write a new base graph' '
93 git reset --hard commits/1 &&
94 for i in $(test_seq 4 5)
97 git branch commits/$i || return 1
99 git reset --hard commits/2 &&
100 for i in $(test_seq 6 10)
103 git branch commits/$i || return 1
105 git reset --hard commits/2 &&
106 git merge commits/4 &&
107 git branch merge/1 &&
108 git reset --hard commits/4 &&
109 git merge commits/6 &&
110 git branch merge/2 &&
111 git commit-graph write --reachable &&
115 test_expect_success
'fork and fail to base a chain on a commit-graph file' '
116 test_when_finished rm -rf fork &&
120 rm .git/objects/info/commit-graph &&
121 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
122 test_commit new-commit &&
123 git commit-graph write --reachable --split &&
124 test_path_is_file $graphdir/commit-graph-chain &&
125 test_line_count = 1 $graphdir/commit-graph-chain &&
126 verify_chain_files_exist $graphdir
130 test_expect_success
'add three more commits, write a tip graph' '
131 git reset --hard commits/3 &&
133 git merge commits/5 &&
135 git branch merge/3 &&
136 git commit-graph write --reachable --split &&
137 test_path_is_missing $infodir/commit-graph &&
138 test_path_is_file $graphdir/commit-graph-chain &&
139 ls $graphdir/graph-*.graph >graph-files &&
140 test_line_count = 2 graph-files &&
141 verify_chain_files_exist $graphdir
144 graph_git_behavior
'split commit-graph: merge 3 vs 2' merge
/3 merge
/2
146 test_expect_success
'add one commit, write a tip graph' '
148 git branch commits/11 &&
149 git commit-graph write --reachable --split &&
150 test_path_is_missing $infodir/commit-graph &&
151 test_path_is_file $graphdir/commit-graph-chain &&
152 ls $graphdir/graph-*.graph >graph-files &&
153 test_line_count = 3 graph-files &&
154 verify_chain_files_exist $graphdir
157 graph_git_behavior
'three-layer commit-graph: commit 11 vs 6' commits
/11 commits
/6
159 test_expect_success
'add one commit, write a merged graph' '
161 git branch commits/12 &&
162 git commit-graph write --reachable --split &&
163 test_path_is_file $graphdir/commit-graph-chain &&
164 test_line_count = 2 $graphdir/commit-graph-chain &&
165 ls $graphdir/graph-*.graph >graph-files &&
166 test_line_count = 2 graph-files &&
167 verify_chain_files_exist $graphdir
170 graph_git_behavior
'merged commit-graph: commit 12 vs 6' commits
/12 commits
/6
172 test_expect_success
'create fork and chain across alternate' '
176 git config core.commitGraph true &&
178 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
180 git branch commits/13 &&
181 git commit-graph write --reachable --split &&
182 test_path_is_file $graphdir/commit-graph-chain &&
183 test_line_count = 3 $graphdir/commit-graph-chain &&
184 ls $graphdir/graph-*.graph >graph-files &&
185 test_line_count = 1 graph-files &&
186 git -c core.commitGraph=true rev-list HEAD >expect &&
187 git -c core.commitGraph=false rev-list HEAD >actual &&
188 test_cmp expect actual &&
190 git commit-graph write --reachable --split --object-dir=.git/objects/ &&
191 test_line_count = 3 $graphdir/commit-graph-chain &&
192 ls $graphdir/graph-*.graph >graph-files &&
193 test_line_count = 1 graph-files
199 graph_git_behavior
'alternate: commit 13 vs 6' commits
/13 origin
/commits
/6 "fork"
202 test_expect_success
'test merge stragety constants' '
203 git clone . merge-2 &&
206 git config core.commitGraph true &&
207 test_line_count = 2 $graphdir/commit-graph-chain &&
209 git commit-graph write --reachable --split --size-multiple=2 &&
210 test_line_count = 3 $graphdir/commit-graph-chain
213 git clone . merge-10 &&
216 git config core.commitGraph true &&
217 test_line_count = 2 $graphdir/commit-graph-chain &&
219 git commit-graph write --reachable --split --size-multiple=10 &&
220 test_line_count = 1 $graphdir/commit-graph-chain &&
221 ls $graphdir/graph-*.graph >graph-files &&
222 test_line_count = 1 graph-files
224 git clone . merge-10-expire &&
226 cd merge-10-expire &&
227 git config core.commitGraph true &&
228 test_line_count = 2 $graphdir/commit-graph-chain &&
230 touch $graphdir/to-delete.graph $graphdir/to-keep.graph &&
231 test-tool chmtime =1546362000 $graphdir/to-delete.graph &&
232 test-tool chmtime =1546362001 $graphdir/to-keep.graph &&
233 git commit-graph write --reachable --split --size-multiple=10 \
234 --expire-time="2019-01-01 12:00 -05:00" &&
235 test_line_count = 1 $graphdir/commit-graph-chain &&
236 test_path_is_missing $graphdir/to-delete.graph &&
237 test_path_is_file $graphdir/to-keep.graph &&
238 ls $graphdir/graph-*.graph >graph-files &&
239 test_line_count = 3 graph-files
241 git clone --no-hardlinks . max-commits &&
244 git config core.commitGraph true &&
245 test_line_count = 2 $graphdir/commit-graph-chain &&
248 git commit-graph write --reachable --split --max-commits=1 &&
249 test_line_count = 1 $graphdir/commit-graph-chain &&
250 ls $graphdir/graph-*.graph >graph-files &&
251 test_line_count = 1 graph-files
255 test_expect_success
'remove commit-graph-chain file after flattening' '
256 git clone . flatten &&
259 test_line_count = 2 $graphdir/commit-graph-chain &&
260 git commit-graph write --reachable &&
261 test_path_is_missing $graphdir/commit-graph-chain &&
262 ls $graphdir >graph-files &&
263 test_line_count = 0 graph-files
272 printf "$data" |
dd of
="$file" bs
=1 seek
="$pos" conv
=notrunc
275 test_expect_success
'verify hashes along chain, even in shallow' '
276 git clone --no-hardlinks . verify &&
279 git commit-graph verify &&
280 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
281 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
282 test_must_fail git commit-graph verify --shallow 2>test_err &&
283 grep -v "^+" test_err >err &&
284 test_i18ngrep "incorrect checksum" err
288 test_expect_success
'verify --shallow does not check base contents' '
289 git clone --no-hardlinks . verify-shallow &&
292 git commit-graph verify &&
293 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
294 corrupt_file "$base_file" 1000 "\01" &&
295 git commit-graph verify --shallow &&
296 test_must_fail git commit-graph verify 2>test_err &&
297 grep -v "^+" test_err >err &&
298 test_i18ngrep "incorrect checksum" err
302 test_expect_success
'warn on base graph chunk incorrect' '
303 git clone --no-hardlinks . base-chunk &&
306 git commit-graph verify &&
307 base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
308 corrupt_file "$base_file" $(test_oid base) "\01" &&
309 git commit-graph verify --shallow 2>test_err &&
310 grep -v "^+" test_err >err &&
311 test_i18ngrep "commit-graph chain does not match" err
315 test_expect_success
'verify after commit-graph-chain corruption (base)' '
316 git clone --no-hardlinks . verify-chain-base &&
318 cd verify-chain-base &&
319 corrupt_file "$graphdir/commit-graph-chain" 30 "G" &&
320 git commit-graph verify 2>test_err &&
321 grep -v "^+" test_err >err &&
322 test_i18ngrep "invalid commit-graph chain" err &&
323 corrupt_file "$graphdir/commit-graph-chain" 30 "A" &&
324 git commit-graph verify 2>test_err &&
325 grep -v "^+" test_err >err &&
326 test_i18ngrep "unable to find all commit-graph files" err
330 test_expect_success
'verify after commit-graph-chain corruption (tip)' '
331 git clone --no-hardlinks . verify-chain-tip &&
333 cd verify-chain-tip &&
334 corrupt_file "$graphdir/commit-graph-chain" 70 "G" &&
335 git commit-graph verify 2>test_err &&
336 grep -v "^+" test_err >err &&
337 test_i18ngrep "invalid commit-graph chain" err &&
338 corrupt_file "$graphdir/commit-graph-chain" 70 "A" &&
339 git commit-graph verify 2>test_err &&
340 grep -v "^+" test_err >err &&
341 test_i18ngrep "unable to find all commit-graph files" err
345 test_expect_success
'verify across alternates' '
346 git clone --no-hardlinks . verify-alt &&
350 altdir="$(pwd)/../.git/objects" &&
351 echo "$altdir" >.git/objects/info/alternates &&
352 git commit-graph verify --object-dir="$altdir/" &&
354 git commit-graph write --reachable --split &&
355 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
356 corrupt_file "$tip_file" 100 "\01" &&
357 test_must_fail git commit-graph verify --shallow 2>test_err &&
358 grep -v "^+" test_err >err &&
359 test_i18ngrep "commit-graph has incorrect fanout value" err
363 test_expect_success
'add octopus merge' '
364 git reset --hard commits/10 &&
365 git merge commits/3 commits/4 &&
366 git branch merge/octopus &&
367 git commit-graph write --reachable --split &&
368 git commit-graph verify --progress 2>err &&
369 test_line_count = 1 err &&
370 grep "Verifying commits in commit graph: 100% (18/18)" err &&
371 test_i18ngrep ! warning err &&
372 test_line_count = 3 $graphdir/commit-graph-chain
375 graph_git_behavior
'graph exists' merge
/octopus commits
/12
377 test_expect_success
'split across alternate where alternate is not split' '
378 git commit-graph write --reachable &&
379 test_path_is_file .git/objects/info/commit-graph &&
380 cp .git/objects/info/commit-graph . &&
381 git clone --no-hardlinks . alt-split &&
384 rm -f .git/objects/info/commit-graph &&
385 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
387 git commit-graph write --reachable --split &&
388 test_line_count = 1 $graphdir/commit-graph-chain
390 test_cmp commit-graph .git/objects/info/commit-graph
393 test_expect_success
'--split=no-merge always writes an incremental' '
394 test_when_finished rm -rf a b &&
395 rm -rf $graphdir $infodir/commit-graph &&
396 git reset --hard commits/2 &&
397 git rev-list HEAD~1 >a &&
398 git rev-list HEAD >b &&
399 git commit-graph write --split --stdin-commits <a &&
400 git commit-graph write --split=no-merge --stdin-commits <b &&
401 test_line_count = 2 $graphdir/commit-graph-chain
404 test_expect_success
'--split=replace replaces the chain' '
405 rm -rf $graphdir $infodir/commit-graph &&
406 git reset --hard commits/3 &&
407 git rev-list -1 HEAD~2 >a &&
408 git rev-list -1 HEAD~1 >b &&
409 git rev-list -1 HEAD >c &&
410 git commit-graph write --split=no-merge --stdin-commits <a &&
411 git commit-graph write --split=no-merge --stdin-commits <b &&
412 git commit-graph write --split=no-merge --stdin-commits <c &&
413 test_line_count = 3 $graphdir/commit-graph-chain &&
414 git commit-graph write --stdin-commits --split=replace <b &&
415 test_path_is_missing $infodir/commit-graph &&
416 test_path_is_file $graphdir/commit-graph-chain &&
417 ls $graphdir/graph-*.graph >graph-files &&
418 test_line_count = 1 graph-files &&
419 verify_chain_files_exist $graphdir &&
423 test_expect_success ULIMIT_FILE_DESCRIPTORS
'handles file descriptor exhaustion' '
427 for i in $(test_seq 64)
430 run_with_limited_open_files test_might_fail git commit-graph write \
431 --split=no-merge --reachable || return 1
436 while read mode modebits
438 test_expect_success POSIXPERM
"split commit-graph respects core.sharedrepository $mode" '
439 rm -rf $graphdir $infodir/commit-graph &&
440 git reset --hard commits/1 &&
441 test_config core.sharedrepository "$mode" &&
442 git commit-graph write --split --reachable &&
443 ls $graphdir/graph-*.graph >graph-files &&
444 test_line_count = 1 graph-files &&
445 echo "$modebits" >expect &&
446 test_modebits $graphdir/graph-*.graph >actual &&
447 test_cmp expect actual &&
448 test_modebits $graphdir/commit-graph-chain >actual &&
449 test_cmp expect actual
456 test_expect_success
'--split=replace with partial Bloom data' '
457 rm -rf $graphdir $infodir/commit-graph &&
458 git reset --hard commits/3 &&
459 git rev-list -1 HEAD~2 >a &&
460 git rev-list -1 HEAD~1 >b &&
461 git commit-graph write --split=no-merge --stdin-commits --changed-paths <a &&
462 git commit-graph write --split=no-merge --stdin-commits <b &&
463 git commit-graph write --split=replace --stdin-commits --changed-paths <c &&
464 ls $graphdir/graph-*.graph >graph-files &&
465 test_line_count = 1 graph-files &&
466 verify_chain_files_exist $graphdir
469 test_expect_success
'prevent regression for duplicate commits across layers' '
471 git -C dup commit --allow-empty -m one &&
472 git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err &&
473 test_i18ngrep "attempting to write a commit-graph" err &&
474 git -C dup commit-graph write --split=no-merge --reachable &&
475 git -C dup commit --allow-empty -m two &&
476 git -C dup commit-graph write --split=no-merge --reachable &&
477 git -C dup commit --allow-empty -m three &&
478 git -C dup commit-graph write --split --reachable &&
479 git -C dup commit-graph verify
482 NUM_FIRST_LAYER_COMMITS
=64
483 NUM_SECOND_LAYER_COMMITS
=16
484 NUM_THIRD_LAYER_COMMITS
=7
485 NUM_FOURTH_LAYER_COMMITS
=8
486 NUM_FIFTH_LAYER_COMMITS
=16
487 SECOND_LAYER_SEQUENCE_START
=$
(($NUM_FIRST_LAYER_COMMITS + 1))
488 SECOND_LAYER_SEQUENCE_END
=$
(($SECOND_LAYER_SEQUENCE_START + $NUM_SECOND_LAYER_COMMITS - 1))
489 THIRD_LAYER_SEQUENCE_START
=$
(($SECOND_LAYER_SEQUENCE_END + 1))
490 THIRD_LAYER_SEQUENCE_END
=$
(($THIRD_LAYER_SEQUENCE_START + $NUM_THIRD_LAYER_COMMITS - 1))
491 FOURTH_LAYER_SEQUENCE_START
=$
(($THIRD_LAYER_SEQUENCE_END + 1))
492 FOURTH_LAYER_SEQUENCE_END
=$
(($FOURTH_LAYER_SEQUENCE_START + $NUM_FOURTH_LAYER_COMMITS - 1))
493 FIFTH_LAYER_SEQUENCE_START
=$
(($FOURTH_LAYER_SEQUENCE_END + 1))
494 FIFTH_LAYER_SEQUENCE_END
=$
(($FIFTH_LAYER_SEQUENCE_START + $NUM_FIFTH_LAYER_COMMITS - 1))
496 # Current split graph chain:
498 # 16 commits (No GDAT)
499 # ------------------------
502 test_expect_success
'setup repo for mixed generation commit-graph-chain' '
503 graphdir=".git/objects/info/commit-graphs" &&
504 test_oid_cache <<-EOF &&
511 git config core.commitGraph true &&
512 git config gc.writeCommitGraph false &&
513 for i in $(test_seq $NUM_FIRST_LAYER_COMMITS)
516 git branch commits/$i || return 1
518 git -c commitGraph.generationVersion=2 commit-graph write --reachable --split &&
519 graph_read_expect $NUM_FIRST_LAYER_COMMITS &&
520 test_line_count = 1 $graphdir/commit-graph-chain &&
521 for i in $(test_seq $SECOND_LAYER_SEQUENCE_START $SECOND_LAYER_SEQUENCE_END)
524 git branch commits/$i || return 1
526 git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge &&
527 test_line_count = 2 $graphdir/commit-graph-chain &&
528 test-tool read-graph >output &&
529 cat >expect <<-EOF &&
530 header: 43475048 1 $(test_oid oid_version) 4 1
531 num_commits: $NUM_SECOND_LAYER_COMMITS
532 chunks: oid_fanout oid_lookup commit_metadata
535 test_cmp expect output &&
536 git commit-graph verify &&
537 cat $graphdir/commit-graph-chain
541 # The new layer will be added without generation data chunk as it was not
542 # present on the layer underneath it.
544 # 7 commits (No GDAT)
545 # ------------------------
546 # 16 commits (No GDAT)
547 # ------------------------
550 test_expect_success
'do not write generation data chunk if not present on existing tip' '
551 git clone mixed mixed-no-gdat &&
554 for i in $(test_seq $THIRD_LAYER_SEQUENCE_START $THIRD_LAYER_SEQUENCE_END)
557 git branch commits/$i || return 1
559 git commit-graph write --reachable --split=no-merge &&
560 test_line_count = 3 $graphdir/commit-graph-chain &&
561 test-tool read-graph >output &&
562 cat >expect <<-EOF &&
563 header: 43475048 1 $(test_oid oid_version) 4 2
564 num_commits: $NUM_THIRD_LAYER_COMMITS
565 chunks: oid_fanout oid_lookup commit_metadata
568 test_cmp expect output &&
569 git commit-graph verify
573 # Number of commits in each layer of the split-commit graph before merge:
575 # 8 commits (No GDAT)
576 # ------------------------
577 # 7 commits (No GDAT)
578 # ------------------------
579 # 16 commits (No GDAT)
580 # ------------------------
583 # The top two layers are merged and do not have generation data chunk as layer below them does
584 # not have generation data chunk.
586 # 15 commits (No GDAT)
587 # ------------------------
588 # 16 commits (No GDAT)
589 # ------------------------
592 test_expect_success
'do not write generation data chunk if the topmost remaining layer does not have generation data chunk' '
593 git clone mixed-no-gdat mixed-merge-no-gdat &&
595 cd mixed-merge-no-gdat &&
596 for i in $(test_seq $FOURTH_LAYER_SEQUENCE_START $FOURTH_LAYER_SEQUENCE_END)
599 git branch commits/$i || return 1
601 git commit-graph write --reachable --split --size-multiple 1 &&
602 test_line_count = 3 $graphdir/commit-graph-chain &&
603 test-tool read-graph >output &&
604 cat >expect <<-EOF &&
605 header: 43475048 1 $(test_oid oid_version) 4 2
606 num_commits: $(($NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS))
607 chunks: oid_fanout oid_lookup commit_metadata
610 test_cmp expect output &&
611 git commit-graph verify
615 # Number of commits in each layer of the split-commit graph before merge:
617 # 16 commits (No GDAT)
618 # ------------------------
619 # 15 commits (No GDAT)
620 # ------------------------
621 # 16 commits (No GDAT)
622 # ------------------------
625 # The top three layers are merged and has generation data chunk as the topmost remaining layer
626 # has generation data chunk.
629 # ------------------------
632 test_expect_success
'write generation data chunk if topmost remaining layer has generation data chunk' '
633 git clone mixed-merge-no-gdat mixed-merge-gdat &&
635 cd mixed-merge-gdat &&
636 for i in $(test_seq $FIFTH_LAYER_SEQUENCE_START $FIFTH_LAYER_SEQUENCE_END)
639 git branch commits/$i || return 1
641 git commit-graph write --reachable --split --size-multiple 1 &&
642 test_line_count = 2 $graphdir/commit-graph-chain &&
643 test-tool read-graph >output &&
644 cat >expect <<-EOF &&
645 header: 43475048 1 $(test_oid oid_version) 5 1
646 num_commits: $(($NUM_SECOND_LAYER_COMMITS + $NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS + $NUM_FIFTH_LAYER_COMMITS))
647 chunks: oid_fanout oid_lookup commit_metadata generation_data
648 options: read_generation_data
650 test_cmp expect output
654 test_expect_success
'write generation data chunk when commit-graph chain is replaced' '
655 git clone mixed mixed-replace &&
658 git commit-graph write --reachable --split=replace &&
659 test_path_is_file $graphdir/commit-graph-chain &&
660 test_line_count = 1 $graphdir/commit-graph-chain &&
661 verify_chain_files_exist $graphdir &&
662 graph_read_expect $(($NUM_FIRST_LAYER_COMMITS + $NUM_SECOND_LAYER_COMMITS)) &&
663 git commit-graph verify