3 test_description='exercise basic bitmap functionality'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 echo ".git/objects/$(echo "$1" | sed -e 's|\(..\)|\1/|')"
13 # show objects present in pack ($1 should be associated *.idx)
14 list_packed_objects () {
15 git show-index <"$1" >object-list &&
16 cut -d' ' -f2 object-list
19 # has_any pattern-file content-file
20 # tests whether content-file has any entry from pattern-file with entries being
26 test_expect_success 'setup repo with moderate-sized history' '
27 test_commit_bulk --id=file 100 &&
28 git checkout -b other HEAD~5 &&
29 test_commit_bulk --id=side 10 &&
30 git checkout master &&
31 bitmaptip=$(git rev-parse master) &&
32 blob=$(echo tagged-blob | git hash-object -w --stdin) &&
33 git tag tagged-blob $blob &&
34 git config repack.writebitmaps true
37 test_expect_success 'full repack creates bitmaps' '
39 ls .git/objects/pack/ | grep bitmap >output &&
40 test_line_count = 1 output
43 test_expect_success 'rev-list --test-bitmap verifies bitmaps' '
44 git rev-list --test-bitmap HEAD
50 test_expect_success "counting commits via bitmap ($state)" '
51 git rev-list --count HEAD >expect &&
52 git rev-list --use-bitmap-index --count HEAD >actual &&
53 test_cmp expect actual
56 test_expect_success "counting partial commits via bitmap ($state)" '
57 git rev-list --count HEAD~5..HEAD >expect &&
58 git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual &&
59 test_cmp expect actual
62 test_expect_success "counting commits with limit ($state)" '
63 git rev-list --count -n 1 HEAD >expect &&
64 git rev-list --use-bitmap-index --count -n 1 HEAD >actual &&
65 test_cmp expect actual
68 test_expect_success "counting non-linear history ($state)" '
69 git rev-list --count other...master >expect &&
70 git rev-list --use-bitmap-index --count other...master >actual &&
71 test_cmp expect actual
74 test_expect_success "counting commits with limiting ($state)" '
75 git rev-list --count HEAD -- 1.t >expect &&
76 git rev-list --use-bitmap-index --count HEAD -- 1.t >actual &&
77 test_cmp expect actual
80 test_expect_success "counting objects via bitmap ($state)" '
81 git rev-list --count --objects HEAD >expect &&
82 git rev-list --use-bitmap-index --count --objects HEAD >actual &&
83 test_cmp expect actual
86 test_expect_success "enumerate commits ($state)" '
87 git rev-list --use-bitmap-index HEAD >actual &&
88 git rev-list HEAD >expect &&
89 test_bitmap_traversal --no-confirm-bitmaps expect actual
92 test_expect_success "enumerate --objects ($state)" '
93 git rev-list --objects --use-bitmap-index HEAD >actual &&
94 git rev-list --objects HEAD >expect &&
95 test_bitmap_traversal expect actual
98 test_expect_success "bitmap --objects handles non-commit objects ($state)" '
99 git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual &&
104 rev_list_tests 'full bitmap'
106 test_expect_success 'clone from bitmapped repository' '
107 git clone --no-local --bare . clone.git &&
108 git rev-parse HEAD >expect &&
109 git --git-dir=clone.git rev-parse HEAD >actual &&
110 test_cmp expect actual
113 test_expect_success 'partial clone from bitmapped repository' '
114 test_config uploadpack.allowfilter true &&
115 git clone --no-local --bare --filter=blob:none . partial-clone.git &&
117 cd partial-clone.git &&
118 pack=$(echo objects/pack/*.pack) &&
119 git verify-pack -v "$pack" >have &&
120 awk "/blob/ { print \$1 }" <have >blobs &&
121 # we expect this single blob because of the direct ref
122 git rev-parse refs/tags/tagged-blob >expect &&
123 test_cmp expect blobs
127 test_expect_success 'setup further non-bitmapped commits' '
128 test_commit_bulk --id=further 10
131 rev_list_tests 'partial bitmap'
133 test_expect_success 'fetch (partial bitmap)' '
134 git --git-dir=clone.git fetch origin master:master &&
135 git rev-parse HEAD >expect &&
136 git --git-dir=clone.git rev-parse HEAD >actual &&
137 test_cmp expect actual
140 test_expect_success 'incremental repack fails when bitmaps are requested' '
141 test_commit more-1 &&
142 test_must_fail git repack -d 2>err &&
143 test_i18ngrep "Incremental repacks are incompatible with bitmap" err
146 test_expect_success 'incremental repack can disable bitmaps' '
147 test_commit more-2 &&
148 git repack -d --no-write-bitmap-index
151 test_expect_success 'pack-objects respects --local (non-local loose)' '
152 git init --bare alt.git &&
153 echo $(pwd)/alt.git/objects >.git/objects/info/alternates &&
154 echo content1 >file1 &&
155 # non-local loose object which is not present in bitmapped pack
156 altblob=$(GIT_DIR=alt.git git hash-object -w file1) &&
157 # non-local loose object which is also present in bitmapped pack
158 git cat-file blob $blob | GIT_DIR=alt.git git hash-object -w --stdin &&
161 git commit -m commit_file1 &&
162 echo HEAD | git pack-objects --local --stdout --revs >1.pack &&
163 git index-pack 1.pack &&
164 list_packed_objects 1.idx >1.objects &&
165 printf "%s\n" "$altblob" "$blob" >nonlocal-loose &&
166 ! has_any nonlocal-loose 1.objects
169 test_expect_success 'pack-objects respects --honor-pack-keep (local non-bitmapped pack)' '
170 echo content2 >file2 &&
171 blob2=$(git hash-object -w file2) &&
174 git commit -m commit_file2 &&
175 printf "%s\n" "$blob2" "$bitmaptip" >keepobjects &&
176 pack2=$(git pack-objects pack2 <keepobjects) &&
177 mv pack2-$pack2.* .git/objects/pack/ &&
178 >.git/objects/pack/pack2-$pack2.keep &&
179 rm $(objpath $blob2) &&
180 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >2a.pack &&
181 git index-pack 2a.pack &&
182 list_packed_objects 2a.idx >2a.objects &&
183 ! has_any keepobjects 2a.objects
186 test_expect_success 'pack-objects respects --local (non-local pack)' '
187 mv .git/objects/pack/pack2-$pack2.* alt.git/objects/pack/ &&
188 echo HEAD | git pack-objects --local --stdout --revs >2b.pack &&
189 git index-pack 2b.pack &&
190 list_packed_objects 2b.idx >2b.objects &&
191 ! has_any keepobjects 2b.objects
194 test_expect_success 'pack-objects respects --honor-pack-keep (local bitmapped pack)' '
195 ls .git/objects/pack/ | grep bitmap >output &&
196 test_line_count = 1 output &&
197 packbitmap=$(basename $(cat output) .bitmap) &&
198 list_packed_objects .git/objects/pack/$packbitmap.idx >packbitmap.objects &&
199 test_when_finished "rm -f .git/objects/pack/$packbitmap.keep" &&
200 >.git/objects/pack/$packbitmap.keep &&
201 echo HEAD | git pack-objects --honor-pack-keep --stdout --revs >3a.pack &&
202 git index-pack 3a.pack &&
203 list_packed_objects 3a.idx >3a.objects &&
204 ! has_any packbitmap.objects 3a.objects
207 test_expect_success 'pack-objects respects --local (non-local bitmapped pack)' '
208 mv .git/objects/pack/$packbitmap.* alt.git/objects/pack/ &&
209 rm -f .git/objects/pack/multi-pack-index &&
210 test_when_finished "mv alt.git/objects/pack/$packbitmap.* .git/objects/pack/" &&
211 echo HEAD | git pack-objects --local --stdout --revs >3b.pack &&
212 git index-pack 3b.pack &&
213 list_packed_objects 3b.idx >3b.objects &&
214 ! has_any packbitmap.objects 3b.objects
217 test_expect_success 'pack-objects to file can use bitmap' '
218 # make sure we still have 1 bitmap index from previous tests
219 ls .git/objects/pack/ | grep bitmap >output &&
220 test_line_count = 1 output &&
221 # verify equivalent packs are generated with/without using bitmap index
222 packasha1=$(git pack-objects --no-use-bitmap-index --all packa </dev/null) &&
223 packbsha1=$(git pack-objects --use-bitmap-index --all packb </dev/null) &&
224 list_packed_objects packa-$packasha1.idx >packa.objects &&
225 list_packed_objects packb-$packbsha1.idx >packb.objects &&
226 test_cmp packa.objects packb.objects
229 test_expect_success 'full repack, reusing previous bitmaps' '
231 ls .git/objects/pack/ | grep bitmap >output &&
232 test_line_count = 1 output
235 test_expect_success 'fetch (full bitmap)' '
236 git --git-dir=clone.git fetch origin master:master &&
237 git rev-parse HEAD >expect &&
238 git --git-dir=clone.git rev-parse HEAD >actual &&
239 test_cmp expect actual
242 test_expect_success 'create objects for missing-HAVE tests' '
243 blob=$(echo "missing have" | git hash-object -w --stdin) &&
244 tree=$(printf "100644 blob $blob\tfile\n" | git mktree) &&
245 parent=$(echo parent | git commit-tree $tree) &&
246 commit=$(echo commit | git commit-tree $tree -p $parent) &&
254 test_expect_success 'pack-objects respects --incremental' '
259 git pack-objects --incremental --stdout --revs <revs2 >4.pack &&
260 git index-pack 4.pack &&
261 list_packed_objects 4.idx >4.objects &&
262 test_line_count = 4 4.objects &&
263 git rev-list --objects $commit >revlist &&
264 cut -d" " -f1 revlist |sort >objects &&
265 test_cmp 4.objects objects
268 test_expect_success 'pack with missing blob' '
269 rm $(objpath $blob) &&
270 git pack-objects --stdout --revs <revs >/dev/null
273 test_expect_success 'pack with missing tree' '
274 rm $(objpath $tree) &&
275 git pack-objects --stdout --revs <revs >/dev/null
278 test_expect_success 'pack with missing parent' '
279 rm $(objpath $parent) &&
280 git pack-objects --stdout --revs <revs >/dev/null
283 test_expect_success JGIT 'we can read jgit bitmaps' '
284 git clone --bare . compat-jgit.git &&
286 cd compat-jgit.git &&
287 rm -f objects/pack/*.bitmap &&
289 git rev-list --test-bitmap HEAD
293 test_expect_success JGIT 'jgit can read our bitmaps' '
294 git clone --bare . compat-us.git &&
298 # jgit gc will barf if it does not like our bitmaps
303 test_expect_success 'splitting packs does not generate bogus bitmaps' '
304 test-tool genrandom foo $((1024 * 1024)) >rand &&
306 git commit -m "commit with big file" &&
307 git -c pack.packSizeLimit=500k repack -adb &&
308 git init --bare no-bitmaps.git &&
309 git -C no-bitmaps.git fetch .. HEAD
312 test_expect_success 'set up reusable pack' '
313 rm -f .git/objects/pack/*.keep &&
316 git for-each-ref --format="%(objectname)" |
317 git pack-objects --delta-base-offset --revs --stdout "$@"
321 test_expect_success 'pack reuse respects --honor-pack-keep' '
322 test_when_finished "rm -f .git/objects/pack/*.keep" &&
323 for i in .git/objects/pack/*.pack
327 reusable_pack --honor-pack-keep >empty.pack &&
328 git index-pack empty.pack &&
329 git show-index <empty.idx >actual &&
330 test_must_be_empty actual
333 test_expect_success 'pack reuse respects --local' '
334 mv .git/objects/pack/* alt.git/objects/pack/ &&
335 test_when_finished "mv alt.git/objects/pack/* .git/objects/pack/" &&
336 reusable_pack --local >empty.pack &&
337 git index-pack empty.pack &&
338 git show-index <empty.idx >actual &&
339 test_must_be_empty actual
342 test_expect_success 'pack reuse respects --incremental' '
343 reusable_pack --incremental >empty.pack &&
344 git index-pack empty.pack &&
345 git show-index <empty.idx >actual &&
346 test_must_be_empty actual
349 test_expect_success 'truncated bitmap fails gracefully' '
351 git rev-list --use-bitmap-index --count --all >expect &&
352 bitmap=$(ls .git/objects/pack/*.bitmap) &&
353 test_when_finished "rm -f $bitmap" &&
354 test_copy_bytes 512 <$bitmap >$bitmap.tmp &&
355 mv -f $bitmap.tmp $bitmap &&
356 git rev-list --use-bitmap-index --count --all >actual 2>stderr &&
357 test_cmp expect actual &&
358 test_i18ngrep corrupt stderr
361 # have_delta <obj> <expected_base>
363 # Note that because this relies on cat-file, it might find _any_ copy of an
364 # object in the repository. The caller is responsible for making sure
365 # there's only one (e.g., via "repack -ad", or having just fetched a copy).
368 echo $1 | git cat-file --batch-check="%(deltabase)" >actual &&
369 test_cmp expect actual
372 # Create a state of history with these properties:
374 # - refs that allow a client to fetch some new history, while sharing some old
375 # history with the server; we use branches delta-reuse-old and
376 # delta-reuse-new here
378 # - the new history contains an object that is stored on the server as a delta
379 # against a base that is in the old history
381 # - the base object is not immediately reachable from the tip of the old
382 # history; finding it would involve digging down through history we know the
385 # This should result in a state where fetching from old->new would not
386 # traditionally reuse the on-disk delta (because we'd have to dig to realize
387 # that the client has it), but we will do so if bitmaps can tell us cheaply
388 # that the other side has it.
389 test_expect_success 'set up thin delta-reuse parent' '
390 # This first commit contains the buried base object.
391 test-tool genrandom delta 16384 >file &&
393 git commit -m "delta base" &&
394 base=$(git rev-parse --verify HEAD:file) &&
396 # These intermediate commits bury the base back in history.
397 # This becomes the "old" state.
401 git commit -am "intermediate $i" || return 1
403 git branch delta-reuse-old &&
405 # And now our new history has a delta against the buried base. Note
406 # that this must be smaller than the original file, since pack-objects
407 # prefers to create deltas from smaller objects to larger.
408 test-tool genrandom delta 16300 >file &&
409 git commit -am "delta result" &&
410 delta=$(git rev-parse --verify HEAD:file) &&
411 git branch delta-reuse-new &&
413 # Repack with bitmaps and double check that we have the expected delta
416 have_delta $delta $base
419 # Now we can sanity-check the non-bitmap behavior (that the server is not able
420 # to reuse the delta). This isn't strictly something we care about, so this
421 # test could be scrapped in the future. But it makes sure that the next test is
422 # actually triggering the feature we want.
424 # Note that our tools for working with on-the-wire "thin" packs are limited. So
425 # we actually perform the fetch, retain the resulting pack, and inspect the
427 test_expect_success 'fetch without bitmaps ignores delta against old base' '
428 test_config pack.usebitmaps false &&
429 test_when_finished "rm -rf client.git" &&
430 git init --bare client.git &&
433 git config transfer.unpackLimit 1 &&
434 git fetch .. delta-reuse-old:delta-reuse-old &&
435 git fetch .. delta-reuse-new:delta-reuse-new &&
436 have_delta $delta $ZERO_OID
440 # And do the same for the bitmap case, where we do expect to find the delta.
441 test_expect_success 'fetch with bitmaps can reuse old base' '
442 test_config pack.usebitmaps true &&
443 test_when_finished "rm -rf client.git" &&
444 git init --bare client.git &&
447 git config transfer.unpackLimit 1 &&
448 git fetch .. delta-reuse-old:delta-reuse-old &&
449 git fetch .. delta-reuse-new:delta-reuse-new &&
450 have_delta $delta $base