| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='incremental multi-pack-index' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | . "$TEST_DIRECTORY"/lib-midx.sh |
| 7 | |
| 8 | GIT_TEST_MULTI_PACK_INDEX=0 |
| 9 | export GIT_TEST_MULTI_PACK_INDEX |
| 10 | |
| 11 | objdir=.git/objects |
| 12 | packdir=$objdir/pack |
| 13 | midxdir=$packdir/multi-pack-index.d |
| 14 | midx_chain=$midxdir/multi-pack-index-chain |
| 15 | |
| 16 | test_expect_success 'convert non-incremental MIDX to incremental' ' |
| 17 | test_commit base && |
| 18 | git config set maintenance.auto false && |
| 19 | git repack -ad && |
| 20 | git multi-pack-index write && |
| 21 | |
| 22 | test_path_is_file $packdir/multi-pack-index && |
| 23 | old_hash="$(midx_checksum $objdir)" && |
| 24 | |
| 25 | test_commit other && |
| 26 | git repack -d && |
| 27 | git multi-pack-index write --incremental && |
| 28 | |
| 29 | test_path_is_missing $packdir/multi-pack-index && |
| 30 | test_path_is_file $midx_chain && |
| 31 | test_line_count = 2 $midx_chain && |
| 32 | test_grep $old_hash $midx_chain |
| 33 | ' |
| 34 | |
| 35 | compare_results_with_midx 'incremental MIDX' |
| 36 | |
| 37 | test_expect_success 'convert incremental to non-incremental' ' |
| 38 | test_commit squash && |
| 39 | git repack -d && |
| 40 | git multi-pack-index write && |
| 41 | |
| 42 | test_path_is_file $packdir/multi-pack-index && |
| 43 | test_dir_is_empty $midxdir |
| 44 | ' |
| 45 | |
| 46 | compare_results_with_midx 'non-incremental MIDX conversion' |
| 47 | |
| 48 | write_midx_layer () { |
| 49 | n=1 |
| 50 | if test -f $midx_chain |
| 51 | then |
| 52 | n="$(($(wc -l <$midx_chain) + 1))" |
| 53 | fi |
| 54 | |
| 55 | for i in 1 2 |
| 56 | do |
| 57 | test_commit $n.$i && |
| 58 | git repack -d || return 1 |
| 59 | done && |
| 60 | git multi-pack-index write --bitmap --incremental |
| 61 | } |
| 62 | |
| 63 | test_expect_success 'write initial MIDX layer' ' |
| 64 | git repack -ad && |
| 65 | write_midx_layer |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'read bitmap from first MIDX layer' ' |
| 69 | git rev-list --test-bitmap 1.2 |
| 70 | ' |
| 71 | |
| 72 | test_expect_success 'write another MIDX layer' ' |
| 73 | write_midx_layer |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'midx verify with multiple layers' ' |
| 77 | test_path_is_file "$midx_chain" && |
| 78 | test_line_count = 2 "$midx_chain" && |
| 79 | |
| 80 | git multi-pack-index verify |
| 81 | ' |
| 82 | |
| 83 | test_expect_success 'read bitmap from second MIDX layer' ' |
| 84 | git rev-list --test-bitmap 2.2 |
| 85 | ' |
| 86 | |
| 87 | test_expect_success 'read earlier bitmap from second MIDX layer' ' |
| 88 | git rev-list --test-bitmap 1.2 |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'show object from first pack' ' |
| 92 | git cat-file -p 1.1 |
| 93 | ' |
| 94 | |
| 95 | test_expect_success 'show object from second pack' ' |
| 96 | git cat-file -p 2.2 |
| 97 | ' |
| 98 | |
| 99 | test_expect_success 'write MIDX layer with --no-write-chain-file' ' |
| 100 | test_commit no-write-chain-file && |
| 101 | git repack -d && |
| 102 | |
| 103 | cp "$midx_chain" "$midx_chain.bak" && |
| 104 | layer="$(git multi-pack-index write --bitmap --incremental \ |
| 105 | --no-write-chain-file)" && |
| 106 | |
| 107 | test_cmp "$midx_chain.bak" "$midx_chain" && |
| 108 | test_path_is_file "$midxdir/multi-pack-index-$layer.midx" |
| 109 | ' |
| 110 | |
| 111 | test_expect_success 'write non-incremental MIDX layer with --no-write-chain-file' ' |
| 112 | test_must_fail git multi-pack-index write --bitmap --no-write-chain-file 2>err && |
| 113 | test_grep "cannot use --no-write-chain-file without --incremental" err |
| 114 | ' |
| 115 | |
| 116 | test_expect_success 'write MIDX layer with --base without --no-write-chain-file' ' |
| 117 | test_must_fail git multi-pack-index write --bitmap --incremental \ |
| 118 | --base=none 2>err && |
| 119 | test_grep "cannot use --base without --no-write-chain-file" err |
| 120 | ' |
| 121 | |
| 122 | test_expect_success 'write MIDX layer with --base=none and --no-write-chain-file' ' |
| 123 | test_commit base-none && |
| 124 | git repack -d && |
| 125 | |
| 126 | cp "$midx_chain" "$midx_chain.bak" && |
| 127 | layer="$(git multi-pack-index write --bitmap --incremental \ |
| 128 | --no-write-chain-file --base=none)" && |
| 129 | |
| 130 | test_cmp "$midx_chain.bak" "$midx_chain" && |
| 131 | test_path_is_file "$midxdir/multi-pack-index-$layer.midx" && |
| 132 | |
| 133 | echo "$layer" >"$midx_chain" && |
| 134 | test-tool read-midx --show-objects "$objdir" "$layer" >midx.objects && |
| 135 | test_grep "^$(git rev-parse 2.2) " midx.objects && |
| 136 | cp "$midx_chain.bak" "$midx_chain" |
| 137 | ' |
| 138 | |
| 139 | test_expect_success 'write MIDX layer with --base=<hash> and --no-write-chain-file' ' |
| 140 | test_commit base-hash && |
| 141 | git repack -d && |
| 142 | |
| 143 | cp "$midx_chain" "$midx_chain.bak" && |
| 144 | base="$(nth_line 1 "$midx_chain")" && |
| 145 | layer="$(git multi-pack-index write --bitmap --incremental \ |
| 146 | --no-write-chain-file --base="$base")" && |
| 147 | |
| 148 | test_cmp "$midx_chain.bak" "$midx_chain" && |
| 149 | test_path_is_file "$midxdir/multi-pack-index-$layer.midx" && |
| 150 | |
| 151 | { |
| 152 | echo "$base" && |
| 153 | echo "$layer" |
| 154 | } >"$midx_chain" && |
| 155 | test-tool read-midx --show-objects "$objdir" "$layer" >midx.objects && |
| 156 | test_grep "^$(git rev-parse 2.2) " midx.objects && |
| 157 | cp "$midx_chain.bak" "$midx_chain" |
| 158 | ' |
| 159 | |
| 160 | for reuse in false single multi |
| 161 | do |
| 162 | test_expect_success "full clone (pack.allowPackReuse=$reuse)" ' |
| 163 | rm -fr clone.git && |
| 164 | |
| 165 | git config pack.allowPackReuse $reuse && |
| 166 | git clone --no-local --bare . clone.git |
| 167 | ' |
| 168 | done |
| 169 | |
| 170 | test_expect_success 'relink existing MIDX layer' ' |
| 171 | rm -fr "$midxdir" && |
| 172 | |
| 173 | GIT_TEST_MIDX_WRITE_REV=1 git multi-pack-index write --bitmap && |
| 174 | |
| 175 | midx_hash="$(test-tool read-midx --checksum $objdir)" && |
| 176 | |
| 177 | test_path_is_file "$packdir/multi-pack-index" && |
| 178 | test_path_is_file "$packdir/multi-pack-index-$midx_hash.bitmap" && |
| 179 | test_path_is_file "$packdir/multi-pack-index-$midx_hash.rev" && |
| 180 | |
| 181 | test_commit another && |
| 182 | git repack -d && |
| 183 | git multi-pack-index write --bitmap --incremental && |
| 184 | |
| 185 | test_path_is_missing "$packdir/multi-pack-index" && |
| 186 | test_path_is_missing "$packdir/multi-pack-index-$midx_hash.bitmap" && |
| 187 | test_path_is_missing "$packdir/multi-pack-index-$midx_hash.rev" && |
| 188 | |
| 189 | test_path_is_file "$midxdir/multi-pack-index-$midx_hash.midx" && |
| 190 | test_path_is_file "$midxdir/multi-pack-index-$midx_hash.bitmap" && |
| 191 | test_path_is_file "$midxdir/multi-pack-index-$midx_hash.rev" && |
| 192 | test_line_count = 2 "$midx_chain" |
| 193 | |
| 194 | ' |
| 195 | |
| 196 | test_expect_success 'non-incremental write with existing incremental chain' ' |
| 197 | git init non-incremental-write-with-existing && |
| 198 | test_when_finished "rm -fr non-incremental-write-with-existing" && |
| 199 | |
| 200 | ( |
| 201 | cd non-incremental-write-with-existing && |
| 202 | |
| 203 | git config set maintenance.auto false && |
| 204 | |
| 205 | write_midx_layer && |
| 206 | write_midx_layer && |
| 207 | |
| 208 | git multi-pack-index write |
| 209 | ) |
| 210 | ' |
| 211 | |
| 212 | test_done |