blob: 669ddc645faccfc402b04044ed75676592e64356 [file] [log] [blame]
Derrick Stolee135a7122019-06-18 11:14:28 -07001#!/bin/sh
2
3test_description='split commit graph'
4. ./test-lib.sh
5
6GIT_TEST_COMMIT_GRAPH=0
Garima Singhd5b873c2020-04-06 16:59:55 +00007GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
Derrick Stolee135a7122019-06-18 11:14:28 -07008
9test_expect_success 'setup repo' '
10 git init &&
11 git config core.commitGraph true &&
Derrick Stolee31b1de62019-08-13 11:37:45 -070012 git config gc.writeCommitGraph false &&
Derrick Stolee135a7122019-06-18 11:14:28 -070013 infodir=".git/objects/info" &&
14 graphdir="$infodir/commit-graphs" &&
brian m. carlson82d5aeb2019-12-21 19:49:27 +000015 test_oid_cache <<-EOM
Abhishek Kumare8b63002021-01-16 18:11:15 +000016 shallow sha1:2132
17 shallow sha256:2436
brian m. carlson82d5aeb2019-12-21 19:49:27 +000018
Abhishek Kumare8b63002021-01-16 18:11:15 +000019 base sha1:1408
20 base sha256:1528
Derrick Stolee665d70a2020-08-17 14:04:47 +000021
22 oid_version sha1:1
23 oid_version sha256:2
brian m. carlson82d5aeb2019-12-21 19:49:27 +000024 EOM
Derrick Stolee135a7122019-06-18 11:14:28 -070025'
26
27graph_read_expect() {
28 NUM_BASE=0
29 if test ! -z $2
30 then
31 NUM_BASE=$2
32 fi
Derrick Stolee3b0199d2022-03-01 19:48:31 +000033 OPTIONS=
34 if test -z "$3"
35 then
36 OPTIONS=" read_generation_data"
37 fi
Derrick Stolee135a7122019-06-18 11:14:28 -070038 cat >expect <<- EOF
Abhishek Kumare8b63002021-01-16 18:11:15 +000039 header: 43475048 1 $(test_oid oid_version) 4 $NUM_BASE
Derrick Stolee135a7122019-06-18 11:14:28 -070040 num_commits: $1
Abhishek Kumare8b63002021-01-16 18:11:15 +000041 chunks: oid_fanout oid_lookup commit_metadata generation_data
Derrick Stolee3b0199d2022-03-01 19:48:31 +000042 options:$OPTIONS
Derrick Stolee135a7122019-06-18 11:14:28 -070043 EOF
Derrick Stolee4bd05932019-11-12 16:58:20 +000044 test-tool read-graph >output &&
Derrick Stolee135a7122019-06-18 11:14:28 -070045 test_cmp expect output
46}
47
Taylor Blauf4d62842020-04-29 11:36:42 -060048test_expect_success POSIXPERM 'tweak umask for modebit tests' '
49 umask 022
50'
51
Derrick Stolee135a7122019-06-18 11:14:28 -070052test_expect_success 'create commits and write commit-graph' '
53 for i in $(test_seq 3)
54 do
55 test_commit $i &&
56 git branch commits/$i || return 1
57 done &&
58 git commit-graph write --reachable &&
59 test_path_is_file $infodir/commit-graph &&
60 graph_read_expect 3
61'
62
63graph_git_two_modes() {
Ævar Arnfjörð Bjarmasona046aa32021-10-15 01:37:15 +020064 git ${2:+ -C "$2"} -c core.commitGraph=true $1 >output &&
65 git ${2:+ -C "$2"} -c core.commitGraph=false $1 >expect &&
Derrick Stolee135a7122019-06-18 11:14:28 -070066 test_cmp expect output
67}
68
69graph_git_behavior() {
70 MSG=$1
71 BRANCH=$2
72 COMPARE=$3
Ævar Arnfjörð Bjarmasona046aa32021-10-15 01:37:15 +020073 DIR=$4
Derrick Stolee135a7122019-06-18 11:14:28 -070074 test_expect_success "check normal git operations: $MSG" '
Ævar Arnfjörð Bjarmasona046aa32021-10-15 01:37:15 +020075 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"
Derrick Stolee135a7122019-06-18 11:14:28 -070080 '
81}
82
83graph_git_behavior 'graph exists' commits/3 commits/1
84
85verify_chain_files_exist() {
86 for hash in $(cat $1/commit-graph-chain)
87 do
88 test_path_is_file $1/graph-$hash.graph || return 1
89 done
90}
91
92test_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)
95 do
96 test_commit $i &&
97 git branch commits/$i || return 1
98 done &&
99 git reset --hard commits/2 &&
100 for i in $(test_seq 6 10)
101 do
102 test_commit $i &&
103 git branch commits/$i || return 1
104 done &&
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 &&
112 graph_read_expect 12
113'
114
Derrick Stoleec5230352019-06-18 11:14:30 -0700115test_expect_success 'fork and fail to base a chain on a commit-graph file' '
116 test_when_finished rm -rf fork &&
117 git clone . fork &&
118 (
119 cd 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
127 )
128'
129
Derrick Stolee135a7122019-06-18 11:14:28 -0700130test_expect_success 'add three more commits, write a tip graph' '
131 git reset --hard commits/3 &&
132 git merge merge/1 &&
133 git merge commits/5 &&
134 git merge merge/2 &&
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
142'
143
144graph_git_behavior 'split commit-graph: merge 3 vs 2' merge/3 merge/2
145
146test_expect_success 'add one commit, write a tip graph' '
147 test_commit 11 &&
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
155'
156
157graph_git_behavior 'three-layer commit-graph: commit 11 vs 6' commits/11 commits/6
158
Derrick Stolee1771be92019-06-18 11:14:29 -0700159test_expect_success 'add one commit, write a merged graph' '
160 test_commit 12 &&
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 &&
Derrick Stolee8d840972019-06-18 11:14:31 -0700166 test_line_count = 2 graph-files &&
Derrick Stolee1771be92019-06-18 11:14:29 -0700167 verify_chain_files_exist $graphdir
168'
169
170graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6
171
Derrick Stoleec5230352019-06-18 11:14:30 -0700172test_expect_success 'create fork and chain across alternate' '
173 git clone . fork &&
174 (
175 cd fork &&
176 git config core.commitGraph true &&
177 rm -rf $graphdir &&
178 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
179 test_commit 13 &&
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 &&
Derrick Stolee16110c92019-06-18 11:14:36 -0700188 test_cmp expect actual &&
189 test_commit 14 &&
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
Derrick Stoleec5230352019-06-18 11:14:30 -0700194 )
195'
196
Ævar Arnfjörð Bjarmasona046aa32021-10-15 01:37:15 +0200197if test -d fork
198then
199 graph_git_behavior 'alternate: commit 13 vs 6' commits/13 origin/commits/6 "fork"
200fi
Derrick Stoleec5230352019-06-18 11:14:30 -0700201
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700202test_expect_success 'test merge stragety constants' '
203 git clone . merge-2 &&
204 (
205 cd merge-2 &&
206 git config core.commitGraph true &&
207 test_line_count = 2 $graphdir/commit-graph-chain &&
208 test_commit 14 &&
209 git commit-graph write --reachable --split --size-multiple=2 &&
210 test_line_count = 3 $graphdir/commit-graph-chain
211
212 ) &&
213 git clone . merge-10 &&
214 (
215 cd merge-10 &&
216 git config core.commitGraph true &&
217 test_line_count = 2 $graphdir/commit-graph-chain &&
218 test_commit 14 &&
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
223 ) &&
224 git clone . merge-10-expire &&
225 (
226 cd merge-10-expire &&
227 git config core.commitGraph true &&
228 test_line_count = 2 $graphdir/commit-graph-chain &&
229 test_commit 15 &&
Derrick Stoleeb09b7852020-04-01 21:00:44 +0000230 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" &&
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700235 test_line_count = 1 $graphdir/commit-graph-chain &&
Derrick Stoleeb09b7852020-04-01 21:00:44 +0000236 test_path_is_missing $graphdir/to-delete.graph &&
237 test_path_is_file $graphdir/to-keep.graph &&
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700238 ls $graphdir/graph-*.graph >graph-files &&
239 test_line_count = 3 graph-files
240 ) &&
241 git clone --no-hardlinks . max-commits &&
242 (
243 cd max-commits &&
244 git config core.commitGraph true &&
245 test_line_count = 2 $graphdir/commit-graph-chain &&
246 test_commit 16 &&
247 test_commit 17 &&
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
252 )
253'
254
Derrick Stoleeba411122019-06-18 11:14:33 -0700255test_expect_success 'remove commit-graph-chain file after flattening' '
256 git clone . flatten &&
257 (
258 cd 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
264 )
265'
266
Derrick Stolee3da4b602019-06-18 11:14:32 -0700267corrupt_file() {
268 file=$1
269 pos=$2
270 data="${3:-\0}"
Derrick Stolee5b15eb32019-06-18 11:14:36 -0700271 chmod a+w "$file" &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700272 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
273}
274
275test_expect_success 'verify hashes along chain, even in shallow' '
276 git clone --no-hardlinks . verify &&
277 (
278 cd verify &&
279 git commit-graph verify &&
280 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
brian m. carlson82d5aeb2019-12-21 19:49:27 +0000281 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700282 test_must_fail git commit-graph verify --shallow 2>test_err &&
283 grep -v "^+" test_err >err &&
284 test_i18ngrep "incorrect checksum" err
285 )
286'
287
288test_expect_success 'verify --shallow does not check base contents' '
289 git clone --no-hardlinks . verify-shallow &&
290 (
291 cd 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
299 )
300'
301
302test_expect_success 'warn on base graph chunk incorrect' '
303 git clone --no-hardlinks . base-chunk &&
304 (
305 cd base-chunk &&
306 git commit-graph verify &&
307 base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
brian m. carlson82d5aeb2019-12-21 19:49:27 +0000308 corrupt_file "$base_file" $(test_oid base) "\01" &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700309 git commit-graph verify --shallow 2>test_err &&
310 grep -v "^+" test_err >err &&
311 test_i18ngrep "commit-graph chain does not match" err
312 )
313'
314
315test_expect_success 'verify after commit-graph-chain corruption' '
316 git clone --no-hardlinks . verify-chain &&
317 (
318 cd verify-chain &&
319 corrupt_file "$graphdir/commit-graph-chain" 60 "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" 60 "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
327 )
328'
329
Derrick Stolee5b15eb32019-06-18 11:14:36 -0700330test_expect_success 'verify across alternates' '
331 git clone --no-hardlinks . verify-alt &&
332 (
333 cd verify-alt &&
334 rm -rf $graphdir &&
335 altdir="$(pwd)/../.git/objects" &&
336 echo "$altdir" >.git/objects/info/alternates &&
337 git commit-graph verify --object-dir="$altdir/" &&
338 test_commit extra &&
339 git commit-graph write --reachable --split &&
340 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
341 corrupt_file "$tip_file" 100 "\01" &&
342 test_must_fail git commit-graph verify --shallow 2>test_err &&
343 grep -v "^+" test_err >err &&
344 test_i18ngrep "commit-graph has incorrect fanout value" err
345 )
346'
347
Derrick Stoleee2017c42019-06-18 11:14:34 -0700348test_expect_success 'add octopus merge' '
349 git reset --hard commits/10 &&
350 git merge commits/3 commits/4 &&
351 git branch merge/octopus &&
352 git commit-graph write --reachable --split &&
Garima Singh73716122019-08-26 09:29:58 -0700353 git commit-graph verify --progress 2>err &&
Derrick Stoleea35bea42019-08-05 09:43:41 -0700354 test_line_count = 3 err &&
355 test_i18ngrep ! warning err &&
Derrick Stoleee2017c42019-06-18 11:14:34 -0700356 test_line_count = 3 $graphdir/commit-graph-chain
357'
358
359graph_git_behavior 'graph exists' merge/octopus commits/12
360
Derrick Stoleea09c1302019-06-18 11:14:35 -0700361test_expect_success 'split across alternate where alternate is not split' '
362 git commit-graph write --reachable &&
363 test_path_is_file .git/objects/info/commit-graph &&
364 cp .git/objects/info/commit-graph . &&
365 git clone --no-hardlinks . alt-split &&
366 (
367 cd alt-split &&
Derrick Stolee31b1de62019-08-13 11:37:45 -0700368 rm -f .git/objects/info/commit-graph &&
Derrick Stoleea09c1302019-06-18 11:14:35 -0700369 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
370 test_commit 18 &&
371 git commit-graph write --reachable --split &&
372 test_line_count = 1 $graphdir/commit-graph-chain
373 ) &&
374 test_cmp commit-graph .git/objects/info/commit-graph
375'
376
Taylor Blaufdbde822020-04-13 22:04:12 -0600377test_expect_success '--split=no-merge always writes an incremental' '
378 test_when_finished rm -rf a b &&
379 rm -rf $graphdir $infodir/commit-graph &&
380 git reset --hard commits/2 &&
381 git rev-list HEAD~1 >a &&
382 git rev-list HEAD >b &&
383 git commit-graph write --split --stdin-commits <a &&
384 git commit-graph write --split=no-merge --stdin-commits <b &&
385 test_line_count = 2 $graphdir/commit-graph-chain
386'
387
Taylor Blau8a6ac282020-04-13 22:04:17 -0600388test_expect_success '--split=replace replaces the chain' '
389 rm -rf $graphdir $infodir/commit-graph &&
390 git reset --hard commits/3 &&
391 git rev-list -1 HEAD~2 >a &&
392 git rev-list -1 HEAD~1 >b &&
393 git rev-list -1 HEAD >c &&
394 git commit-graph write --split=no-merge --stdin-commits <a &&
395 git commit-graph write --split=no-merge --stdin-commits <b &&
396 git commit-graph write --split=no-merge --stdin-commits <c &&
397 test_line_count = 3 $graphdir/commit-graph-chain &&
398 git commit-graph write --stdin-commits --split=replace <b &&
399 test_path_is_missing $infodir/commit-graph &&
400 test_path_is_file $graphdir/commit-graph-chain &&
401 ls $graphdir/graph-*.graph >graph-files &&
402 test_line_count = 1 graph-files &&
403 verify_chain_files_exist $graphdir &&
404 graph_read_expect 2
405'
406
Taylor Blaub78a5562020-04-23 15:41:09 -0600407test_expect_success ULIMIT_FILE_DESCRIPTORS 'handles file descriptor exhaustion' '
408 git init ulimit &&
409 (
410 cd ulimit &&
411 for i in $(test_seq 64)
412 do
413 test_commit $i &&
Denton Liu6861ac82020-07-07 02:04:35 -0400414 run_with_limited_open_files test_might_fail git commit-graph write \
Taylor Blaub78a5562020-04-23 15:41:09 -0600415 --split=no-merge --reachable || return 1
416 done
417 )
418'
419
Taylor Blauf4d62842020-04-29 11:36:42 -0600420while read mode modebits
421do
422 test_expect_success POSIXPERM "split commit-graph respects core.sharedrepository $mode" '
423 rm -rf $graphdir $infodir/commit-graph &&
424 git reset --hard commits/1 &&
425 test_config core.sharedrepository "$mode" &&
426 git commit-graph write --split --reachable &&
427 ls $graphdir/graph-*.graph >graph-files &&
428 test_line_count = 1 graph-files &&
429 echo "$modebits" >expect &&
430 test_modebits $graphdir/graph-*.graph >actual &&
Taylor Blau45a43652020-04-29 11:36:46 -0600431 test_cmp expect actual &&
432 test_modebits $graphdir/commit-graph-chain >actual &&
Taylor Blauf4d62842020-04-29 11:36:42 -0600433 test_cmp expect actual
434 '
435done <<\EOF
4360666 -r--r--r--
4370600 -r--------
438EOF
439
Taylor Blau4f364402020-09-09 11:22:44 -0400440test_expect_success '--split=replace with partial Bloom data' '
441 rm -rf $graphdir $infodir/commit-graph &&
442 git reset --hard commits/3 &&
443 git rev-list -1 HEAD~2 >a &&
444 git rev-list -1 HEAD~1 >b &&
445 git commit-graph write --split=no-merge --stdin-commits --changed-paths <a &&
446 git commit-graph write --split=no-merge --stdin-commits <b &&
447 git commit-graph write --split=replace --stdin-commits --changed-paths <c &&
448 ls $graphdir/graph-*.graph >graph-files &&
449 test_line_count = 1 graph-files &&
450 verify_chain_files_exist $graphdir
451'
452
Derrick Stolee150f1152020-10-09 20:53:51 +0000453test_expect_success 'prevent regression for duplicate commits across layers' '
454 git init dup &&
Derrick Stolee150f1152020-10-09 20:53:51 +0000455 git -C dup commit --allow-empty -m one &&
Derrick Stolee85102ac2020-10-09 20:53:52 +0000456 git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err &&
457 test_i18ngrep "attempting to write a commit-graph" err &&
Derrick Stolee150f1152020-10-09 20:53:51 +0000458 git -C dup commit-graph write --split=no-merge --reachable &&
459 git -C dup commit --allow-empty -m two &&
460 git -C dup commit-graph write --split=no-merge --reachable &&
461 git -C dup commit --allow-empty -m three &&
462 git -C dup commit-graph write --split --reachable &&
463 git -C dup commit-graph verify
464'
465
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000466NUM_FIRST_LAYER_COMMITS=64
467NUM_SECOND_LAYER_COMMITS=16
468NUM_THIRD_LAYER_COMMITS=7
469NUM_FOURTH_LAYER_COMMITS=8
470NUM_FIFTH_LAYER_COMMITS=16
471SECOND_LAYER_SEQUENCE_START=$(($NUM_FIRST_LAYER_COMMITS + 1))
472SECOND_LAYER_SEQUENCE_END=$(($SECOND_LAYER_SEQUENCE_START + $NUM_SECOND_LAYER_COMMITS - 1))
473THIRD_LAYER_SEQUENCE_START=$(($SECOND_LAYER_SEQUENCE_END + 1))
474THIRD_LAYER_SEQUENCE_END=$(($THIRD_LAYER_SEQUENCE_START + $NUM_THIRD_LAYER_COMMITS - 1))
475FOURTH_LAYER_SEQUENCE_START=$(($THIRD_LAYER_SEQUENCE_END + 1))
476FOURTH_LAYER_SEQUENCE_END=$(($FOURTH_LAYER_SEQUENCE_START + $NUM_FOURTH_LAYER_COMMITS - 1))
477FIFTH_LAYER_SEQUENCE_START=$(($FOURTH_LAYER_SEQUENCE_END + 1))
478FIFTH_LAYER_SEQUENCE_END=$(($FIFTH_LAYER_SEQUENCE_START + $NUM_FIFTH_LAYER_COMMITS - 1))
479
480# Current split graph chain:
481#
482# 16 commits (No GDAT)
483# ------------------------
484# 64 commits (GDAT)
485#
486test_expect_success 'setup repo for mixed generation commit-graph-chain' '
487 graphdir=".git/objects/info/commit-graphs" &&
488 test_oid_cache <<-EOF &&
489 oid_version sha1:1
490 oid_version sha256:2
491 EOF
492 git init mixed &&
493 (
494 cd mixed &&
495 git config core.commitGraph true &&
496 git config gc.writeCommitGraph false &&
497 for i in $(test_seq $NUM_FIRST_LAYER_COMMITS)
498 do
499 test_commit $i &&
500 git branch commits/$i || return 1
501 done &&
Derrick Stolee702110a2021-02-25 18:19:43 +0000502 git -c commitGraph.generationVersion=2 commit-graph write --reachable --split &&
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000503 graph_read_expect $NUM_FIRST_LAYER_COMMITS &&
504 test_line_count = 1 $graphdir/commit-graph-chain &&
505 for i in $(test_seq $SECOND_LAYER_SEQUENCE_START $SECOND_LAYER_SEQUENCE_END)
506 do
507 test_commit $i &&
508 git branch commits/$i || return 1
509 done &&
Derrick Stolee702110a2021-02-25 18:19:43 +0000510 git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge &&
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000511 test_line_count = 2 $graphdir/commit-graph-chain &&
512 test-tool read-graph >output &&
513 cat >expect <<-EOF &&
514 header: 43475048 1 $(test_oid oid_version) 4 1
515 num_commits: $NUM_SECOND_LAYER_COMMITS
516 chunks: oid_fanout oid_lookup commit_metadata
Derrick Stoleec78c7a92022-03-01 19:48:28 +0000517 options:
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000518 EOF
519 test_cmp expect output &&
520 git commit-graph verify &&
521 cat $graphdir/commit-graph-chain
522 )
523'
524
525# The new layer will be added without generation data chunk as it was not
526# present on the layer underneath it.
527#
528# 7 commits (No GDAT)
529# ------------------------
530# 16 commits (No GDAT)
531# ------------------------
532# 64 commits (GDAT)
533#
534test_expect_success 'do not write generation data chunk if not present on existing tip' '
535 git clone mixed mixed-no-gdat &&
536 (
537 cd mixed-no-gdat &&
538 for i in $(test_seq $THIRD_LAYER_SEQUENCE_START $THIRD_LAYER_SEQUENCE_END)
539 do
540 test_commit $i &&
541 git branch commits/$i || return 1
542 done &&
543 git commit-graph write --reachable --split=no-merge &&
544 test_line_count = 3 $graphdir/commit-graph-chain &&
545 test-tool read-graph >output &&
546 cat >expect <<-EOF &&
547 header: 43475048 1 $(test_oid oid_version) 4 2
548 num_commits: $NUM_THIRD_LAYER_COMMITS
549 chunks: oid_fanout oid_lookup commit_metadata
Derrick Stoleec78c7a92022-03-01 19:48:28 +0000550 options:
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000551 EOF
552 test_cmp expect output &&
553 git commit-graph verify
554 )
555'
556
557# Number of commits in each layer of the split-commit graph before merge:
558#
559# 8 commits (No GDAT)
560# ------------------------
561# 7 commits (No GDAT)
562# ------------------------
563# 16 commits (No GDAT)
564# ------------------------
565# 64 commits (GDAT)
566#
567# The top two layers are merged and do not have generation data chunk as layer below them does
568# not have generation data chunk.
569#
570# 15 commits (No GDAT)
571# ------------------------
572# 16 commits (No GDAT)
573# ------------------------
574# 64 commits (GDAT)
575#
576test_expect_success 'do not write generation data chunk if the topmost remaining layer does not have generation data chunk' '
577 git clone mixed-no-gdat mixed-merge-no-gdat &&
578 (
579 cd mixed-merge-no-gdat &&
580 for i in $(test_seq $FOURTH_LAYER_SEQUENCE_START $FOURTH_LAYER_SEQUENCE_END)
581 do
582 test_commit $i &&
583 git branch commits/$i || return 1
584 done &&
585 git commit-graph write --reachable --split --size-multiple 1 &&
586 test_line_count = 3 $graphdir/commit-graph-chain &&
587 test-tool read-graph >output &&
588 cat >expect <<-EOF &&
589 header: 43475048 1 $(test_oid oid_version) 4 2
590 num_commits: $(($NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS))
591 chunks: oid_fanout oid_lookup commit_metadata
Derrick Stoleec78c7a92022-03-01 19:48:28 +0000592 options:
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000593 EOF
594 test_cmp expect output &&
595 git commit-graph verify
596 )
597'
598
599# Number of commits in each layer of the split-commit graph before merge:
600#
601# 16 commits (No GDAT)
602# ------------------------
603# 15 commits (No GDAT)
604# ------------------------
605# 16 commits (No GDAT)
606# ------------------------
607# 64 commits (GDAT)
608#
609# The top three layers are merged and has generation data chunk as the topmost remaining layer
610# has generation data chunk.
611#
612# 47 commits (GDAT)
613# ------------------------
614# 64 commits (GDAT)
615#
616test_expect_success 'write generation data chunk if topmost remaining layer has generation data chunk' '
617 git clone mixed-merge-no-gdat mixed-merge-gdat &&
618 (
619 cd mixed-merge-gdat &&
620 for i in $(test_seq $FIFTH_LAYER_SEQUENCE_START $FIFTH_LAYER_SEQUENCE_END)
621 do
622 test_commit $i &&
623 git branch commits/$i || return 1
624 done &&
625 git commit-graph write --reachable --split --size-multiple 1 &&
626 test_line_count = 2 $graphdir/commit-graph-chain &&
627 test-tool read-graph >output &&
628 cat >expect <<-EOF &&
629 header: 43475048 1 $(test_oid oid_version) 5 1
630 num_commits: $(($NUM_SECOND_LAYER_COMMITS + $NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS + $NUM_FIFTH_LAYER_COMMITS))
631 chunks: oid_fanout oid_lookup commit_metadata generation_data
Derrick Stolee3b0199d2022-03-01 19:48:31 +0000632 options: read_generation_data
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000633 EOF
634 test_cmp expect output
635 )
636'
637
638test_expect_success 'write generation data chunk when commit-graph chain is replaced' '
639 git clone mixed mixed-replace &&
640 (
641 cd mixed-replace &&
642 git commit-graph write --reachable --split=replace &&
643 test_path_is_file $graphdir/commit-graph-chain &&
644 test_line_count = 1 $graphdir/commit-graph-chain &&
645 verify_chain_files_exist $graphdir &&
646 graph_read_expect $(($NUM_FIRST_LAYER_COMMITS + $NUM_SECOND_LAYER_COMMITS)) &&
647 git commit-graph verify
648 )
649'
650
Derrick Stolee135a7122019-06-18 11:14:28 -0700651test_done