| 1 | #!/bin/sh |
| 2 | test_description='test git fast-import unpack limit' |
| 3 | |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | test_expect_success 'create loose objects on import' ' |
| 7 | test_tick && |
| 8 | cat >input <<-INPUT_END && |
| 9 | commit refs/heads/main |
| 10 | committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE |
| 11 | data <<COMMIT |
| 12 | initial |
| 13 | COMMIT |
| 14 | |
| 15 | done |
| 16 | INPUT_END |
| 17 | |
| 18 | git -c fastimport.unpackLimit=2 fast-import --done <input && |
| 19 | git fsck --no-progress && |
| 20 | test $(find .git/objects/?? -type f | wc -l) -eq 2 && |
| 21 | test $(find .git/objects/pack -type f | wc -l) -eq 0 |
| 22 | ' |
| 23 | |
| 24 | test_expect_success 'bigger packs are preserved' ' |
| 25 | test_tick && |
| 26 | cat >input <<-INPUT_END && |
| 27 | commit refs/heads/main |
| 28 | committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE |
| 29 | data <<COMMIT |
| 30 | incremental should create a pack |
| 31 | COMMIT |
| 32 | from refs/heads/main^0 |
| 33 | |
| 34 | commit refs/heads/branch |
| 35 | committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE |
| 36 | data <<COMMIT |
| 37 | branch |
| 38 | COMMIT |
| 39 | |
| 40 | done |
| 41 | INPUT_END |
| 42 | |
| 43 | git -c fastimport.unpackLimit=2 fast-import --done <input && |
| 44 | git fsck --no-progress && |
| 45 | test $(find .git/objects/?? -type f | wc -l) -eq 2 && |
| 46 | test $(find .git/objects/pack -type f | wc -l) -eq 2 |
| 47 | ' |
| 48 | |
| 49 | test_expect_success 'lookups after checkpoint works' ' |
| 50 | hello_id=$(echo hello | git hash-object --stdin -t blob) && |
| 51 | id="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" && |
| 52 | before=$(git rev-parse refs/heads/main^0) && |
| 53 | ( |
| 54 | cat <<-INPUT_END && |
| 55 | blob |
| 56 | mark :1 |
| 57 | data 6 |
| 58 | hello |
| 59 | |
| 60 | commit refs/heads/main |
| 61 | mark :2 |
| 62 | committer $id |
| 63 | data <<COMMIT |
| 64 | checkpoint after this |
| 65 | COMMIT |
| 66 | from refs/heads/main^0 |
| 67 | M 100644 :1 hello |
| 68 | |
| 69 | # pre-checkpoint |
| 70 | cat-blob :1 |
| 71 | cat-blob $hello_id |
| 72 | checkpoint |
| 73 | # post-checkpoint |
| 74 | cat-blob :1 |
| 75 | cat-blob $hello_id |
| 76 | INPUT_END |
| 77 | |
| 78 | n=0 && |
| 79 | from=$before && |
| 80 | while test x"$from" = x"$before" |
| 81 | do |
| 82 | if test $n -gt 30 |
| 83 | then |
| 84 | echo >&2 "checkpoint did not update branch" && |
| 85 | exit 1 |
| 86 | else |
| 87 | n=$(($n + 1)) |
| 88 | fi && |
| 89 | sleep 1 && |
| 90 | from=$(git rev-parse refs/heads/main^0) |
| 91 | done && |
| 92 | cat <<-INPUT_END && |
| 93 | commit refs/heads/main |
| 94 | committer $id |
| 95 | data <<COMMIT |
| 96 | make sure from "unpacked sha1 reference" works, too |
| 97 | COMMIT |
| 98 | from $from |
| 99 | INPUT_END |
| 100 | echo done |
| 101 | ) | git -c fastimport.unpackLimit=100 fast-import --done && |
| 102 | test $(find .git/objects/?? -type f | wc -l) -eq 6 && |
| 103 | test $(find .git/objects/pack -type f | wc -l) -eq 2 |
| 104 | ' |
| 105 | |
| 106 | test_done |