]>
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 | ||
12 | objdir=.git/objects | |
13 | midx=$objdir/pack/multi-pack-index | |
14 | ||
15 | # midx_pack_source <obj> | |
16 | midx_pack_source () { | |
17 | test-tool read-midx --show-objects .git/objects | grep "^$1 " | cut -f2 | |
18 | } | |
19 | ||
f0ed59af TB |
20 | test_rev_exists () { |
21 | commit="$1" | |
22 | ||
23 | test_expect_success 'reverse index exists' ' | |
24 | GIT_TRACE2_EVENT=$(pwd)/event.trace \ | |
25 | git rev-list --test-bitmap "$commit" && | |
26 | ||
27 | test_path_is_file $midx-$(midx_checksum $objdir).rev && | |
28 | grep "\"category\":\"load_midx_revindex\",\"key\":\"source\",\"value\":\"rev\"" event.trace | |
29 | ' | |
30 | } | |
31 | ||
c51f5a64 TB |
32 | setup_bitmap_history |
33 | ||
c51f5a64 TB |
34 | test_expect_success 'create single-pack midx with bitmaps' ' |
35 | git repack -ad && | |
36 | git multi-pack-index write --bitmap && | |
37 | test_path_is_file $midx && | |
f0ed59af | 38 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap |
c51f5a64 TB |
39 | ' |
40 | ||
f0ed59af TB |
41 | test_rev_exists HEAD |
42 | ||
c51f5a64 TB |
43 | basic_bitmap_tests |
44 | ||
45 | test_expect_success 'create new additional packs' ' | |
46 | for i in $(test_seq 1 16) | |
47 | do | |
48 | test_commit "$i" && | |
49 | git repack -d || return 1 | |
50 | done && | |
51 | ||
52 | git checkout -b other2 HEAD~8 && | |
53 | for i in $(test_seq 1 8) | |
54 | do | |
55 | test_commit "side-$i" && | |
56 | git repack -d || return 1 | |
57 | done && | |
58 | git checkout second | |
59 | ' | |
60 | ||
61 | test_expect_success 'create multi-pack midx with bitmaps' ' | |
62 | git multi-pack-index write --bitmap && | |
63 | ||
64 | ls $objdir/pack/pack-*.pack >packs && | |
65 | test_line_count = 25 packs && | |
66 | ||
67 | test_path_is_file $midx && | |
f0ed59af | 68 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap |
c51f5a64 TB |
69 | ' |
70 | ||
f0ed59af TB |
71 | test_rev_exists HEAD |
72 | ||
c51f5a64 TB |
73 | basic_bitmap_tests |
74 | ||
75 | test_expect_success '--no-bitmap is respected when bitmaps exist' ' | |
76 | git multi-pack-index write --bitmap && | |
77 | ||
78 | test_commit respect--no-bitmap && | |
79 | git repack -d && | |
80 | ||
81 | test_path_is_file $midx && | |
82 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
c51f5a64 TB |
83 | |
84 | git multi-pack-index write --no-bitmap && | |
85 | ||
86 | test_path_is_file $midx && | |
87 | test_path_is_missing $midx-$(midx_checksum $objdir).bitmap && | |
88 | test_path_is_missing $midx-$(midx_checksum $objdir).rev | |
89 | ' | |
90 | ||
91 | test_expect_success 'setup midx with base from later pack' ' | |
92 | # Write a and b so that "a" is a delta on top of base "b", since Git | |
93 | # prefers to delete contents out of a base rather than add to a shorter | |
94 | # object. | |
95 | test_seq 1 128 >a && | |
96 | test_seq 1 130 >b && | |
97 | ||
98 | git add a b && | |
99 | git commit -m "initial commit" && | |
100 | ||
101 | a=$(git rev-parse HEAD:a) && | |
102 | b=$(git rev-parse HEAD:b) && | |
103 | ||
104 | # In the first pack, "a" is stored as a delta to "b". | |
105 | p1=$(git pack-objects .git/objects/pack/pack <<-EOF | |
106 | $a | |
107 | $b | |
108 | EOF | |
109 | ) && | |
110 | ||
111 | # In the second pack, "a" is missing, and "b" is not a delta nor base to | |
112 | # any other object. | |
113 | p2=$(git pack-objects .git/objects/pack/pack <<-EOF | |
114 | $b | |
115 | $(git rev-parse HEAD) | |
116 | $(git rev-parse HEAD^{tree}) | |
117 | EOF | |
118 | ) && | |
119 | ||
120 | git prune-packed && | |
121 | # Use the second pack as the preferred source, so that "b" occurs | |
122 | # earlier in the MIDX object order, rendering "a" unusable for pack | |
123 | # reuse. | |
124 | git multi-pack-index write --bitmap --preferred-pack=pack-$p2.idx && | |
125 | ||
126 | have_delta $a $b && | |
127 | test $(midx_pack_source $a) != $(midx_pack_source $b) | |
128 | ' | |
129 | ||
130 | rev_list_tests 'full bitmap with backwards delta' | |
131 | ||
132 | test_expect_success 'clone with bitmaps enabled' ' | |
133 | git clone --no-local --bare . clone-reverse-delta.git && | |
134 | test_when_finished "rm -fr clone-reverse-delta.git" && | |
135 | ||
136 | git rev-parse HEAD >expect && | |
137 | git --git-dir=clone-reverse-delta.git rev-parse HEAD >actual && | |
138 | test_cmp expect actual | |
139 | ' | |
140 | ||
141 | bitmap_reuse_tests() { | |
142 | from=$1 | |
143 | to=$2 | |
144 | ||
145 | test_expect_success "setup pack reuse tests ($from -> $to)" ' | |
146 | rm -fr repo && | |
147 | git init repo && | |
148 | ( | |
149 | cd repo && | |
150 | test_commit_bulk 16 && | |
151 | git tag old-tip && | |
152 | ||
153 | git config core.multiPackIndex true && | |
154 | if test "MIDX" = "$from" | |
155 | then | |
156 | git repack -Ad && | |
157 | git multi-pack-index write --bitmap | |
158 | else | |
159 | git repack -Adb | |
160 | fi | |
161 | ) | |
162 | ' | |
163 | ||
164 | test_expect_success "build bitmap from existing ($from -> $to)" ' | |
165 | ( | |
166 | cd repo && | |
167 | test_commit_bulk --id=further 16 && | |
168 | git tag new-tip && | |
169 | ||
170 | if test "MIDX" = "$to" | |
171 | then | |
172 | git repack -d && | |
173 | git multi-pack-index write --bitmap | |
174 | else | |
175 | git repack -Adb | |
176 | fi | |
177 | ) | |
178 | ' | |
179 | ||
180 | test_expect_success "verify resulting bitmaps ($from -> $to)" ' | |
181 | ( | |
182 | cd repo && | |
183 | git for-each-ref && | |
184 | git rev-list --test-bitmap refs/tags/old-tip && | |
185 | git rev-list --test-bitmap refs/tags/new-tip | |
186 | ) | |
187 | ' | |
188 | } | |
189 | ||
190 | bitmap_reuse_tests 'pack' 'MIDX' | |
191 | bitmap_reuse_tests 'MIDX' 'pack' | |
192 | bitmap_reuse_tests 'MIDX' 'MIDX' | |
193 | ||
194 | test_expect_success 'missing object closure fails gracefully' ' | |
195 | rm -fr repo && | |
196 | git init repo && | |
197 | test_when_finished "rm -fr repo" && | |
198 | ( | |
199 | cd repo && | |
200 | ||
201 | test_commit loose && | |
202 | test_commit packed && | |
203 | ||
204 | # Do not pass "--revs"; we want a pack without the "loose" | |
205 | # commit. | |
206 | git pack-objects $objdir/pack/pack <<-EOF && | |
207 | $(git rev-parse packed) | |
208 | EOF | |
209 | ||
210 | test_must_fail git multi-pack-index write --bitmap 2>err && | |
211 | grep "doesn.t have full closure" err && | |
212 | test_path_is_missing $midx | |
213 | ) | |
214 | ' | |
215 | ||
216 | test_expect_success 'setup partial bitmaps' ' | |
217 | test_commit packed && | |
218 | git repack && | |
219 | test_commit loose && | |
220 | git multi-pack-index write --bitmap 2>err && | |
221 | test_path_is_file $midx && | |
f0ed59af | 222 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap |
c51f5a64 TB |
223 | ' |
224 | ||
f0ed59af TB |
225 | test_rev_exists HEAD~ |
226 | ||
c51f5a64 TB |
227 | basic_bitmap_tests HEAD~ |
228 | ||
229 | test_expect_success 'removing a MIDX clears stale bitmaps' ' | |
230 | rm -fr repo && | |
231 | git init repo && | |
232 | test_when_finished "rm -fr repo" && | |
233 | ( | |
234 | cd repo && | |
235 | test_commit base && | |
236 | git repack && | |
237 | git multi-pack-index write --bitmap && | |
238 | ||
239 | # Write a MIDX and bitmap; remove the MIDX but leave the bitmap. | |
240 | stale_bitmap=$midx-$(midx_checksum $objdir).bitmap && | |
c51f5a64 TB |
241 | rm $midx && |
242 | ||
243 | # Then write a new MIDX. | |
244 | test_commit new && | |
245 | git repack && | |
246 | git multi-pack-index write --bitmap && | |
247 | ||
248 | test_path_is_file $midx && | |
249 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
f0ed59af | 250 | test_path_is_missing $stale_bitmap |
c51f5a64 TB |
251 | ) |
252 | ' | |
253 | ||
254 | test_expect_success 'pack.preferBitmapTips' ' | |
255 | git init repo && | |
256 | test_when_finished "rm -fr repo" && | |
257 | ( | |
258 | cd repo && | |
259 | ||
260 | test_commit_bulk --message="%s" 103 && | |
261 | ||
262 | git log --format="%H" >commits.raw && | |
263 | sort <commits.raw >commits && | |
264 | ||
265 | git log --format="create refs/tags/%s %H" HEAD >refs && | |
266 | git update-ref --stdin <refs && | |
267 | ||
268 | git multi-pack-index write --bitmap && | |
269 | test_path_is_file $midx && | |
270 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
c51f5a64 TB |
271 | |
272 | test-tool bitmap list-commits | sort >bitmaps && | |
273 | comm -13 bitmaps commits >before && | |
274 | test_line_count = 1 before && | |
275 | ||
276 | perl -ne "printf(\"create refs/tags/include/%d \", $.); print" \ | |
277 | <before | git update-ref --stdin && | |
278 | ||
279 | rm -fr $midx-$(midx_checksum $objdir).bitmap && | |
c51f5a64 TB |
280 | rm -fr $midx && |
281 | ||
282 | git -c pack.preferBitmapTips=refs/tags/include \ | |
283 | multi-pack-index write --bitmap && | |
284 | test-tool bitmap list-commits | sort >bitmaps && | |
285 | comm -13 bitmaps commits >after && | |
286 | ||
287 | ! test_cmp before after | |
288 | ) | |
289 | ' | |
290 | ||
08944d1c TB |
291 | test_expect_success 'writing a bitmap with --refs-snapshot' ' |
292 | git init repo && | |
293 | test_when_finished "rm -fr repo" && | |
294 | ( | |
295 | cd repo && | |
296 | ||
297 | test_commit one && | |
298 | test_commit two && | |
299 | ||
300 | git rev-parse one >snapshot && | |
301 | ||
302 | git repack -ad && | |
303 | ||
304 | # First, write a MIDX which see both refs/tags/one and | |
305 | # refs/tags/two (causing both of those commits to receive | |
306 | # bitmaps). | |
307 | git multi-pack-index write --bitmap && | |
308 | ||
309 | test_path_is_file $midx && | |
310 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
311 | ||
312 | test-tool bitmap list-commits | sort >bitmaps && | |
313 | grep "$(git rev-parse one)" bitmaps && | |
314 | grep "$(git rev-parse two)" bitmaps && | |
315 | ||
316 | rm -fr $midx-$(midx_checksum $objdir).bitmap && | |
08944d1c TB |
317 | rm -fr $midx && |
318 | ||
319 | # Then again, but with a refs snapshot which only sees | |
320 | # refs/tags/one. | |
321 | git multi-pack-index write --bitmap --refs-snapshot=snapshot && | |
322 | ||
323 | test_path_is_file $midx && | |
324 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
325 | ||
326 | test-tool bitmap list-commits | sort >bitmaps && | |
327 | grep "$(git rev-parse one)" bitmaps && | |
328 | ! grep "$(git rev-parse two)" bitmaps | |
329 | ) | |
330 | ' | |
331 | ||
332 | test_expect_success 'write a bitmap with --refs-snapshot (preferred tips)' ' | |
333 | git init repo && | |
334 | test_when_finished "rm -fr repo" && | |
335 | ( | |
336 | cd repo && | |
337 | ||
338 | test_commit_bulk --message="%s" 103 && | |
339 | ||
340 | git log --format="%H" >commits.raw && | |
341 | sort <commits.raw >commits && | |
342 | ||
343 | git log --format="create refs/tags/%s %H" HEAD >refs && | |
344 | git update-ref --stdin <refs && | |
345 | ||
346 | git multi-pack-index write --bitmap && | |
347 | test_path_is_file $midx && | |
348 | test_path_is_file $midx-$(midx_checksum $objdir).bitmap && | |
349 | ||
350 | test-tool bitmap list-commits | sort >bitmaps && | |
351 | comm -13 bitmaps commits >before && | |
352 | test_line_count = 1 before && | |
353 | ||
354 | ( | |
355 | grep -vf before commits.raw && | |
356 | # mark missing commits as preferred | |
357 | sed "s/^/+/" before | |
358 | ) >snapshot && | |
359 | ||
360 | rm -fr $midx-$(midx_checksum $objdir).bitmap && | |
08944d1c TB |
361 | rm -fr $midx && |
362 | ||
363 | git multi-pack-index write --bitmap --refs-snapshot=snapshot && | |
364 | test-tool bitmap list-commits | sort >bitmaps && | |
365 | comm -13 bitmaps commits >after && | |
366 | ||
367 | ! test_cmp before after | |
368 | ) | |
369 | ' | |
370 | ||
54156af0 TB |
371 | test_expect_success 'hash-cache values are propagated from pack bitmaps' ' |
372 | rm -fr repo && | |
373 | git init repo && | |
374 | test_when_finished "rm -fr repo" && | |
375 | ( | |
376 | cd repo && | |
377 | ||
378 | test_commit base && | |
379 | test_commit base2 && | |
380 | git repack -adb && | |
381 | ||
382 | test-tool bitmap dump-hashes >pack.raw && | |
383 | test_file_not_empty pack.raw && | |
384 | sort pack.raw >pack.hashes && | |
385 | ||
386 | test_commit new && | |
387 | git repack && | |
388 | git multi-pack-index write --bitmap && | |
389 | ||
390 | test-tool bitmap dump-hashes >midx.raw && | |
391 | sort midx.raw >midx.hashes && | |
392 | ||
393 | # ensure that every namehash in the pack bitmap can be found in | |
394 | # the midx bitmap (i.e., that there are no oid-namehash pairs | |
395 | # unique to the pack bitmap). | |
396 | comm -23 pack.hashes midx.hashes >dropped.hashes && | |
397 | test_must_be_empty dropped.hashes | |
398 | ) | |
399 | ' | |
400 | ||
95e8383b | 401 | test_expect_success 'changing the preferred pack does not corrupt bitmaps' ' |
61fd31a1 TB |
402 | rm -fr repo && |
403 | git init repo && | |
404 | test_when_finished "rm -fr repo" && | |
405 | ( | |
406 | cd repo && | |
407 | ||
408 | test_commit A && | |
409 | test_commit B && | |
410 | ||
411 | git rev-list --objects --no-object-names HEAD^ >A.objects && | |
412 | git rev-list --objects --no-object-names HEAD^.. >B.objects && | |
413 | ||
414 | A=$(git pack-objects $objdir/pack/pack <A.objects) && | |
415 | B=$(git pack-objects $objdir/pack/pack <B.objects) && | |
416 | ||
417 | cat >indexes <<-EOF && | |
418 | pack-$A.idx | |
419 | pack-$B.idx | |
420 | EOF | |
421 | ||
422 | git multi-pack-index write --bitmap --stdin-packs \ | |
423 | --preferred-pack=pack-$A.pack <indexes && | |
424 | git rev-list --test-bitmap A && | |
425 | ||
426 | git multi-pack-index write --bitmap --stdin-packs \ | |
427 | --preferred-pack=pack-$B.pack <indexes && | |
428 | git rev-list --test-bitmap A | |
429 | ) | |
430 | ' | |
431 | ||
c51f5a64 | 432 | test_done |