]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | test_description='exercise basic bitmap functionality' | |
4 | . ./test-lib.sh | |
5 | ||
6 | objpath () { | |
7 | echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')" | |
8 | } | |
9 | ||
10 | # show objects present in pack ($1 should be associated *.idx) | |
11 | list_packed_objects () { | |
12 | git show-index <"$1" >object-list && | |
13 | cut -d' ' -f2 object-list | |
14 | } | |
15 | ||
16 | # has_any pattern-file content-file | |
17 | # tests whether content-file has any entry from pattern-file with entries being | |
18 | # whole lines. | |
19 | has_any () { | |
20 | grep -Ff "$1" "$2" | |
21 | } | |
22 | ||
23 | test_expect_success 'setup repo with moderate-sized history' ' | |
24 | test_commit_bulk --id=file 100 && | |
25 | git checkout -b other HEAD~5 && | |
26 | test_commit_bulk --id=side 10 && | |
27 | git checkout master && | |
28 | bitmaptip=$(git rev-parse master) && | |
29 | blob=$(echo tagged-blob | git hash-object -w --stdin) && | |
30 | git tag tagged-blob $blob && | |
31 | git config repack.writebitmaps true | |
32 | ' | |
33 | ||
34 | test_expect_success 'full repack creates bitmaps' ' | |
35 | git repack -ad && | |
36 | ls .git/objects/pack/ | grep bitmap >output && | |
37 | test_line_count = 1 output | |
38 | ' | |
39 | ||
40 | test_expect_success 'rev-list --test-bitmap verifies bitmaps' ' | |
41 | git rev-list --test-bitmap HEAD | |
42 | ' | |
43 | ||
44 | rev_list_tests() { | |
45 | state=$1 | |
46 | ||
47 | test_expect_success "counting commits via bitmap ($state)" ' | |
48 | git rev-list --count HEAD >expect && | |
49 | git rev-list --use-bitmap-index --count HEAD >actual && | |
50 | test_cmp expect actual | |
51 | ' | |
52 | ||
53 | test_expect_success "counting partial commits via bitmap ($state)" ' | |
54 | git rev-list --count HEAD~5..HEAD >expect && | |
55 | git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual && | |
56 | test_cmp expect actual | |
57 | ' | |
58 | ||
59 | test_expect_success "counting commits with limit ($state)" ' | |
60 | git rev-list --count -n 1 HEAD >expect && | |
61 | git rev-list --use-bitmap-index --count -n 1 HEAD >actual && | |
62 | test_cmp expect actual | |
63 | ' | |
64 | ||
65 | test_expect_success "counting non-linear history ($state)" ' | |
66 | git rev-list --count other...master >expect && | |
67 | git rev-list --use-bitmap-index --count other...master >actual && | |
68 | test_cmp expect actual | |
69 | ' | |
70 | ||
71 | test_expect_success "counting commits with limiting ($state)" ' | |
72 | git rev-list --count HEAD -- 1.t >expect && | |
73 | git rev-list --use-bitmap-index --count HEAD -- 1.t >actual && | |
74 | test_cmp expect actual | |
75 | ' | |
76 | ||
77 | test_expect_success "counting objects via bitmap ($state)" ' | |
78 | git rev-list --count --objects HEAD >expect && | |
79 | git rev-list --use-bitmap-index --count --objects HEAD >actual && | |
80 | test_cmp expect actual | |
81 | ' | |
82 | ||
83 | test_expect_success "enumerate commits ($state)" ' | |
84 | git rev-list --use-bitmap-index HEAD >actual && | |
85 | git rev-list HEAD >expect && | |
86 | test_bitmap_traversal --no-confirm-bitmaps expect actual | |
87 | ' | |
88 | ||
89 | test_expect_success "enumerate --objects ($state)" ' | |
90 | git rev-list --objects --use-bitmap-index HEAD >actual && | |
91 | git rev-list --objects HEAD >expect && | |
92 | test_bitmap_traversal expect actual | |
93 | ' | |
94 | ||
95 | test_expect_success "bitmap --objects handles non-commit objects ($state)" ' | |
96 | git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual && | |
97 | grep $blob actual | |
98 | ' | |
99 | } | |
100 | ||
101 | rev_list_tests 'full bitmap' | |
102 | ||
103 | test_expect_success 'clone from bitmapped repository' ' | |
104 | git clone --no-local --bare . clone.git && | |
105 | git rev-parse HEAD >expect && | |
106 | git --git-dir=clone.git rev-parse HEAD >actual && | |
107 | test_cmp expect actual | |
108 | ' | |
109 | ||
110 | test_expect_success 'partial clone from bitmapped repository' ' | |
111 | test_config uploadpack.allowfilter true && | |
112 | git clone --no-local --bare --filter=blob:none . partial-clone.git && | |
113 | ( | |
114 | cd partial-clone.git && | |
115 | pack=$(echo objects/pack/*.pack) && | |
116 | git verify-pack -v "$pack" >have && | |
117 | awk "/blob/ { print \$1 }" <have >blobs && | |
118 | # we expect this single blob because of the direct ref | |
119 | git rev-parse refs/tags/tagged-blob >expect && | |
120 | test_cmp expect blobs | |
121 | ) | |
122 | ' | |
123 | ||
124 | test_expect_success 'setup further non-bitmapped commits' ' | |
125 | test_commit_bulk --id=further 10 | |
126 | ' | |
127 | ||
128 | rev_list_tests 'partial bitmap' | |
129 | ||
130 | test_expect_success 'fetch (partial bitmap)' ' | |
131 | git --git-dir=clone.git fetch origin master:master && | |
132 | git rev-parse HEAD >expect && | |
133 | git --git-dir=clone.git rev-parse HEAD >actual && | |
134 | test_cmp expect actual | |
135 | ' | |
136 | ||
137 | test_expect_success 'incremental repack fails when bitmaps are requested' ' | |
138 | test_commit more-1 && | |
139 | test_must_fail git repack -d 2>err && | |
140 | test_i18ngrep "Incremental repacks are incompatible with bitmap" err | |
141 | ' | |
142 | ||
143 | test_expect_success 'incremental repack can disable bitmaps' ' | |
144 | test_commit more-2 && | |
145 | git repack -d --no-write-bitmap-index | |
146 | ' | |
147 | ||
148 | test_expect_success 'pack-objects respects --local (non-local loose)' ' | |
149 | git init --bare alt.git && | |
150 | echo $(pwd)/alt.git/objects >.git/objects/info/alternates && | |
151 | echo content1 >file1 && | |
152 | # non-local loose object which is not present in bitmapped pack | |
153 | altblob=$(GIT_DIR=alt.git git hash-object -w file1) && | |
154 | # non-local loose object which is also present in bitmapped pack | |
155 | git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin && | |
156 | git add file1 && | |
157 | test_tick && | |
158 | git commit -m commit_file1 && | |
159 | echo HEAD | git pack-objects --local --stdout --revs >1.pack && | |
160 | git index-pack 1.pack && | |
161 | list_packed_objects 1.idx >1.objects && | |
162 | printf "%s\n" "$altblob" "$blob" >nonlocal-loose && | |
163 | ! has_any nonlocal-loose 1.objects | |
164 | ' | |
165 | ||
166 | test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' ' | |
167 | echo content2 >file2 && | |
168 | blob2=$(git hash-object -w file2) && | |
169 | git add file2 && | |
170 | test_tick && | |
171 | git commit -m commit_file2 && | |
172 | printf "%s\n" "$blob2" "$bitmaptip" >keepobjects && | |
173 | pack2=$(git pack-objects pack2 <keepobjects) && | |
174 | mv pack2-$pack2.* .git/objects/pack/ && | |
175 | >.git/objects/pack/pack2-$pack2.keep && | |
176 | rm $(objpath $blob2) && | |
177 | echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack && | |
178 | git index-pack 2a.pack && | |
179 | list_packed_objects 2a.idx >2a.objects && | |
180 | ! has_any keepobjects 2a.objects | |
181 | ' | |
182 | ||
183 | test_expect_success 'pack-objects respects --local (non-local pack)' ' | |
184 | mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ && | |
185 | echo HEAD | git pack-objects --local --stdout --revs >2b.pack && | |
186 | git index-pack 2b.pack && | |
187 | list_packed_objects 2b.idx >2b.objects && | |
188 | ! has_any keepobjects 2b.objects | |
189 | ' | |
190 | ||
191 | test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' ' | |
192 | ls .git/objects/pack/ | grep bitmap >output && | |
193 | test_line_count = 1 output && | |
194 | packbitmap=$(basename $(cat output) .bitmap) && | |
195 | list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects && | |
196 | test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" && | |
197 | >.git/objects/pack/$packbitmap.keep && | |
198 | echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack && | |
199 | git index-pack 3a.pack && | |
200 | list_packed_objects 3a.idx >3a.objects && | |
201 | ! has_any packbitmap.objects 3a.objects | |
202 | ' | |
203 | ||
204 | test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' ' | |
205 | mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ && | |
206 | rm -f .git/objects/pack/multi-pack-index && | |
207 | test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" && | |
208 | echo HEAD | git pack-objects --local --stdout --revs >3b.pack && | |
209 | git index-pack 3b.pack && | |
210 | list_packed_objects 3b.idx >3b.objects && | |
211 | ! has_any packbitmap.objects 3b.objects | |
212 | ' | |
213 | ||
214 | test_expect_success 'pack-objects to file can use bitmap' ' | |
215 | # make sure we still have 1 bitmap index from previous tests | |
216 | ls .git/objects/pack/ | grep bitmap >output && | |
217 | test_line_count = 1 output && | |
218 | # verify equivalent packs are generated with/without using bitmap index | |
219 | packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) && | |
220 | packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) && | |
221 | list_packed_objects packa-$packasha1.idx >packa.objects && | |
222 | list_packed_objects packb-$packbsha1.idx >packb.objects && | |
223 | test_cmp packa.objects packb.objects | |
224 | ' | |
225 | ||
226 | test_expect_success 'full repack, reusing previous bitmaps' ' | |
227 | git repack -ad && | |
228 | ls .git/objects/pack/ | grep bitmap >output && | |
229 | test_line_count = 1 output | |
230 | ' | |
231 | ||
232 | test_expect_success 'fetch (full bitmap)' ' | |
233 | git --git-dir=clone.git fetch origin master:master && | |
234 | git rev-parse HEAD >expect && | |
235 | git --git-dir=clone.git rev-parse HEAD >actual && | |
236 | test_cmp expect actual | |
237 | ' | |
238 | ||
239 | test_expect_success 'create objects for missing-HAVE tests' ' | |
240 | blob=$(echo "missing have" | git hash-object -w --stdin) && | |
241 | tree=$(printf "100644 blob $blob\tfile\n" | git mktree) && | |
242 | parent=$(echo parent | git commit-tree $tree) && | |
243 | commit=$(echo commit | git commit-tree $tree -p $parent) && | |
244 | cat >revs <<-EOF | |
245 | HEAD | |
246 | ^HEAD^ | |
247 | ^$commit | |
248 | EOF | |
249 | ' | |
250 | ||
251 | test_expect_success 'pack-objects respects --incremental' ' | |
252 | cat >revs2 <<-EOF && | |
253 | HEAD | |
254 | $commit | |
255 | EOF | |
256 | git pack-objects --incremental --stdout --revs <revs2 >4.pack && | |
257 | git index-pack 4.pack && | |
258 | list_packed_objects 4.idx >4.objects && | |
259 | test_line_count = 4 4.objects && | |
260 | git rev-list --objects $commit >revlist && | |
261 | cut -d" " -f1 revlist |sort >objects && | |
262 | test_cmp 4.objects objects | |
263 | ' | |
264 | ||
265 | test_expect_success 'pack with missing blob' ' | |
266 | rm $(objpath $blob) && | |
267 | git pack-objects --stdout --revs <revs >/dev/null | |
268 | ' | |
269 | ||
270 | test_expect_success 'pack with missing tree' ' | |
271 | rm $(objpath $tree) && | |
272 | git pack-objects --stdout --revs <revs >/dev/null | |
273 | ' | |
274 | ||
275 | test_expect_success 'pack with missing parent' ' | |
276 | rm $(objpath $parent) && | |
277 | git pack-objects --stdout --revs <revs >/dev/null | |
278 | ' | |
279 | ||
280 | test_expect_success JGIT,SHA1 'we can read jgit bitmaps' ' | |
281 | git clone --bare . compat-jgit.git && | |
282 | ( | |
283 | cd compat-jgit.git && | |
284 | rm -f objects/pack/*.bitmap && | |
285 | jgit gc && | |
286 | git rev-list --test-bitmap HEAD | |
287 | ) | |
288 | ' | |
289 | ||
290 | test_expect_success JGIT,SHA1 'jgit can read our bitmaps' ' | |
291 | git clone --bare . compat-us.git && | |
292 | ( | |
293 | cd compat-us.git && | |
294 | git repack -adb && | |
295 | # jgit gc will barf if it does not like our bitmaps | |
296 | jgit gc | |
297 | ) | |
298 | ' | |
299 | ||
300 | test_expect_success 'splitting packs does not generate bogus bitmaps' ' | |
301 | test-tool genrandom foo $((1024 * 1024)) >rand && | |
302 | git add rand && | |
303 | git commit -m "commit with big file" && | |
304 | git -c pack.packSizeLimit=500k repack -adb && | |
305 | git init --bare no-bitmaps.git && | |
306 | git -C no-bitmaps.git fetch .. HEAD | |
307 | ' | |
308 | ||
309 | test_expect_success 'set up reusable pack' ' | |
310 | rm -f .git/objects/pack/*.keep && | |
311 | git repack -adb && | |
312 | reusable_pack () { | |
313 | git for-each-ref --format="%(objectname)" | | |
314 | git pack-objects --delta-base-offset --revs --stdout "$@" | |
315 | } | |
316 | ' | |
317 | ||
318 | test_expect_success 'pack reuse respects --honor-pack-keep' ' | |
319 | test_when_finished "rm -f .git/objects/pack/*.keep" && | |
320 | for i in .git/objects/pack/*.pack | |
321 | do | |
322 | >${i%.pack}.keep | |
323 | done && | |
324 | reusable_pack --honor-pack-keep >empty.pack && | |
325 | git index-pack empty.pack && | |
326 | git show-index <empty.idx >actual && | |
327 | test_must_be_empty actual | |
328 | ' | |
329 | ||
330 | test_expect_success 'pack reuse respects --local' ' | |
331 | mv .git/objects/pack/* alt.git/objects/pack/ && | |
332 | test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" && | |
333 | reusable_pack --local >empty.pack && | |
334 | git index-pack empty.pack && | |
335 | git show-index <empty.idx >actual && | |
336 | test_must_be_empty actual | |
337 | ' | |
338 | ||
339 | test_expect_success 'pack reuse respects --incremental' ' | |
340 | reusable_pack --incremental >empty.pack && | |
341 | git index-pack empty.pack && | |
342 | git show-index <empty.idx >actual && | |
343 | test_must_be_empty actual | |
344 | ' | |
345 | ||
346 | test_expect_success 'truncated bitmap fails gracefully' ' | |
347 | git repack -ad && | |
348 | git rev-list --use-bitmap-index --count --all >expect && | |
349 | bitmap=$(ls .git/objects/pack/*.bitmap) && | |
350 | test_when_finished "rm -f $bitmap" && | |
351 | test_copy_bytes 512 <$bitmap >$bitmap.tmp && | |
352 | mv -f $bitmap.tmp $bitmap && | |
353 | git rev-list --use-bitmap-index --count --all >actual 2>stderr && | |
354 | test_cmp expect actual && | |
355 | test_i18ngrep corrupt stderr | |
356 | ' | |
357 | ||
358 | # have_delta <obj> <expected_base> | |
359 | # | |
360 | # Note that because this relies on cat-file, it might find _any_ copy of an | |
361 | # object in the repository. The caller is responsible for making sure | |
362 | # there's only one (e.g., via "repack -ad", or having just fetched a copy). | |
363 | have_delta () { | |
364 | echo $2 >expect && | |
365 | echo $1 | git cat-file --batch-check="%(deltabase)" >actual && | |
366 | test_cmp expect actual | |
367 | } | |
368 | ||
369 | # Create a state of history with these properties: | |
370 | # | |
371 | # - refs that allow a client to fetch some new history, while sharing some old | |
372 | # history with the server; we use branches delta-reuse-old and | |
373 | # delta-reuse-new here | |
374 | # | |
375 | # - the new history contains an object that is stored on the server as a delta | |
376 | # against a base that is in the old history | |
377 | # | |
378 | # - the base object is not immediately reachable from the tip of the old | |
379 | # history; finding it would involve digging down through history we know the | |
380 | # other side has | |
381 | # | |
382 | # This should result in a state where fetching from old->new would not | |
383 | # traditionally reuse the on-disk delta (because we'd have to dig to realize | |
384 | # that the client has it), but we will do so if bitmaps can tell us cheaply | |
385 | # that the other side has it. | |
386 | test_expect_success 'set up thin delta-reuse parent' ' | |
387 | # This first commit contains the buried base object. | |
388 | test-tool genrandom delta 16384 >file && | |
389 | git add file && | |
390 | git commit -m "delta base" && | |
391 | base=$(git rev-parse --verify HEAD:file) && | |
392 | ||
393 | # These intermediate commits bury the base back in history. | |
394 | # This becomes the "old" state. | |
395 | for i in 1 2 3 4 5 | |
396 | do | |
397 | echo $i >file && | |
398 | git commit -am "intermediate $i" || return 1 | |
399 | done && | |
400 | git branch delta-reuse-old && | |
401 | ||
402 | # And now our new history has a delta against the buried base. Note | |
403 | # that this must be smaller than the original file, since pack-objects | |
404 | # prefers to create deltas from smaller objects to larger. | |
405 | test-tool genrandom delta 16300 >file && | |
406 | git commit -am "delta result" && | |
407 | delta=$(git rev-parse --verify HEAD:file) && | |
408 | git branch delta-reuse-new && | |
409 | ||
410 | # Repack with bitmaps and double check that we have the expected delta | |
411 | # relationship. | |
412 | git repack -adb && | |
413 | have_delta $delta $base | |
414 | ' | |
415 | ||
416 | # Now we can sanity-check the non-bitmap behavior (that the server is not able | |
417 | # to reuse the delta). This isn't strictly something we care about, so this | |
418 | # test could be scrapped in the future. But it makes sure that the next test is | |
419 | # actually triggering the feature we want. | |
420 | # | |
421 | # Note that our tools for working with on-the-wire "thin" packs are limited. So | |
422 | # we actually perform the fetch, retain the resulting pack, and inspect the | |
423 | # result. | |
424 | test_expect_success 'fetch without bitmaps ignores delta against old base' ' | |
425 | test_config pack.usebitmaps false && | |
426 | test_when_finished "rm -rf client.git" && | |
427 | git init --bare client.git && | |
428 | ( | |
429 | cd client.git && | |
430 | git config transfer.unpackLimit 1 && | |
431 | git fetch .. delta-reuse-old:delta-reuse-old && | |
432 | git fetch .. delta-reuse-new:delta-reuse-new && | |
433 | have_delta $delta $ZERO_OID | |
434 | ) | |
435 | ' | |
436 | ||
437 | # And do the same for the bitmap case, where we do expect to find the delta. | |
438 | test_expect_success 'fetch with bitmaps can reuse old base' ' | |
439 | test_config pack.usebitmaps true && | |
440 | test_when_finished "rm -rf client.git" && | |
441 | git init --bare client.git && | |
442 | ( | |
443 | cd client.git && | |
444 | git config transfer.unpackLimit 1 && | |
445 | git fetch .. delta-reuse-old:delta-reuse-old && | |
446 | git fetch .. delta-reuse-new:delta-reuse-new && | |
447 | have_delta $delta $base | |
448 | ) | |
449 | ' | |
450 | ||
451 | test_done |