]>
Commit | Line | Data |
---|---|---|
c51f5a64 TB |
1 | #!/bin/sh |
2 | ||
3 | test_description='exercise basic multi-pack bitmap functionality' | |
4 | . ./test-lib.sh | |
5 | . "${TEST_DIRECTORY}/lib-bitmap.sh" | |
6 | ||
7 | # We'll be writing our own midx and bitmaps, so avoid getting confused by the | |
8 | # automatic ones. | |
9 | GIT_TEST_MULTI_PACK_INDEX=0 | |
10 | GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0 | |
11 | ||
7f514b7a TB |
12 | # This test exercise multi-pack bitmap functionality where the object order is |
13 | # stored and read from a special chunk within the MIDX, so use the default | |
14 | # behavior here. | |
15 | sane_unset GIT_TEST_MIDX_WRITE_REV | |
16 | sane_unset GIT_TEST_MIDX_READ_RIDX | |
17 | ||
791170fa | 18 | midx_bitmap_core |
c51f5a64 TB |
19 | |
20 | bitmap_reuse_tests() { | |
21 | from=$1 | |
22 | to=$2 | |
23 | ||
24 | test_expect_success "setup pack reuse tests ($from -> $to)" ' | |
25 | rm -fr repo && | |
26 | git init repo && | |
27 | ( | |
28 | cd repo && | |
29 | test_commit_bulk 16 && | |
30 | git tag old-tip && | |
31 | ||
32 | git config core.multiPackIndex true && | |
33 | if test "MIDX" = "$from" | |
34 | then | |
35 | git repack -Ad && | |
36 | git multi-pack-index write --bitmap | |
37 | else | |
38 | git repack -Adb | |
39 | fi | |
40 | ) | |
41 | ' | |
42 | ||
43 | test_expect_success "build bitmap from existing ($from -> $to)" ' | |
44 | ( | |
45 | cd repo && | |
46 | test_commit_bulk --id=further 16 && | |
47 | git tag new-tip && | |
48 | ||
49 | if test "MIDX" = "$to" | |
50 | then | |
51 | git repack -d && | |
52 | git multi-pack-index write --bitmap | |
53 | else | |
54 | git repack -Adb | |
55 | fi | |
56 | ) | |
57 | ' | |
58 | ||
59 | test_expect_success "verify resulting bitmaps ($from -> $to)" ' | |
60 | ( | |
61 | cd repo && | |
62 | git for-each-ref && | |
63 | git rev-list --test-bitmap refs/tags/old-tip && | |
64 | git rev-list --test-bitmap refs/tags/new-tip | |
65 | ) | |
66 | ' | |
67 | } | |
68 | ||
69 | bitmap_reuse_tests 'pack' 'MIDX' | |
70 | bitmap_reuse_tests 'MIDX' 'pack' | |
71 | bitmap_reuse_tests 'MIDX' 'MIDX' | |
72 | ||
73 | test_expect_success 'missing object closure fails gracefully' ' | |
74 | rm -fr repo && | |
75 | git init repo && | |
76 | test_when_finished "rm -fr repo" && | |
77 | ( | |
78 | cd repo && | |
79 | ||
80 | test_commit loose && | |
81 | test_commit packed && | |
82 | ||
83 | # Do not pass "--revs"; we want a pack without the "loose" | |
84 | # commit. | |
85 | git pack-objects $objdir/pack/pack <<-EOF && | |
86 | $(git rev-parse packed) | |
87 | EOF | |
88 | ||
89 | test_must_fail git multi-pack-index write --bitmap 2>err && | |
90 | grep "doesn.t have full closure" err && | |
91 | test_path_is_missing $midx | |
92 | ) | |
93 | ' | |
94 | ||
791170fa | 95 | midx_bitmap_partial_tests |
c51f5a64 TB |
96 | |
97 | test_expect_success 'removing a MIDX clears stale bitmaps' ' | |
98 | rm -fr repo && | |
99 | git init repo && | |
100 | test_when_finished "rm -fr repo" && | |
101 | ( | |
102 | cd repo && | |
103 | test_commit base && | |
104 | git repack && | |
105 | git multi-pack-index write --bitmap && | |
106 | ||
107 | # Write a MIDX and bitmap; remove the MIDX but leave the bitmap. | |
108 | stale_bitmap=$midx-$(midx_checksum $objdir).bitmap && | |
c51f5a64 TB |
109 | rm $midx && |
110 | ||
111 | # Then write a new MIDX. | |
112 | test_commit new && | |
113 | git repack && | |
114 | git multi-pack-index write --bitmap && | |
115 | ||
116 | test_path_is_file $midx && | |
117 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
f0ed59af | 118 | test_path_is_missing $stale_bitmap |
c51f5a64 TB |
119 | ) |
120 | ' | |
121 | ||
122 | test_expect_success 'pack.preferBitmapTips' ' | |
123 | git init repo && | |
124 | test_when_finished "rm -fr repo" && | |
125 | ( | |
126 | cd repo && | |
127 | ||
128 | test_commit_bulk --message="%s" 103 && | |
129 | ||
130 | git log --format="%H" >commits.raw && | |
131 | sort <commits.raw >commits && | |
132 | ||
133 | git log --format="create refs/tags/%s %H" HEAD >refs && | |
134 | git update-ref --stdin <refs && | |
135 | ||
136 | git multi-pack-index write --bitmap && | |
137 | test_path_is_file $midx && | |
138 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
c51f5a64 TB |
139 | |
140 | test-tool bitmap list-commits | sort >bitmaps && | |
141 | comm -13 bitmaps commits >before && | |
142 | test_line_count = 1 before && | |
143 | ||
144 | perl -ne "printf(\"create refs/tags/include/%d \", $.); print" \ | |
145 | <before | git update-ref --stdin && | |
146 | ||
147 | rm -fr $midx-$(midx_checksum $objdir).bitmap && | |
c51f5a64 TB |
148 | rm -fr $midx && |
149 | ||
150 | git -c pack.preferBitmapTips=refs/tags/include \ | |
151 | multi-pack-index write --bitmap && | |
152 | test-tool bitmap list-commits | sort >bitmaps && | |
153 | comm -13 bitmaps commits >after && | |
154 | ||
155 | ! test_cmp before after | |
156 | ) | |
157 | ' | |
158 | ||
08944d1c TB |
159 | test_expect_success 'writing a bitmap with --refs-snapshot' ' |
160 | git init repo && | |
161 | test_when_finished "rm -fr repo" && | |
162 | ( | |
163 | cd repo && | |
164 | ||
165 | test_commit one && | |
166 | test_commit two && | |
167 | ||
168 | git rev-parse one >snapshot && | |
169 | ||
170 | git repack -ad && | |
171 | ||
172 | # First, write a MIDX which see both refs/tags/one and | |
173 | # refs/tags/two (causing both of those commits to receive | |
174 | # bitmaps). | |
175 | git multi-pack-index write --bitmap && | |
176 | ||
177 | test_path_is_file $midx && | |
178 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
179 | ||
180 | test-tool bitmap list-commits | sort >bitmaps && | |
181 | grep "$(git rev-parse one)" bitmaps && | |
182 | grep "$(git rev-parse two)" bitmaps && | |
183 | ||
184 | rm -fr $midx-$(midx_checksum $objdir).bitmap && | |
08944d1c TB |
185 | rm -fr $midx && |
186 | ||
187 | # Then again, but with a refs snapshot which only sees | |
188 | # refs/tags/one. | |
189 | git multi-pack-index write --bitmap --refs-snapshot=snapshot && | |
190 | ||
191 | test_path_is_file $midx && | |
192 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
193 | ||
194 | test-tool bitmap list-commits | sort >bitmaps && | |
195 | grep "$(git rev-parse one)" bitmaps && | |
196 | ! grep "$(git rev-parse two)" bitmaps | |
197 | ) | |
198 | ' | |
199 | ||
200 | test_expect_success 'write a bitmap with --refs-snapshot (preferred tips)' ' | |
201 | git init repo && | |
202 | test_when_finished "rm -fr repo" && | |
203 | ( | |
204 | cd repo && | |
205 | ||
206 | test_commit_bulk --message="%s" 103 && | |
207 | ||
208 | git log --format="%H" >commits.raw && | |
209 | sort <commits.raw >commits && | |
210 | ||
211 | git log --format="create refs/tags/%s %H" HEAD >refs && | |
212 | git update-ref --stdin <refs && | |
213 | ||
214 | git multi-pack-index write --bitmap && | |
215 | test_path_is_file $midx && | |
216 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
217 | ||
218 | test-tool bitmap list-commits | sort >bitmaps && | |
219 | comm -13 bitmaps commits >before && | |
220 | test_line_count = 1 before && | |
221 | ||
222 | ( | |
223 | grep -vf before commits.raw && | |
224 | # mark missing commits as preferred | |
225 | sed "s/^/+/" before | |
226 | ) >snapshot && | |
227 | ||
228 | rm -fr $midx-$(midx_checksum $objdir).bitmap && | |
08944d1c TB |
229 | rm -fr $midx && |
230 | ||
231 | git multi-pack-index write --bitmap --refs-snapshot=snapshot && | |
232 | test-tool bitmap list-commits | sort >bitmaps && | |
233 | comm -13 bitmaps commits >after && | |
234 | ||
235 | ! test_cmp before after | |
236 | ) | |
237 | ' | |
238 | ||
54156af0 TB |
239 | test_expect_success 'hash-cache values are propagated from pack bitmaps' ' |
240 | rm -fr repo && | |
241 | git init repo && | |
242 | test_when_finished "rm -fr repo" && | |
243 | ( | |
244 | cd repo && | |
245 | ||
246 | test_commit base && | |
247 | test_commit base2 && | |
248 | git repack -adb && | |
249 | ||
250 | test-tool bitmap dump-hashes >pack.raw && | |
251 | test_file_not_empty pack.raw && | |
252 | sort pack.raw >pack.hashes && | |
253 | ||
254 | test_commit new && | |
255 | git repack && | |
256 | git multi-pack-index write --bitmap && | |
257 | ||
258 | test-tool bitmap dump-hashes >midx.raw && | |
259 | sort midx.raw >midx.hashes && | |
260 | ||
261 | # ensure that every namehash in the pack bitmap can be found in | |
262 | # the midx bitmap (i.e., that there are no oid-namehash pairs | |
263 | # unique to the pack bitmap). | |
264 | comm -23 pack.hashes midx.hashes >dropped.hashes && | |
265 | test_must_be_empty dropped.hashes | |
266 | ) | |
267 | ' | |
268 | ||
eb57277b TB |
269 | test_expect_success 'no .bitmap is written without any objects' ' |
270 | rm -fr repo && | |
271 | git init repo && | |
272 | test_when_finished "rm -fr repo" && | |
273 | ( | |
274 | cd repo && | |
275 | ||
276 | empty="$(git pack-objects $objdir/pack/pack </dev/null)" && | |
277 | cat >packs <<-EOF && | |
278 | pack-$empty.idx | |
279 | EOF | |
280 | ||
281 | git multi-pack-index write --bitmap --stdin-packs \ | |
282 | <packs 2>err && | |
283 | ||
284 | grep "bitmap without any objects" err && | |
285 | ||
286 | test_path_is_file $midx && | |
287 | test_path_is_missing $midx-$(midx_checksum $objdir).bitmap | |
288 | ) | |
289 | ' | |
290 | ||
f8b60cf9 TB |
291 | test_expect_success 'graceful fallback when missing reverse index' ' |
292 | rm -fr repo && | |
293 | git init repo && | |
294 | test_when_finished "rm -fr repo" && | |
295 | ( | |
296 | cd repo && | |
297 | ||
298 | test_commit base && | |
299 | ||
300 | # write a pack and MIDX bitmap containing base | |
301 | git repack -adb && | |
302 | git multi-pack-index write --bitmap && | |
303 | ||
304 | GIT_TEST_MIDX_READ_RIDX=0 \ | |
305 | git rev-list --use-bitmap-index HEAD 2>err && | |
306 | ! grep "ignoring extra bitmap file" err | |
307 | ) | |
308 | ' | |
309 | ||
65168c42 TB |
310 | test_expect_success 'preferred pack change with existing MIDX bitmap' ' |
311 | git init preferred-pack-with-existing && | |
312 | ( | |
313 | cd preferred-pack-with-existing && | |
314 | ||
315 | test_commit base && | |
316 | test_commit other && | |
317 | ||
318 | git rev-list --objects --no-object-names base >p1.objects && | |
319 | git rev-list --objects --no-object-names other >p2.objects && | |
320 | ||
321 | p1="$(git pack-objects "$objdir/pack/pack" \ | |
322 | --delta-base-offset <p1.objects)" && | |
323 | p2="$(git pack-objects "$objdir/pack/pack" \ | |
324 | --delta-base-offset <p2.objects)" && | |
325 | ||
326 | # Generate a MIDX containing the first two packs, | |
327 | # marking p1 as preferred, and ensure that it can be | |
328 | # successfully cloned. | |
329 | git multi-pack-index write --bitmap \ | |
330 | --preferred-pack="pack-$p1.pack" && | |
331 | test_path_is_file $midx && | |
332 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
333 | git clone --no-local . clone1 && | |
334 | ||
335 | # Then generate a new pack which sorts ahead of any | |
336 | # existing pack (by tweaking the pack prefix). | |
337 | test_commit foo && | |
338 | git pack-objects --all --unpacked $objdir/pack/pack0 && | |
339 | ||
340 | # Generate a new MIDX which changes the preferred pack | |
341 | # to a pack contained in the existing MIDX, such that | |
342 | # not all objects from p2 that appear in the MIDX had | |
343 | # their copy selected from p2. | |
344 | git multi-pack-index write --bitmap \ | |
345 | --preferred-pack="pack-$p2.pack" && | |
346 | test_path_is_file $midx && | |
347 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
348 | ||
349 | # When the above circumstances are met, an existing bug | |
350 | # in the MIDX machinery will cause the reverse index to | |
351 | # be read incorrectly, resulting in failed clones (among | |
352 | # other things). | |
353 | test_must_fail git clone --no-local . clone2 | |
354 | ) | |
355 | ' | |
356 | ||
c51f5a64 | 357 | test_done |