]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5324-split-commit-graph.sh
Merge branch 'ea/blame-use-oideq'
[thirdparty/git.git] / t / t5324-split-commit-graph.sh
CommitLineData
135a7123
DS
1#!/bin/sh
2
3test_description='split commit graph'
4. ./test-lib.sh
5
6GIT_TEST_COMMIT_GRAPH=0
d5b873c8 7GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
135a7123
DS
8
9test_expect_success 'setup repo' '
10 git init &&
11 git config core.commitGraph true &&
31b1de6a 12 git config gc.writeCommitGraph false &&
135a7123
DS
13 infodir=".git/objects/info" &&
14 graphdir="$infodir/commit-graphs" &&
82d5aeb1 15 test_oid_cache <<-EOM
16 shallow sha1:1760
17 shallow sha256:2064
18
19 base sha1:1376
20 base sha256:1496
665d70ad
DS
21
22 oid_version sha1:1
23 oid_version sha256:2
82d5aeb1 24 EOM
135a7123
DS
25'
26
27graph_read_expect() {
28 NUM_BASE=0
29 if test ! -z $2
30 then
31 NUM_BASE=$2
32 fi
33 cat >expect <<- EOF
665d70ad 34 header: 43475048 1 $(test_oid oid_version) 3 $NUM_BASE
135a7123
DS
35 num_commits: $1
36 chunks: oid_fanout oid_lookup commit_metadata
37 EOF
4bd0593e 38 test-tool read-graph >output &&
135a7123
DS
39 test_cmp expect output
40}
41
f4d62847
TB
42test_expect_success POSIXPERM 'tweak umask for modebit tests' '
43 umask 022
44'
45
135a7123
DS
46test_expect_success 'create commits and write commit-graph' '
47 for i in $(test_seq 3)
48 do
49 test_commit $i &&
50 git branch commits/$i || return 1
51 done &&
52 git commit-graph write --reachable &&
53 test_path_is_file $infodir/commit-graph &&
54 graph_read_expect 3
55'
56
57graph_git_two_modes() {
58 git -c core.commitGraph=true $1 >output
59 git -c core.commitGraph=false $1 >expect
60 test_cmp expect output
61}
62
63graph_git_behavior() {
64 MSG=$1
65 BRANCH=$2
66 COMPARE=$3
67 test_expect_success "check normal git operations: $MSG" '
68 graph_git_two_modes "log --oneline $BRANCH" &&
69 graph_git_two_modes "log --topo-order $BRANCH" &&
70 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
71 graph_git_two_modes "branch -vv" &&
72 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
73 '
74}
75
76graph_git_behavior 'graph exists' commits/3 commits/1
77
78verify_chain_files_exist() {
79 for hash in $(cat $1/commit-graph-chain)
80 do
81 test_path_is_file $1/graph-$hash.graph || return 1
82 done
83}
84
85test_expect_success 'add more commits, and write a new base graph' '
86 git reset --hard commits/1 &&
87 for i in $(test_seq 4 5)
88 do
89 test_commit $i &&
90 git branch commits/$i || return 1
91 done &&
92 git reset --hard commits/2 &&
93 for i in $(test_seq 6 10)
94 do
95 test_commit $i &&
96 git branch commits/$i || return 1
97 done &&
98 git reset --hard commits/2 &&
99 git merge commits/4 &&
100 git branch merge/1 &&
101 git reset --hard commits/4 &&
102 git merge commits/6 &&
103 git branch merge/2 &&
104 git commit-graph write --reachable &&
105 graph_read_expect 12
106'
107
c523035c
DS
108test_expect_success 'fork and fail to base a chain on a commit-graph file' '
109 test_when_finished rm -rf fork &&
110 git clone . fork &&
111 (
112 cd fork &&
113 rm .git/objects/info/commit-graph &&
114 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
115 test_commit new-commit &&
116 git commit-graph write --reachable --split &&
117 test_path_is_file $graphdir/commit-graph-chain &&
118 test_line_count = 1 $graphdir/commit-graph-chain &&
119 verify_chain_files_exist $graphdir
120 )
121'
122
135a7123
DS
123test_expect_success 'add three more commits, write a tip graph' '
124 git reset --hard commits/3 &&
125 git merge merge/1 &&
126 git merge commits/5 &&
127 git merge merge/2 &&
128 git branch merge/3 &&
129 git commit-graph write --reachable --split &&
130 test_path_is_missing $infodir/commit-graph &&
131 test_path_is_file $graphdir/commit-graph-chain &&
132 ls $graphdir/graph-*.graph >graph-files &&
133 test_line_count = 2 graph-files &&
134 verify_chain_files_exist $graphdir
135'
136
137graph_git_behavior 'split commit-graph: merge 3 vs 2' merge/3 merge/2
138
139test_expect_success 'add one commit, write a tip graph' '
140 test_commit 11 &&
141 git branch commits/11 &&
142 git commit-graph write --reachable --split &&
143 test_path_is_missing $infodir/commit-graph &&
144 test_path_is_file $graphdir/commit-graph-chain &&
145 ls $graphdir/graph-*.graph >graph-files &&
146 test_line_count = 3 graph-files &&
147 verify_chain_files_exist $graphdir
148'
149
150graph_git_behavior 'three-layer commit-graph: commit 11 vs 6' commits/11 commits/6
151
1771be90
DS
152test_expect_success 'add one commit, write a merged graph' '
153 test_commit 12 &&
154 git branch commits/12 &&
155 git commit-graph write --reachable --split &&
156 test_path_is_file $graphdir/commit-graph-chain &&
157 test_line_count = 2 $graphdir/commit-graph-chain &&
158 ls $graphdir/graph-*.graph >graph-files &&
8d84097f 159 test_line_count = 2 graph-files &&
1771be90
DS
160 verify_chain_files_exist $graphdir
161'
162
163graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6
164
c523035c
DS
165test_expect_success 'create fork and chain across alternate' '
166 git clone . fork &&
167 (
168 cd fork &&
169 git config core.commitGraph true &&
170 rm -rf $graphdir &&
171 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
172 test_commit 13 &&
173 git branch commits/13 &&
174 git commit-graph write --reachable --split &&
175 test_path_is_file $graphdir/commit-graph-chain &&
176 test_line_count = 3 $graphdir/commit-graph-chain &&
177 ls $graphdir/graph-*.graph >graph-files &&
178 test_line_count = 1 graph-files &&
179 git -c core.commitGraph=true rev-list HEAD >expect &&
180 git -c core.commitGraph=false rev-list HEAD >actual &&
16110c93
DS
181 test_cmp expect actual &&
182 test_commit 14 &&
183 git commit-graph write --reachable --split --object-dir=.git/objects/ &&
184 test_line_count = 3 $graphdir/commit-graph-chain &&
185 ls $graphdir/graph-*.graph >graph-files &&
186 test_line_count = 1 graph-files
c523035c
DS
187 )
188'
189
190graph_git_behavior 'alternate: commit 13 vs 6' commits/13 commits/6
191
c2bc6e6a
DS
192test_expect_success 'test merge stragety constants' '
193 git clone . merge-2 &&
194 (
195 cd merge-2 &&
196 git config core.commitGraph true &&
197 test_line_count = 2 $graphdir/commit-graph-chain &&
198 test_commit 14 &&
199 git commit-graph write --reachable --split --size-multiple=2 &&
200 test_line_count = 3 $graphdir/commit-graph-chain
201
202 ) &&
203 git clone . merge-10 &&
204 (
205 cd merge-10 &&
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=10 &&
210 test_line_count = 1 $graphdir/commit-graph-chain &&
211 ls $graphdir/graph-*.graph >graph-files &&
212 test_line_count = 1 graph-files
213 ) &&
214 git clone . merge-10-expire &&
215 (
216 cd merge-10-expire &&
217 git config core.commitGraph true &&
218 test_line_count = 2 $graphdir/commit-graph-chain &&
219 test_commit 15 &&
b09b785c
DS
220 touch $graphdir/to-delete.graph $graphdir/to-keep.graph &&
221 test-tool chmtime =1546362000 $graphdir/to-delete.graph &&
222 test-tool chmtime =1546362001 $graphdir/to-keep.graph &&
223 git commit-graph write --reachable --split --size-multiple=10 \
224 --expire-time="2019-01-01 12:00 -05:00" &&
c2bc6e6a 225 test_line_count = 1 $graphdir/commit-graph-chain &&
b09b785c
DS
226 test_path_is_missing $graphdir/to-delete.graph &&
227 test_path_is_file $graphdir/to-keep.graph &&
c2bc6e6a
DS
228 ls $graphdir/graph-*.graph >graph-files &&
229 test_line_count = 3 graph-files
230 ) &&
231 git clone --no-hardlinks . max-commits &&
232 (
233 cd max-commits &&
234 git config core.commitGraph true &&
235 test_line_count = 2 $graphdir/commit-graph-chain &&
236 test_commit 16 &&
237 test_commit 17 &&
238 git commit-graph write --reachable --split --max-commits=1 &&
239 test_line_count = 1 $graphdir/commit-graph-chain &&
240 ls $graphdir/graph-*.graph >graph-files &&
241 test_line_count = 1 graph-files
242 )
243'
244
ba41112a
DS
245test_expect_success 'remove commit-graph-chain file after flattening' '
246 git clone . flatten &&
247 (
248 cd flatten &&
249 test_line_count = 2 $graphdir/commit-graph-chain &&
250 git commit-graph write --reachable &&
251 test_path_is_missing $graphdir/commit-graph-chain &&
252 ls $graphdir >graph-files &&
253 test_line_count = 0 graph-files
254 )
255'
256
3da4b609
DS
257corrupt_file() {
258 file=$1
259 pos=$2
260 data="${3:-\0}"
5b15eb39 261 chmod a+w "$file" &&
3da4b609
DS
262 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
263}
264
265test_expect_success 'verify hashes along chain, even in shallow' '
266 git clone --no-hardlinks . verify &&
267 (
268 cd verify &&
269 git commit-graph verify &&
270 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
82d5aeb1 271 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
3da4b609
DS
272 test_must_fail git commit-graph verify --shallow 2>test_err &&
273 grep -v "^+" test_err >err &&
274 test_i18ngrep "incorrect checksum" err
275 )
276'
277
278test_expect_success 'verify --shallow does not check base contents' '
279 git clone --no-hardlinks . verify-shallow &&
280 (
281 cd verify-shallow &&
282 git commit-graph verify &&
283 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
284 corrupt_file "$base_file" 1000 "\01" &&
285 git commit-graph verify --shallow &&
286 test_must_fail git commit-graph verify 2>test_err &&
287 grep -v "^+" test_err >err &&
288 test_i18ngrep "incorrect checksum" err
289 )
290'
291
292test_expect_success 'warn on base graph chunk incorrect' '
293 git clone --no-hardlinks . base-chunk &&
294 (
295 cd base-chunk &&
296 git commit-graph verify &&
297 base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
82d5aeb1 298 corrupt_file "$base_file" $(test_oid base) "\01" &&
3da4b609
DS
299 git commit-graph verify --shallow 2>test_err &&
300 grep -v "^+" test_err >err &&
301 test_i18ngrep "commit-graph chain does not match" err
302 )
303'
304
305test_expect_success 'verify after commit-graph-chain corruption' '
306 git clone --no-hardlinks . verify-chain &&
307 (
308 cd verify-chain &&
309 corrupt_file "$graphdir/commit-graph-chain" 60 "G" &&
310 git commit-graph verify 2>test_err &&
311 grep -v "^+" test_err >err &&
312 test_i18ngrep "invalid commit-graph chain" err &&
313 corrupt_file "$graphdir/commit-graph-chain" 60 "A" &&
314 git commit-graph verify 2>test_err &&
315 grep -v "^+" test_err >err &&
316 test_i18ngrep "unable to find all commit-graph files" err
317 )
318'
319
5b15eb39
DS
320test_expect_success 'verify across alternates' '
321 git clone --no-hardlinks . verify-alt &&
322 (
323 cd verify-alt &&
324 rm -rf $graphdir &&
325 altdir="$(pwd)/../.git/objects" &&
326 echo "$altdir" >.git/objects/info/alternates &&
327 git commit-graph verify --object-dir="$altdir/" &&
328 test_commit extra &&
329 git commit-graph write --reachable --split &&
330 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
331 corrupt_file "$tip_file" 100 "\01" &&
332 test_must_fail git commit-graph verify --shallow 2>test_err &&
333 grep -v "^+" test_err >err &&
334 test_i18ngrep "commit-graph has incorrect fanout value" err
335 )
336'
337
e2017c48
DS
338test_expect_success 'add octopus merge' '
339 git reset --hard commits/10 &&
340 git merge commits/3 commits/4 &&
341 git branch merge/octopus &&
342 git commit-graph write --reachable --split &&
73716122 343 git commit-graph verify --progress 2>err &&
a35bea40
DS
344 test_line_count = 3 err &&
345 test_i18ngrep ! warning err &&
e2017c48
DS
346 test_line_count = 3 $graphdir/commit-graph-chain
347'
348
349graph_git_behavior 'graph exists' merge/octopus commits/12
350
a09c1301
DS
351test_expect_success 'split across alternate where alternate is not split' '
352 git commit-graph write --reachable &&
353 test_path_is_file .git/objects/info/commit-graph &&
354 cp .git/objects/info/commit-graph . &&
355 git clone --no-hardlinks . alt-split &&
356 (
357 cd alt-split &&
31b1de6a 358 rm -f .git/objects/info/commit-graph &&
a09c1301
DS
359 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
360 test_commit 18 &&
361 git commit-graph write --reachable --split &&
362 test_line_count = 1 $graphdir/commit-graph-chain
363 ) &&
364 test_cmp commit-graph .git/objects/info/commit-graph
365'
366
fdbde82f
TB
367test_expect_success '--split=no-merge always writes an incremental' '
368 test_when_finished rm -rf a b &&
369 rm -rf $graphdir $infodir/commit-graph &&
370 git reset --hard commits/2 &&
371 git rev-list HEAD~1 >a &&
372 git rev-list HEAD >b &&
373 git commit-graph write --split --stdin-commits <a &&
374 git commit-graph write --split=no-merge --stdin-commits <b &&
375 test_line_count = 2 $graphdir/commit-graph-chain
376'
377
8a6ac287
TB
378test_expect_success '--split=replace replaces the chain' '
379 rm -rf $graphdir $infodir/commit-graph &&
380 git reset --hard commits/3 &&
381 git rev-list -1 HEAD~2 >a &&
382 git rev-list -1 HEAD~1 >b &&
383 git rev-list -1 HEAD >c &&
384 git commit-graph write --split=no-merge --stdin-commits <a &&
385 git commit-graph write --split=no-merge --stdin-commits <b &&
386 git commit-graph write --split=no-merge --stdin-commits <c &&
387 test_line_count = 3 $graphdir/commit-graph-chain &&
388 git commit-graph write --stdin-commits --split=replace <b &&
389 test_path_is_missing $infodir/commit-graph &&
390 test_path_is_file $graphdir/commit-graph-chain &&
391 ls $graphdir/graph-*.graph >graph-files &&
392 test_line_count = 1 graph-files &&
393 verify_chain_files_exist $graphdir &&
394 graph_read_expect 2
395'
396
b78a556a
TB
397test_expect_success ULIMIT_FILE_DESCRIPTORS 'handles file descriptor exhaustion' '
398 git init ulimit &&
399 (
400 cd ulimit &&
401 for i in $(test_seq 64)
402 do
403 test_commit $i &&
6861ac80 404 run_with_limited_open_files test_might_fail git commit-graph write \
b78a556a
TB
405 --split=no-merge --reachable || return 1
406 done
407 )
408'
409
f4d62847
TB
410while read mode modebits
411do
412 test_expect_success POSIXPERM "split commit-graph respects core.sharedrepository $mode" '
413 rm -rf $graphdir $infodir/commit-graph &&
414 git reset --hard commits/1 &&
415 test_config core.sharedrepository "$mode" &&
416 git commit-graph write --split --reachable &&
417 ls $graphdir/graph-*.graph >graph-files &&
418 test_line_count = 1 graph-files &&
419 echo "$modebits" >expect &&
420 test_modebits $graphdir/graph-*.graph >actual &&
45a4365c
TB
421 test_cmp expect actual &&
422 test_modebits $graphdir/commit-graph-chain >actual &&
f4d62847
TB
423 test_cmp expect actual
424 '
425done <<\EOF
4260666 -r--r--r--
4270600 -r--------
428EOF
429
135a7123 430test_done