Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5300-pack-object.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5300-pack-object.sh` 769 lines ยท 23861 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2005 Junio C Hamano 4 # 5 6 test_description='git pack-object' 7 8 . ./test-lib.sh 9 10 test_expect_success 'setup' ' 11 rm -f .git/index* && 12 test-tool genzeros 4096 | tr "\000" "a" >a && 13 test-tool genzeros 4096 | tr "\000" "b" >b && 14 test-tool genzeros 4096 | tr "\000" "c" >c && 15 test-tool genrandom "seed a" `2097152` >a_big && 16 test-tool genrandom "seed b" `2097152` >b_big && 17 git update-index --add a a_big b b_big c && 18 cat c >d && echo foo >>d && git update-index --add d && 19 tree=$(git write-tree) && 20 commit=$(git commit-tree $tree obj-list && 26 { 27 git diff-tree --root -p $commit && 28 while read object 29 do 30 t=$(git cat-file -t $object) && 31 git cat-file $t $object || return 1 32 done expect 34 ' 35 36 test_expect_success 'pack-object traces bytes written to stdout' ' 37 test_when_finished "rm -f pack.trace pack.pack" && 38 GIT_TRACE2_EVENT="$PWD/pack.trace" \ 39 git pack-objects --quiet --revs --stdout >pack.pack <<-EOF && 40 $commit 41 EOF 42 bytes=$(test_file_size pack.pack) && 43 test_grep "\"key\":\"write_pack_file/wrote_bytes\",\"value\":\"$bytes\"" pack.trace 44 ' 45 46 test_expect_success 'pack-object traces bytes written to split pack files' ' 47 test_when_finished "rm -f split.trace traced-pack-*" && 48 GIT_TRACE2_EVENT="$PWD/split.trace" \ 49 git -c pack.packSizeLimit=3m pack-objects --quiet traced-pack in <<-EOF && 69 $(git -C pack-object-stdin rev-parse one) 70 EOF 71 72 git -C pack-object-stdin pack-objects basic-stdin actual && 75 test_line_count = 1 actual && 76 77 git -C pack-object-stdin pack-objects --revs basic-stdin-revs actual && 80 test_line_count = 3 actual 81 ' 82 83 test_expect_success 'pack-object in <<-EOF && 85 $(git -C pack-object-stdin rev-parse one) 86 garbage 87 $(git -C pack-object-stdin rev-parse two) 88 EOF 89 90 sed "s/^> //g" >err.expect <<-EOF && 91 fatal: expected object ID, got garbage: 92 > garbage 93 94 EOF 95 test_must_fail git -C pack-object-stdin pack-objects bad-line-stdin err.actual && 96 test_cmp err.expect err.actual && 97 98 cat >err.expect <<-EOF && 99 fatal: bad revision '"'"'garbage'"'"' 100 EOF 101 test_must_fail git -C pack-object-stdin pack-objects --revs bad-line-stdin-revs err.actual && 102 test_cmp err.expect err.actual 103 ' 104 105 test_expect_success 'pack-object in <<-EOF && 107 $(git -C pack-object-stdin rev-parse one) 108 109 $(git -C pack-object-stdin rev-parse two) 110 EOF 111 112 sed -e "s/^> //g" -e "s/Z$//g" >err.expect <<-EOF && 113 fatal: expected object ID, got garbage: 114 > Z 115 116 EOF 117 test_must_fail git -C pack-object-stdin pack-objects empty-line-stdin err.actual && 118 test_cmp err.expect err.actual && 119 120 git -C pack-object-stdin pack-objects --revs empty-line-stdin-revs actual && 123 test_line_count = 3 actual 124 ' 125 126 test_expect_success 'pack-object in <<-EOF && 128 $(git -C pack-object-stdin rev-parse one) 129 $(git -C pack-object-stdin rev-parse two) 130 EOF 131 132 # There is the "--stdin-packs is incompatible with --revs" 133 # test below, but we should make sure that the revision.c 134 # --stdin is not picked up 135 cat >err.expect <<-EOF && 136 fatal: disallowed abbreviated or ambiguous option '"'"'stdin'"'"' 137 EOF 138 test_must_fail git -C pack-object-stdin pack-objects stdin-with-stdin-option --stdin err.actual && 139 test_cmp err.expect err.actual && 140 141 test_must_fail git -C pack-object-stdin pack-objects --stdin --revs stdin-with-stdin-option-revs 2>err.actual in <<-EOF && 147 $(git -C pack-object-stdin rev-parse one) 148 $(git -C pack-object-stdin rev-parse two) 149 EOF 150 151 # That we get "two" and not "one" has to do with OID 152 # ordering. It happens to be the same here under SHA-1 and 153 # SHA-256. See commentary in pack-objects.c 154 cat >err.expect <<-EOF && 155 fatal: could not find pack '"'"'$(git -C pack-object-stdin rev-parse two)'"'"' 156 EOF 157 test_must_fail git \ 158 -C pack-object-stdin \ 159 pack-objects stdin-with-stdin-option --stdin-packs \ 160 err.actual && 161 test_cmp err.expect err.actual 162 ' 163 164 # usage: check_deltas 165 # e.g.: check_deltas stderr -gt 0 166 check_deltas() { 167 deltas=$(sed -n 's/Total [0-9][0-9]* (delta \([0-9][0-9]*\)).*/\1/p' "$1") && 168 shift && 169 if ! test "$deltas" "$@" 170 then 171 echo >&2 "unexpected number of deltas (compared $delta $*)" 172 return 1 173 fi 174 } 175 176 test_expect_success 'pack without delta' ' 177 packname_1=$(git pack-objects --progress --window=0 test-1 \ 178 stderr) && 179 check_deltas stderr = 0 180 ' 181 182 test_expect_success 'negative window clamps to 0' ' 183 git pack-objects --progress --window=-1 neg-window stderr && 184 check_deltas stderr = 0 185 ' 186 187 test_expect_success 'pack-objects with bogus arguments' ' 188 test_must_fail git pack-objects --window=0 test-1 blah blah current && 202 cmp "$object_list" current 203 } 204 205 test_expect_success 'unpack without delta' ' 206 check_unpack test-1-${packname_1} obj-list 207 ' 208 209 BATCH_CONFIGURATION='-c core.fsync=loose-object -c core.fsyncmethod=batch' 210 211 test_expect_success 'unpack without delta (core.fsyncmethod=batch)' ' 212 check_unpack test-1-${packname_1} obj-list "$BATCH_CONFIGURATION" 213 ' 214 215 test_expect_success 'pack with REF_DELTA' ' 216 packname_2=$(git pack-objects --progress test-2 stderr) && 217 check_deltas stderr -gt 0 218 ' 219 220 test_expect_success 'unpack with REF_DELTA' ' 221 check_unpack test-2-${packname_2} obj-list 222 ' 223 224 test_expect_success 'unpack with REF_DELTA (core.fsyncmethod=batch)' ' 225 check_unpack test-2-${packname_2} obj-list "$BATCH_CONFIGURATION" 226 ' 227 228 test_expect_success 'pack with OFS_DELTA' ' 229 packname_3=$(git pack-objects --progress --delta-base-offset test-3 \ 230 stderr) && 231 check_deltas stderr -gt 0 232 ' 233 234 test_expect_success 'unpack with OFS_DELTA' ' 235 check_unpack test-3-${packname_3} obj-list 236 ' 237 238 test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' ' 239 check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION" 240 ' 241 242 test_expect_success PERL_TEST_HELPERS 'compare delta flavors' ' 243 perl -e '\'' 244 defined($_ = -s $_) or die for @ARGV; 245 exit 1 if $ARGV[0] <= $ARGV[1]; 246 '\'' test-2-$packname_2.pack test-3-$packname_3.pack 247 ' 248 249 check_use_objects () { 250 test_when_finished "rm -rf git2" && 251 git init --bare git2 && 252 cp "$1".pack "$1".idx git2/objects/pack && 253 ( 254 cd git2 && 255 git diff-tree --root -p $commit && 256 while read object 257 do 258 t=$(git cat-file -t $object) && 259 git cat-file $t $object || exit 1 260 done 261 ) current && 262 cmp expect current 263 } 264 265 test_expect_success 'use packed objects' ' 266 check_use_objects test-1-${packname_1} 267 ' 268 269 test_expect_success 'use packed deltified (REF_DELTA) objects' ' 270 check_use_objects test-2-${packname_2} 271 ' 272 273 test_expect_success 'use packed deltified (OFS_DELTA) objects' ' 274 check_use_objects test-3-${packname_3} 275 ' 276 277 test_expect_success 'survive missing objects/pack directory' ' 278 ( 279 rm -fr missing-pack && 280 mkdir missing-pack && 281 cd missing-pack && 282 git init && 283 GOP=.git/objects/pack && 284 rm -fr $GOP && 285 git index-pack --stdin --keep=test <../test-3-${packname_3}.pack && 286 test_path_is_file $GOP/pack-${packname_3}.pack && 287 cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack && 288 test_path_is_file $GOP/pack-${packname_3}.idx && 289 cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx && 290 test_path_is_file $GOP/pack-${packname_3}.keep 291 ) 292 ' 293 294 test_expect_success 'verify pack' ' 295 git verify-pack test-1-${packname_1}.idx \ 296 test-2-${packname_2}.idx \ 297 test-3-${packname_3}.idx 298 ' 299 300 test_expect_success 'verify pack -v' ' 301 git verify-pack -v test-1-${packname_1}.idx \ 302 test-2-${packname_2}.idx \ 303 test-3-${packname_3}.idx 304 ' 305 306 test_expect_success 'verify-pack catches mismatched .idx and .pack files' ' 307 cat test-1-${packname_1}.idx >test-3.idx && 308 cat test-2-${packname_2}.pack >test-3.pack && 309 if git verify-pack test-3.idx 310 then false 311 else :; 312 fi 313 ' 314 315 test_expect_success 'verify-pack catches a corrupted pack signature' ' 316 cat test-1-${packname_1}.pack >test-3.pack && 317 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=2 && 318 if git verify-pack test-3.idx 319 then false 320 else :; 321 fi 322 ' 323 324 test_expect_success 'verify-pack catches a corrupted pack version' ' 325 cat test-1-${packname_1}.pack >test-3.pack && 326 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=7 && 327 if git verify-pack test-3.idx 328 then false 329 else :; 330 fi 331 ' 332 333 test_expect_success 'verify-pack catches a corrupted type/size of the 1st packed object data' ' 334 cat test-1-${packname_1}.pack >test-3.pack && 335 echo | dd of=test-3.pack count=1 bs=1 conv=notrunc seek=12 && 336 if git verify-pack test-3.idx 337 then false 338 else :; 339 fi 340 ' 341 342 test_expect_success 'verify-pack catches a corrupted sum of the index file itself' ' 343 l=$(wc -c test-3.pack && 346 printf "%20s" "" | dd of=test-3.idx count=20 bs=1 conv=notrunc seek=$l && 347 if git verify-pack test-3.pack 348 then false 349 else :; 350 fi 351 ' 352 353 test_expect_success 'build pack index for an existing pack' ' 354 cat test-1-${packname_1}.pack >test-3.pack && 355 git index-pack -o tmp.idx test-3.pack && 356 cmp tmp.idx test-1-${packname_1}.idx && 357 358 git index-pack test-3.pack && 359 cmp test-3.idx test-1-${packname_1}.idx && 360 361 cat test-2-${packname_2}.pack >test-3.pack && 362 git index-pack -o tmp.idx test-2-${packname_2}.pack && 363 cmp tmp.idx test-2-${packname_2}.idx && 364 365 git index-pack test-3.pack && 366 cmp test-3.idx test-2-${packname_2}.idx && 367 368 cat test-3-${packname_3}.pack >test-3.pack && 369 git index-pack -o tmp.idx test-3-${packname_3}.pack && 370 cmp tmp.idx test-3-${packname_3}.idx && 371 372 git index-pack test-3.pack && 373 cmp test-3.idx test-3-${packname_3}.idx && 374 375 cat test-1-${packname_1}.pack >test-4.pack && 376 rm -f test-4.keep && 377 git index-pack --keep=why test-4.pack && 378 cmp test-1-${packname_1}.idx test-4.idx && 379 test_path_is_file test-4.keep && 380 381 : 382 ' 383 384 test_expect_success 'unpacking with --strict' ' 385 386 for j in a b c d e f g 387 do 388 for i in 0 1 2 3 4 5 6 7 8 9 389 do 390 o=$(echo $j$i | git hash-object -w --stdin) && 391 echo "100644 $o 0 $j$i" || return 1 392 done 393 done >LIST && 394 rm -f .git/index && 395 git update-index --index-info actual && 404 PACK5=$( git pack-objects test-5 LIST && 437 rm -f .git/index && 438 git update-index --index-info actual && 447 PACK5=$( git pack-objects test-5 commit <<-EOF && 476 tree $(git rev-parse HEAD^{tree}) 477 parent $(git rev-parse HEAD) 478 author A U Thor 479 committer A U Thor 480 481 commit: this is a commit with bad emails 482 483 EOF 484 git hash-object --literally -t commit -w --stdin commit_list && 485 git pack-objects test pack-name 486 ) 487 ' 488 489 test_with_bad_commit () { 490 must_fail_arg="$1" && 491 must_pass_arg="$2" && 492 ( 493 cd strict && 494 test_must_fail git index-pack "$must_fail_arg" "test-$(cat pack-name).pack" && 495 git index-pack "$must_pass_arg" "test-$(cat pack-name).pack" 496 ) 497 } 498 499 test_expect_success 'index-pack with --strict downgrading fsck msgs' ' 500 test_with_bad_commit --strict --strict="missingEmail=ignore" 501 ' 502 503 test_expect_success 'index-pack with --fsck-objects downgrading fsck msgs' ' 504 test_with_bad_commit --fsck-objects --fsck-objects="missingEmail=ignore" 505 ' 506 507 test_expect_success 'cleanup for --strict and --fsck-objects downgrading fsck msgs' ' 508 rm -rf strict 509 ' 510 511 test_expect_success 'honor pack.packSizeLimit' ' 512 git config pack.packSizeLimit 3m && 513 packname_10=$(git pack-objects test-10 works in non-repo' ' 542 nongit git index-pack --object-format=$(test_oid algo) ../foo.pack && 543 test_path_is_file foo.idx 544 ' 545 546 test_expect_success 'index-pack --strict works in non-repo' ' 547 rm -f foo.idx && 548 nongit git index-pack --strict --object-format=$(test_oid algo) ../foo.pack && 549 test_path_is_file foo.idx 550 ' 551 552 test_expect_success DEFAULT_HASH_ALGORITHM 'show-index works OK outside a repository' ' 553 nongit git show-index in && 563 git -C explicit-hash-$hash pack-objects explicit-hash-$hash actual && 566 test_line_count = 1 actual 567 ' 568 done 569 570 test_expect_success !PTHREADS,!FAIL_PREREQS \ 571 'index-pack --threads=N or pack.threads=N warns when no pthreads' ' 572 test_must_fail git index-pack --threads=2 2>err && 573 grep ^warning: err >warnings && 574 test_line_count = 1 warnings && 575 test_grep -F "no threads support, ignoring --threads=2" err && 576 577 test_must_fail git -c pack.threads=2 index-pack 2>err && 578 grep ^warning: err >warnings && 579 test_line_count = 1 warnings && 580 test_grep -F "no threads support, ignoring pack.threads" err && 581 582 test_must_fail git -c pack.threads=2 index-pack --threads=4 2>err && 583 grep ^warning: err >warnings && 584 test_line_count = 2 warnings && 585 test_grep -F "no threads support, ignoring --threads=4" err && 586 test_grep -F "no threads support, ignoring pack.threads" err 587 ' 588 589 test_expect_success !PTHREADS,!FAIL_PREREQS \ 590 'pack-objects --threads=N or pack.threads=N warns when no pthreads' ' 591 git pack-objects --threads=2 --stdout --all /dev/null 2>err && 592 grep ^warning: err >warnings && 593 test_line_count = 1 warnings && 594 test_grep -F "no threads support, ignoring --threads" err && 595 596 git -c pack.threads=2 pack-objects --stdout --all /dev/null 2>err && 597 grep ^warning: err >warnings && 598 test_line_count = 1 warnings && 599 test_grep -F "no threads support, ignoring pack.threads" err && 600 601 git -c pack.threads=2 pack-objects --threads=4 --stdout --all /dev/null 2>err && 602 grep ^warning: err >warnings && 603 test_line_count = 2 warnings && 604 test_grep -F "no threads support, ignoring --threads" err && 605 test_grep -F "no threads support, ignoring pack.threads" err 606 ' 607 608 test_expect_success 'pack-objects in too-many-packs mode' ' 609 GIT_TEST_FULL_IN_PACK_ARRAY=1 git repack -ad && 610 git fsck 611 ' 612 613 test_expect_success 'setup: fake a SHA1 hash collision' ' 614 git init corrupt && 615 ( 616 cd corrupt && 617 long_a=$(git hash-object -w ../a | sed -e "s!^..!&/!") && 618 long_b=$(git hash-object -w ../b | sed -e "s!^..!&/!") && 619 test_path_is_file .git/objects/$long_b && 620 cp -f .git/objects/$long_a \ 621 .git/objects/$long_b 622 ) 623 ' 624 625 test_expect_success 'make sure index-pack detects the SHA1 collision' ' 626 ( 627 cd corrupt && 628 test_must_fail git index-pack -o ../bad.idx ../test-3.pack 2>msg && 629 test_grep "SHA1 COLLISION FOUND" msg 630 ) 631 ' 632 633 test_expect_success 'make sure index-pack detects the SHA1 collision (large blobs)' ' 634 ( 635 cd corrupt && 636 test_must_fail git -c core.bigfilethreshold=1 index-pack -o ../bad.idx ../test-3.pack 2>msg && 637 test_grep "SHA1 COLLISION FOUND" msg 638 ) 639 ' 640 641 test_expect_success 'prefetch objects' ' 642 rm -rf server client && 643 644 git init server && 645 test_config -C server uploadpack.allowanysha1inwant 1 && 646 test_config -C server uploadpack.allowfilter 1 && 647 test_config -C server protocol.version 2 && 648 649 echo one >server/one && 650 git -C server add one && 651 git -C server commit -m one && 652 git -C server branch one_branch && 653 654 echo two_a >server/two_a && 655 echo two_b >server/two_b && 656 git -C server add two_a two_b && 657 git -C server commit -m two && 658 659 echo three >server/three && 660 git -C server add three && 661 git -C server commit -m three && 662 git -C server branch three_branch && 663 664 # Clone, fetch "two" with blobs excluded, and re-push it. This requires 665 # the client to have the blobs of "two" - verify that these are 666 # prefetched in one batch. 667 git clone --filter=blob:none --single-branch -b one_branch \ 668 "file://$(pwd)/server" client && 669 test_config -C client protocol.version 2 && 670 TWO=$(git -C server rev-parse three_branch^) && 671 git -C client fetch --filter=blob:none origin "$TWO" && 672 GIT_TRACE_PACKET=$(pwd)/trace git -C client push origin "$TWO":refs/heads/two_branch && 673 grep "fetch> done" trace >donelines && 674 test_line_count = 1 donelines 675 ' 676 677 for hash in sha1 sha256 678 do 679 test_expect_success "verify-pack with $hash packfile" ' 680 test_when_finished "rm -rf repo" && 681 git init --object-format=$hash repo && 682 test_commit -C repo initial && 683 git -C repo repack -ad && 684 git -C repo verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx && 685 if test $hash = $GIT_TEST_BUILTIN_HASH 686 then 687 nongit git verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx 688 else 689 # We have no way to identify the hash used by packfiles 690 # or indices, so we always fall back to SHA1. 691 nongit test_must_fail git verify-pack "$(pwd)"/repo/.git/objects/pack/*.idx && 692 # But with an explicit object format we should succeed. 693 nongit git verify-pack --object-format=$hash "$(pwd)"/repo/.git/objects/pack/*.idx 694 fi 695 ' 696 697 test_expect_success "index-pack outside of a $hash repository" ' 698 test_when_finished "rm -rf repo" && 699 git init --object-format=$hash repo && 700 test_commit -C repo initial && 701 git -C repo repack -ad && 702 git -C repo index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack && 703 if test $hash = $GIT_TEST_BUILTIN_HASH 704 then 705 nongit git index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack 706 else 707 # We have no way to identify the hash used by packfiles 708 # or indices, so we always fall back to SHA1. 709 nongit test_must_fail git index-pack --verify "$(pwd)"/repo/.git/objects/pack/*.pack 2>err && 710 # But with an explicit object format we should succeed. 711 nongit git index-pack --object-format=$hash --verify "$(pwd)"/repo/.git/objects/pack/*.pack 712 fi 713 ' 714 done 715 716 test_expect_success 'valid and invalid --name-hash-versions' ' 717 sane_unset GIT_TEST_NAME_HASH_VERSION && 718 719 # Valid values are hard to verify other than "do not fail". 720 # Performance tests will be more valuable to validate these versions. 721 # Negative values are converted to version 1. 722 for value in -1 1 2 723 do 724 git pack-objects base --all --name-hash-version=$value || return 1 725 done && 726 727 # Invalid values have clear post-conditions. 728 for value in 0 3 729 do 730 test_must_fail git pack-objects base --all --name-hash-version=$value 2>err && 731 test_grep "invalid --name-hash-version option" err || return 1 732 done 733 ' 734 735 # The following test is not necessarily a permanent choice, but since we do not 736 # have a "name hash version" bit in the .bitmap file format, we cannot write the 737 # hash values into the .bitmap file without risking breakage later. 738 # 739 # TODO: Make these compatible in the future and replace this test with the 740 # expected behavior when both are specified. 741 test_expect_success '--name-hash-version=2 and --write-bitmap-index are incompatible' ' 742 git pack-objects base --all --name-hash-version=2 --write-bitmap-index 2>err && 743 test_grep "currently, --write-bitmap-index requires --name-hash-version=1" err && 744 745 # --stdout option silently removes --write-bitmap-index 746 git pack-objects --stdout --all --name-hash-version=2 --write-bitmap-index >out 2>err && 747 test_grep ! "currently, --write-bitmap-index requires --name-hash-version=1" err 748 ' 749 750 test_expect_success '--path-walk pack everything' ' 751 git -C server rev-parse HEAD >in && 752 GIT_PROGRESS_DELAY=0 git -C server pack-objects \ 753 --stdout --revs --path-walk --progress out.pack 2>err && 754 test_grep "Compressing objects by path" err && 755 git -C server index-pack --stdin in <<-EOF && 760 $(git -C server rev-parse HEAD) 761 ^$(git -C server rev-parse HEAD~2) 762 EOF 763 GIT_PROGRESS_DELAY=0 git -C server pack-objects \ 764 --thin --stdout --revs --path-walk --progress out.pack 2>err && 765 test_grep "Compressing objects by path" err && 766 git -C server index-pack --fix-thin --stdin