blob: 281266f7883b35cbc4dd2c631d645d0d5b430d0c [file] [log] [blame]
Derrick Stolee135a7122019-06-18 11:14:28 -07001#!/bin/sh
2
3test_description='split commit graph'
Jeff Kingda09e7a2023-10-03 16:31:30 -04004
5TEST_PASSES_SANITIZE_LEAK=true
Derrick Stolee135a7122019-06-18 11:14:28 -07006. ./test-lib.sh
Jeff King6cf61d02023-10-09 17:05:41 -04007. "$TEST_DIRECTORY"/lib-chunk.sh
Derrick Stolee135a7122019-06-18 11:14:28 -07008
9GIT_TEST_COMMIT_GRAPH=0
Garima Singhd5b873c2020-04-06 16:59:55 +000010GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
Derrick Stolee135a7122019-06-18 11:14:28 -070011
12test_expect_success 'setup repo' '
13 git init &&
14 git config core.commitGraph true &&
Derrick Stolee31b1de62019-08-13 11:37:45 -070015 git config gc.writeCommitGraph false &&
Derrick Stolee135a7122019-06-18 11:14:28 -070016 infodir=".git/objects/info" &&
17 graphdir="$infodir/commit-graphs" &&
brian m. carlson82d5aeb2019-12-21 19:49:27 +000018 test_oid_cache <<-EOM
Abhishek Kumare8b63002021-01-16 18:11:15 +000019 shallow sha1:2132
20 shallow sha256:2436
brian m. carlson82d5aeb2019-12-21 19:49:27 +000021
Abhishek Kumare8b63002021-01-16 18:11:15 +000022 base sha1:1408
23 base sha256:1528
Derrick Stolee665d70a2020-08-17 14:04:47 +000024
25 oid_version sha1:1
26 oid_version sha256:2
brian m. carlson82d5aeb2019-12-21 19:49:27 +000027 EOM
Derrick Stolee135a7122019-06-18 11:14:28 -070028'
29
30graph_read_expect() {
31 NUM_BASE=0
32 if test ! -z $2
33 then
34 NUM_BASE=$2
35 fi
Derrick Stolee3b0199d2022-03-01 19:48:31 +000036 OPTIONS=
37 if test -z "$3"
38 then
39 OPTIONS=" read_generation_data"
40 fi
Derrick Stolee135a7122019-06-18 11:14:28 -070041 cat >expect <<- EOF
Abhishek Kumare8b63002021-01-16 18:11:15 +000042 header: 43475048 1 $(test_oid oid_version) 4 $NUM_BASE
Derrick Stolee135a7122019-06-18 11:14:28 -070043 num_commits: $1
Abhishek Kumare8b63002021-01-16 18:11:15 +000044 chunks: oid_fanout oid_lookup commit_metadata generation_data
Derrick Stolee3b0199d2022-03-01 19:48:31 +000045 options:$OPTIONS
Derrick Stolee135a7122019-06-18 11:14:28 -070046 EOF
Derrick Stolee4bd05932019-11-12 16:58:20 +000047 test-tool read-graph >output &&
Derrick Stolee135a7122019-06-18 11:14:28 -070048 test_cmp expect output
49}
50
Taylor Blauf4d62842020-04-29 11:36:42 -060051test_expect_success POSIXPERM 'tweak umask for modebit tests' '
52 umask 022
53'
54
Derrick Stolee135a7122019-06-18 11:14:28 -070055test_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() {
Ævar Arnfjörð Bjarmasona046aa32021-10-15 01:37:15 +020067 git ${2:+ -C "$2"} -c core.commitGraph=true $1 >output &&
68 git ${2:+ -C "$2"} -c core.commitGraph=false $1 >expect &&
Derrick Stolee135a7122019-06-18 11:14:28 -070069 test_cmp expect output
70}
71
72graph_git_behavior() {
73 MSG=$1
74 BRANCH=$2
75 COMPARE=$3
Ævar Arnfjörð Bjarmasona046aa32021-10-15 01:37:15 +020076 DIR=$4
Derrick Stolee135a7122019-06-18 11:14:28 -070077 test_expect_success "check normal git operations: $MSG" '
Ævar Arnfjörð Bjarmasona046aa32021-10-15 01:37:15 +020078 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"
Derrick Stolee135a7122019-06-18 11:14:28 -070083 '
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
Derrick Stoleec5230352019-06-18 11:14:30 -0700118test_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
Derrick Stolee135a7122019-06-18 11:14:28 -0700133test_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
Derrick Stolee1771be92019-06-18 11:14:29 -0700162test_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 &&
Derrick Stolee8d840972019-06-18 11:14:31 -0700169 test_line_count = 2 graph-files &&
Derrick Stolee1771be92019-06-18 11:14:29 -0700170 verify_chain_files_exist $graphdir
171'
172
173graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6
174
Derrick Stoleec5230352019-06-18 11:14:30 -0700175test_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 &&
Derrick Stolee16110c92019-06-18 11:14:36 -0700191 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
Derrick Stoleec5230352019-06-18 11:14:30 -0700197 )
198'
199
Ævar Arnfjörð Bjarmasona046aa32021-10-15 01:37:15 +0200200if test -d fork
201then
202 graph_git_behavior 'alternate: commit 13 vs 6' commits/13 origin/commits/6 "fork"
203fi
Derrick Stoleec5230352019-06-18 11:14:30 -0700204
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700205test_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 &&
Derrick Stoleeb09b7852020-04-01 21:00:44 +0000233 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" &&
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700238 test_line_count = 1 $graphdir/commit-graph-chain &&
Derrick Stoleeb09b7852020-04-01 21:00:44 +0000239 test_path_is_missing $graphdir/to-delete.graph &&
240 test_path_is_file $graphdir/to-keep.graph &&
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700241 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
Derrick Stoleeba411122019-06-18 11:14:33 -0700258test_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
Derrick Stolee3da4b602019-06-18 11:14:32 -0700270corrupt_file() {
271 file=$1
272 pos=$2
273 data="${3:-\0}"
Derrick Stolee5b15eb32019-06-18 11:14:36 -0700274 chmod a+w "$file" &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700275 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 &&
brian m. carlson82d5aeb2019-12-21 19:49:27 +0000284 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700285 test_must_fail git commit-graph verify --shallow 2>test_err &&
286 grep -v "^+" test_err >err &&
Junio C Hamano67892752023-10-31 14:23:30 +0900287 test_grep "incorrect checksum" err
Derrick Stolee3da4b602019-06-18 11:14:32 -0700288 )
289'
290
Jeff King5f259192023-09-28 00:39:51 -0400291test_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
Derrick Stolee3da4b602019-06-18 11:14:32 -0700317test_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 &&
Jeff King4169d892023-10-09 17:04:58 -0400323 corrupt_file "$base_file" 1500 "\01" &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700324 git commit-graph verify --shallow &&
325 test_must_fail git commit-graph verify 2>test_err &&
326 grep -v "^+" test_err >err &&
Junio C Hamano67892752023-10-31 14:23:30 +0900327 test_grep "incorrect checksum" err
Derrick Stolee3da4b602019-06-18 11:14:32 -0700328 )
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 &&
brian m. carlson82d5aeb2019-12-21 19:49:27 +0000337 corrupt_file "$base_file" $(test_oid base) "\01" &&
Jeff King5f259192023-09-28 00:39:51 -0400338 test_must_fail git commit-graph verify --shallow 2>test_err &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700339 grep -v "^+" test_err >err &&
Junio C Hamano67892752023-10-31 14:23:30 +0900340 test_grep "commit-graph chain does not match" err
Derrick Stolee3da4b602019-06-18 11:14:32 -0700341 )
342'
343
Jeff King2d457102023-09-28 00:38:47 -0400344test_expect_success 'verify after commit-graph-chain corruption (base)' '
345 git clone --no-hardlinks . verify-chain-base &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700346 (
Jeff King2d457102023-09-28 00:38:47 -0400347 cd verify-chain-base &&
348 corrupt_file "$graphdir/commit-graph-chain" 30 "G" &&
Jeff King47d06bb2023-09-28 00:38:59 -0400349 test_must_fail git commit-graph verify 2>test_err &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700350 grep -v "^+" test_err >err &&
Junio C Hamano67892752023-10-31 14:23:30 +0900351 test_grep "invalid commit-graph chain" err &&
Jeff King2d457102023-09-28 00:38:47 -0400352 corrupt_file "$graphdir/commit-graph-chain" 30 "A" &&
Jeff King47d06bb2023-09-28 00:38:59 -0400353 test_must_fail git commit-graph verify 2>test_err &&
Jeff King2d457102023-09-28 00:38:47 -0400354 grep -v "^+" test_err >err &&
Junio C Hamano67892752023-10-31 14:23:30 +0900355 test_grep "unable to find all commit-graph files" err
Jeff King2d457102023-09-28 00:38:47 -0400356 )
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" &&
Jeff King5f259192023-09-28 00:39:51 -0400364 test_must_fail git commit-graph verify 2>test_err &&
Jeff King2d457102023-09-28 00:38:47 -0400365 grep -v "^+" test_err >err &&
Junio C Hamanoa8e23942023-11-08 11:04:02 +0900366 test_grep "invalid commit-graph chain" err &&
Jeff King2d457102023-09-28 00:38:47 -0400367 corrupt_file "$graphdir/commit-graph-chain" 70 "A" &&
Jeff King5f259192023-09-28 00:39:51 -0400368 test_must_fail git commit-graph verify 2>test_err &&
Derrick Stolee3da4b602019-06-18 11:14:32 -0700369 grep -v "^+" test_err >err &&
Junio C Hamanoa8e23942023-11-08 11:04:02 +0900370 test_grep "unable to find all commit-graph files" err
Derrick Stolee3da4b602019-06-18 11:14:32 -0700371 )
372'
373
Jeff King7754a562023-09-28 00:39:10 -0400374test_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
Derrick Stolee5b15eb32019-06-18 11:14:36 -0700386test_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 &&
Jeff King4169d892023-10-09 17:04:58 -0400397 corrupt_file "$tip_file" 1500 "\01" &&
Derrick Stolee5b15eb32019-06-18 11:14:36 -0700398 test_must_fail git commit-graph verify --shallow 2>test_err &&
399 grep -v "^+" test_err >err &&
Junio C Hamanoa8e23942023-11-08 11:04:02 +0900400 test_grep "incorrect checksum" err
Derrick Stolee5b15eb32019-06-18 11:14:36 -0700401 )
402'
403
Jeff King6cf61d02023-10-09 17:05:41 -0400404test_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
Derrick Stoleea09c1302019-06-18 11:14:35 -0700414 )
415'
416
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 &&
Garima Singh73716122019-08-26 09:29:58 -0700422 git commit-graph verify --progress 2>err &&
Taylor Blau9281cd02023-07-07 20:31:45 -0400423 test_line_count = 1 err &&
424 grep "Verifying commits in commit graph: 100% (18/18)" err &&
Junio C Hamano67892752023-10-31 14:23:30 +0900425 test_grep ! warning err &&
Derrick Stoleee2017c42019-06-18 11:14:34 -0700426 test_line_count = 3 $graphdir/commit-graph-chain
427'
428
429graph_git_behavior 'graph exists' merge/octopus commits/12
430
Derrick Stoleea09c1302019-06-18 11:14:35 -0700431test_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 &&
Derrick Stolee31b1de62019-08-13 11:37:45 -0700438 rm -f .git/objects/info/commit-graph &&
Derrick Stoleea09c1302019-06-18 11:14:35 -0700439 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
Taylor Blaufdbde822020-04-13 22:04:12 -0600447test_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
Taylor Blau8a6ac282020-04-13 22:04:17 -0600458test_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
Taylor Blaub78a5562020-04-23 15:41:09 -0600477test_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 &&
Denton Liu6861ac82020-07-07 02:04:35 -0400484 run_with_limited_open_files test_might_fail git commit-graph write \
Taylor Blaub78a5562020-04-23 15:41:09 -0600485 --split=no-merge --reachable || return 1
486 done
487 )
488'
489
Taylor Blauf4d62842020-04-29 11:36:42 -0600490while 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 &&
Taylor Blau45a43652020-04-29 11:36:46 -0600501 test_cmp expect actual &&
502 test_modebits $graphdir/commit-graph-chain >actual &&
Taylor Blauf4d62842020-04-29 11:36:42 -0600503 test_cmp expect actual
504 '
505done <<\EOF
5060666 -r--r--r--
5070600 -r--------
508EOF
509
Taylor Blau4f364402020-09-09 11:22:44 -0400510test_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
Derrick Stolee150f1152020-10-09 20:53:51 +0000523test_expect_success 'prevent regression for duplicate commits across layers' '
524 git init dup &&
Derrick Stolee150f1152020-10-09 20:53:51 +0000525 git -C dup commit --allow-empty -m one &&
Derrick Stolee85102ac2020-10-09 20:53:52 +0000526 git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err &&
Junio C Hamano67892752023-10-31 14:23:30 +0900527 test_grep "attempting to write a commit-graph" err &&
Derrick Stolee150f1152020-10-09 20:53:51 +0000528 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
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000536NUM_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 &&
Derrick Stolee702110a2021-02-25 18:19:43 +0000572 git -c commitGraph.generationVersion=2 commit-graph write --reachable --split &&
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000573 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 &&
Derrick Stolee702110a2021-02-25 18:19:43 +0000580 git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge &&
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000581 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
Derrick Stoleec78c7a92022-03-01 19:48:28 +0000587 options:
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000588 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
Derrick Stoleec78c7a92022-03-01 19:48:28 +0000620 options:
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000621 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
Derrick Stoleec78c7a92022-03-01 19:48:28 +0000662 options:
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000663 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
Derrick Stolee3b0199d2022-03-01 19:48:31 +0000702 options: read_generation_data
Abhishek Kumar1fdc3832021-01-16 18:11:16 +0000703 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
Derrick Stolee135a7122019-06-18 11:14:28 -0700721test_done