]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t5300-pack-object.sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git pack-object
16 perl -e "print \"a\" x 4096;" > a &&
17 perl -e "print \"b\" x 4096;" > b &&
18 perl -e "print \"c\" x 4096;" > c &&
19 test-tool genrandom "seed a" 2097152 > a_big &&
20 test-tool genrandom "seed b" 2097152 > b_big &&
21 git update-index --add a a_big b b_big c &&
22 cat c >d && echo foo >>d && git update-index --add d &&
23 tree=$(git write-tree) &&
24 commit=$(git commit-tree $tree </dev/null) && {
27 git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
29 git diff-tree --root -p $commit &&
32 t=$(git cat-file -t $object) &&
33 git cat-file $t $object || return 1
38 'pack without delta' \
39 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
42 'pack-objects with bogus arguments' \
43 'test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list'
49 'unpack without delta' \
50 "GIT_OBJECT_DIRECTORY=.git2/objects &&
51 export GIT_OBJECT_DIRECTORY &&
53 git unpack-objects -n <test-1-${packname_1}.pack &&
54 git unpack-objects <test-1-${packname_1}.pack"
56 unset GIT_OBJECT_DIRECTORY
60 'check unpack without delta' \
61 '(cd ../.git && find objects -type f -print) |
64 cmp $path ../.git/$path || {
72 'pack with REF_DELTA' \
74 packname_2=$(git pack-objects test-2 <obj-list)'
80 'unpack with REF_DELTA' \
81 'GIT_OBJECT_DIRECTORY=.git2/objects &&
82 export GIT_OBJECT_DIRECTORY &&
84 git unpack-objects -n <test-2-${packname_2}.pack &&
85 git unpack-objects <test-2-${packname_2}.pack'
87 unset GIT_OBJECT_DIRECTORY
90 'check unpack with REF_DELTA' \
91 '(cd ../.git && find objects -type f -print) |
94 cmp $path ../.git/$path || {
101 test_expect_success \
102 'pack with OFS_DELTA' \
104 packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
109 test_expect_success \
110 'unpack with OFS_DELTA' \
111 'GIT_OBJECT_DIRECTORY=.git2/objects &&
112 export GIT_OBJECT_DIRECTORY &&
114 git unpack-objects -n <test-3-${packname_3}.pack &&
115 git unpack-objects <test-3-${packname_3}.pack'
117 unset GIT_OBJECT_DIRECTORY
119 test_expect_success \
120 'check unpack with OFS_DELTA' \
121 '(cd ../.git && find objects -type f -print) |
124 cmp $path ../.git/$path || {
131 test_expect_success
'compare delta flavors' '
133 defined($_ = -s $_) or die for @ARGV;
134 exit 1 if $ARGV[0] <= $ARGV[1];
135 '\'' test-2-$packname_2.pack test-3-$packname_3.pack
141 test_expect_success \
142 'use packed objects' \
143 'GIT_OBJECT_DIRECTORY=.git2/objects &&
144 export GIT_OBJECT_DIRECTORY &&
146 cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
147 git diff-tree --root -p $commit &&
150 t=$(git cat-file -t $object) &&
151 git cat-file $t $object || return 1
156 test_expect_success \
157 'use packed deltified (REF_DELTA) objects' \
158 'GIT_OBJECT_DIRECTORY=.git2/objects &&
159 export GIT_OBJECT_DIRECTORY &&
160 rm -f .git2/objects/pack/test-* &&
161 cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
162 git diff-tree --root -p $commit &&
165 t=$(git cat-file -t $object) &&
166 git cat-file $t $object || return 1
171 test_expect_success \
172 'use packed deltified (OFS_DELTA) objects' \
173 'GIT_OBJECT_DIRECTORY=.git2/objects &&
174 export GIT_OBJECT_DIRECTORY &&
175 rm -f .git2/objects/pack/test-* &&
176 cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
177 git diff-tree --root -p $commit &&
180 t=$(git cat-file -t $object) &&
181 git cat-file $t $object || return 1
186 unset GIT_OBJECT_DIRECTORY
188 test_expect_success
'survive missing objects/pack directory' '
190 rm -fr missing-pack &&
191 mkdir missing-pack &&
194 GOP=.git/objects/pack &&
196 git index-pack --stdin --keep=test <../test-3-${packname_3}.pack &&
197 test -f $GOP/pack-${packname_3}.pack &&
198 cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack &&
199 test -f $GOP/pack-${packname_3}.idx &&
200 cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx &&
201 test -f $GOP/pack-${packname_3}.keep
205 test_expect_success \
207 'git verify-pack test-1-${packname_1}.idx \
208 test-2-${packname_2}.idx \
209 test-3-${packname_3}.idx'
211 test_expect_success \
213 'git verify-pack -v test-1-${packname_1}.idx \
214 test-2-${packname_2}.idx \
215 test-3-${packname_3}.idx'
217 test_expect_success \
218 'verify-pack catches mismatched .idx and .pack files' \
219 'cat test-1-${packname_1}.idx >test-3.idx &&
220 cat test-2-${packname_2}.pack >test-3.pack &&
221 if git verify-pack test-3.idx
226 test_expect_success \
227 'verify-pack catches a corrupted pack signature' \
228 'cat test-1-${packname_1}.pack >test-3.pack &&
229 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 &&
230 if git verify-pack test-3.idx
235 test_expect_success \
236 'verify-pack catches a corrupted pack version' \
237 'cat test-1-${packname_1}.pack >test-3.pack &&
238 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 &&
239 if git verify-pack test-3.idx
244 test_expect_success \
245 'verify-pack catches a corrupted type/size of the 1st packed object data' \
246 'cat test-1-${packname_1}.pack >test-3.pack &&
247 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 &&
248 if git verify-pack test-3.idx
253 test_expect_success \
254 'verify-pack catches a corrupted sum of the index file itself' \
255 'l=$(wc -c <test-3.idx) &&
257 cat test-1-${packname_1}.pack >test-3.pack &&
258 printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l &&
259 if git verify-pack test-3.pack
264 test_expect_success \
265 'build pack index for an existing pack' \
266 'cat test-1-${packname_1}.pack >test-3.pack &&
267 git index-pack -o tmp.idx test-3.pack &&
268 cmp tmp.idx test-1-${packname_1}.idx &&
270 git index-pack test-3.pack &&
271 cmp test-3.idx test-1-${packname_1}.idx &&
273 cat test-2-${packname_2}.pack >test-3.pack &&
274 git index-pack -o tmp.idx test-2-${packname_2}.pack &&
275 cmp tmp.idx test-2-${packname_2}.idx &&
277 git index-pack test-3.pack &&
278 cmp test-3.idx test-2-${packname_2}.idx &&
280 cat test-3-${packname_3}.pack >test-3.pack &&
281 git index-pack -o tmp.idx test-3-${packname_3}.pack &&
282 cmp tmp.idx test-3-${packname_3}.idx &&
284 git index-pack test-3.pack &&
285 cmp test-3.idx test-3-${packname_3}.idx &&
287 cat test-1-${packname_1}.pack >test-4.pack &&
289 git index-pack --keep=why test-4.pack &&
290 cmp test-1-${packname_1}.idx test-4.idx &&
291 test -f test-4.keep &&
295 test_expect_success
'unpacking with --strict' '
297 for j in a b c d e f g
299 for i in 0 1 2 3 4 5 6 7 8 9
301 o=$(echo $j$i | git hash-object -w --stdin) &&
302 echo "100644 $o 0 $j$i"
306 git update-index --index-info <LIST &&
307 LIST=$(git write-tree) &&
309 head -n 10 LIST | git update-index --index-info &&
310 LI=$(git write-tree) &&
312 tail -n 10 LIST | git update-index --index-info &&
313 ST=$(git write-tree) &&
314 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
315 PACK5=$( git pack-objects test-5 <actual ) &&
320 ) | git pack-objects test-6 ) &&
321 test_create_repo test-5 &&
324 git unpack-objects --strict <../test-5-$PACK5.pack &&
325 git ls-tree -r $LIST &&
326 git ls-tree -r $LI &&
329 test_create_repo test-6 &&
331 # tree-only into empty repo -- many unreachables
333 test_must_fail git unpack-objects --strict <../test-6-$PACK6.pack
336 # already populated -- no unreachables
338 git unpack-objects --strict <../test-6-$PACK6.pack
342 test_expect_success
'index-pack with --strict' '
344 for j in a b c d e f g
346 for i in 0 1 2 3 4 5 6 7 8 9
348 o=$(echo $j$i | git hash-object -w --stdin) &&
349 echo "100644 $o 0 $j$i"
353 git update-index --index-info <LIST &&
354 LIST=$(git write-tree) &&
356 head -n 10 LIST | git update-index --index-info &&
357 LI=$(git write-tree) &&
359 tail -n 10 LIST | git update-index --index-info &&
360 ST=$(git write-tree) &&
361 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
362 PACK5=$( git pack-objects test-5 <actual ) &&
367 ) | git pack-objects test-6 ) &&
368 test_create_repo test-7 &&
371 git index-pack --strict --stdin <../test-5-$PACK5.pack &&
372 git ls-tree -r $LIST &&
373 git ls-tree -r $LI &&
376 test_create_repo test-8 &&
378 # tree-only into empty repo -- many unreachables
380 test_must_fail git index-pack --strict --stdin <../test-6-$PACK6.pack
383 # already populated -- no unreachables
385 git index-pack --strict --stdin <../test-6-$PACK6.pack
389 test_expect_success
'honor pack.packSizeLimit' '
390 git config pack.packSizeLimit 3m &&
391 packname_10=$(git pack-objects test-10 <obj-list) &&
392 test 2 = $(ls test-10-*.pack | wc -l)
395 test_expect_success
'verify resulting packs' '
396 git verify-pack test-10-*.pack
399 test_expect_success
'tolerate packsizelimit smaller than biggest object' '
400 git config pack.packSizeLimit 1 &&
401 packname_11=$(git pack-objects test-11 <obj-list) &&
402 test 5 = $(ls test-11-*.pack | wc -l)
405 test_expect_success
'verify resulting packs' '
406 git verify-pack test-11-*.pack
409 test_expect_success
'set up pack for non-repo tests' '
410 # make sure we have a pack with no matching index file
411 cp test-1-*.pack foo.pack
414 test_expect_success
'index-pack --stdin complains of non-repo' '
415 nongit test_must_fail git index-pack --object-format=$(test_oid algo) --stdin <foo.pack &&
416 test_path_is_missing non-repo/.git
419 test_expect_success
'index-pack <pack> works in non-repo' '
420 nongit git index-pack --object-format=$(test_oid algo) ../foo.pack &&
421 test_path_is_file foo.idx
424 test_expect_success
'index-pack --strict <pack> works in non-repo' '
426 nongit git index-pack --strict --object-format=$(test_oid algo) ../foo.pack &&
427 test_path_is_file foo.idx
430 test_expect_success
!PTHREADS
,!FAIL_PREREQS \
431 'index-pack --threads=N or pack.threads=N warns when no pthreads' '
432 test_must_fail git index-pack --threads=2 2>err &&
433 grep ^warning: err >warnings &&
434 test_line_count = 1 warnings &&
435 grep -F "no threads support, ignoring --threads=2" err &&
437 test_must_fail git -c pack.threads=2 index-pack 2>err &&
438 grep ^warning: err >warnings &&
439 test_line_count = 1 warnings &&
440 grep -F "no threads support, ignoring pack.threads" err &&
442 test_must_fail git -c pack.threads=2 index-pack --threads=4 2>err &&
443 grep ^warning: err >warnings &&
444 test_line_count = 2 warnings &&
445 grep -F "no threads support, ignoring --threads=4" err &&
446 grep -F "no threads support, ignoring pack.threads" err
449 test_expect_success
!PTHREADS
,!FAIL_PREREQS \
450 'pack-objects --threads=N or pack.threads=N warns when no pthreads' '
451 git pack-objects --threads=2 --stdout --all </dev/null >/dev/null 2>err &&
452 grep ^warning: err >warnings &&
453 test_line_count = 1 warnings &&
454 grep -F "no threads support, ignoring --threads" err &&
456 git -c pack.threads=2 pack-objects --stdout --all </dev/null >/dev/null 2>err &&
457 grep ^warning: err >warnings &&
458 test_line_count = 1 warnings &&
459 grep -F "no threads support, ignoring pack.threads" err &&
461 git -c pack.threads=2 pack-objects --threads=4 --stdout --all </dev/null >/dev/null 2>err &&
462 grep ^warning: err >warnings &&
463 test_line_count = 2 warnings &&
464 grep -F "no threads support, ignoring --threads" err &&
465 grep -F "no threads support, ignoring pack.threads" err
468 test_expect_success
'pack-objects in too-many-packs mode' '
469 GIT_TEST_FULL_IN_PACK_ARRAY=1 git repack -ad &&
473 test_expect_success
'setup: fake a SHA1 hash collision' '
477 long_a=$(git hash-object -w ../a | sed -e "s!^..!&/!") &&
478 long_b=$(git hash-object -w ../b | sed -e "s!^..!&/!") &&
479 test -f .git/objects/$long_b &&
480 cp -f .git/objects/$long_a \
485 test_expect_success
'make sure index-pack detects the SHA1 collision' '
488 test_must_fail git index-pack -o ../bad.idx ../test-3.pack 2>msg &&
489 test_i18ngrep "SHA1 COLLISION FOUND" msg
493 test_expect_success
'make sure index-pack detects the SHA1 collision (large blobs)' '
496 test_must_fail git -c core.bigfilethreshold=1 index-pack -o ../bad.idx ../test-3.pack 2>msg &&
497 test_i18ngrep "SHA1 COLLISION FOUND" msg
501 test_expect_success
'prefetch objects' '
502 rm -rf server client &&
505 test_config -C server uploadpack.allowanysha1inwant 1 &&
506 test_config -C server uploadpack.allowfilter 1 &&
507 test_config -C server protocol.version 2 &&
509 echo one >server/one &&
510 git -C server add one &&
511 git -C server commit -m one &&
512 git -C server branch one_branch &&
514 echo two_a >server/two_a &&
515 echo two_b >server/two_b &&
516 git -C server add two_a two_b &&
517 git -C server commit -m two &&
519 echo three >server/three &&
520 git -C server add three &&
521 git -C server commit -m three &&
522 git -C server branch three_branch &&
524 # Clone, fetch "two" with blobs excluded, and re-push it. This requires
525 # the client to have the blobs of "two" - verify that these are
526 # prefetched in one batch.
527 git clone --filter=blob:none --single-branch -b one_branch \
528 "file://$(pwd)/server" client &&
529 test_config -C client protocol.version 2 &&
530 TWO=$(git -C server rev-parse three_branch^) &&
531 git -C client fetch --filter=blob:none origin "$TWO" &&
532 GIT_TRACE_PACKET=$(pwd)/trace git -C client push origin "$TWO":refs/heads/two_branch &&
533 grep "fetch> done" trace >donelines &&
534 test_line_count = 1 donelines
537 test_expect_success
'setup for --stdin-packs tests' '
538 git init stdin-packs &&
548 git pack-objects .git/objects/pack/pack-$id \
549 --incremental --revs <<-EOF
554 ls -la .git/objects/pack
558 test_expect_success
'--stdin-packs with excluded packs' '
562 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
563 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
564 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
566 git pack-objects test --stdin-packs <<-EOF &&
573 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
574 git show-index <$(ls .git/objects/pack/pack-C-*.idx)
576 git show-index <$(ls test-*.idx) >actual.raw &&
578 cut -d" " -f2 <expect.raw | sort >expect &&
579 cut -d" " -f2 <actual.raw | sort >actual &&
580 test_cmp expect actual
584 test_expect_success
'--stdin-packs is incompatible with --filter' '
587 test_must_fail git pack-objects --stdin-packs --stdout \
588 --filter=blob:none </dev/null 2>err &&
589 test_i18ngrep "cannot use --filter with --stdin-packs" err
593 test_expect_success
'--stdin-packs is incompatible with --revs' '
596 test_must_fail git pack-objects --stdin-packs --revs out \
598 test_i18ngrep "cannot use internal rev list with --stdin-packs" err
602 test_expect_success
'--stdin-packs with loose objects' '
606 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
607 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
608 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
610 test_commit D && # loose
612 git pack-objects test2 --stdin-packs --unpacked <<-EOF &&
619 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
620 git show-index <$(ls .git/objects/pack/pack-C-*.idx) &&
621 git rev-list --objects --no-object-names \
622 refs/tags/C..refs/tags/D
626 git show-index <$(ls test2-*.idx) >actual.raw &&
628 cut -d" " -f2 <expect.raw | sort >expect &&
629 cut -d" " -f2 <actual.raw | sort >actual &&
630 test_cmp expect actual
634 test_expect_success
'--stdin-packs with broken links' '
638 # make an unreachable object with a bogus parent
639 git cat-file -p HEAD >commit &&
640 sed "s/$(git rev-parse HEAD^)/$(test_oid zero)/" <commit |
641 git hash-object -w -t commit --stdin >in &&
643 git pack-objects .git/objects/pack/pack-D <in &&
645 PACK_A="$(basename .git/objects/pack/pack-A-*.pack)" &&
646 PACK_B="$(basename .git/objects/pack/pack-B-*.pack)" &&
647 PACK_C="$(basename .git/objects/pack/pack-C-*.pack)" &&
648 PACK_D="$(basename .git/objects/pack/pack-D-*.pack)" &&
650 git pack-objects test3 --stdin-packs --unpacked <<-EOF &&
658 git show-index <$(ls .git/objects/pack/pack-A-*.idx) &&
659 git show-index <$(ls .git/objects/pack/pack-C-*.idx) &&
660 git show-index <$(ls .git/objects/pack/pack-D-*.idx) &&
661 git rev-list --objects --no-object-names \
662 refs/tags/C..refs/tags/D
664 git show-index <$(ls test3-*.idx) >actual.raw &&
666 cut -d" " -f2 <expect.raw | sort >expect &&
667 cut -d" " -f2 <actual.raw | sort >actual &&
668 test_cmp expect actual