1
# Helpers for scripts testing bitmap functionality; see t5310 for
2
# example usage.
3
4
+objdir=.git/objects
5
+midx=$objdir/pack/multi-pack-index
6
+
7
# Compare a file containing rev-list bitmap traversal output to its non-bitmap
8
# counterpart. You can't just use test_cmp for this, because the two produce
9
# subtly different output:
267
midx_checksum () {
268
test-tool read-midx --checksum "$1"
269
}
270
+
271
+# midx_pack_source <obj>
272
+midx_pack_source () {
273
+ test-tool read-midx --show-objects .git/objects | grep "^$1 " | cut -f2
274
+}
275
+
276
+test_rev_exists () {
277
+ commit="$1"
278
+
279
+ test_expect_success 'reverse index exists' '
280
+ GIT_TRACE2_EVENT=$(pwd)/event.trace \
281
+ git rev-list --test-bitmap "$commit" &&
282
+
283
+ test_path_is_file $midx-$(midx_checksum $objdir).rev &&
284
+ grep "\"category\":\"load_midx_revindex\",\"key\":\"source\",\"value\":\"rev\"" event.trace
285
+ '
286
+}
287
+
288
+midx_bitmap_core () {
289
+ setup_bitmap_history
290
+
291
+ test_expect_success 'create single-pack midx with bitmaps' '
292
+ git repack -ad &&
293
+ git multi-pack-index write --bitmap &&
294
+ test_path_is_file $midx &&
295
+ test_path_is_file $midx-$(midx_checksum $objdir).bitmap
296
+ '
297
+
298
+ test_rev_exists HEAD
299
+
300
+ basic_bitmap_tests
301
+
302
+ test_expect_success 'create new additional packs' '
303
+ for i in $(test_seq 1 16)
304
+ do
305
+ test_commit "$i" &&
306
+ git repack -d || return 1
307
+ done &&
308
+
309
+ git checkout -b other2 HEAD~8 &&
310
+ for i in $(test_seq 1 8)
311
+ do
312
+ test_commit "side-$i" &&
313
+ git repack -d || return 1
314
+ done &&
315
+ git checkout second
316
+ '
317
+
318
+ test_expect_success 'create multi-pack midx with bitmaps' '
319
+ git multi-pack-index write --bitmap &&
320
+
321
+ ls $objdir/pack/pack-*.pack >packs &&
322
+ test_line_count = 25 packs &&
323
+
324
+ test_path_is_file $midx &&
325
+ test_path_is_file $midx-$(midx_checksum $objdir).bitmap
326
+ '
327
+
328
+ test_rev_exists HEAD
329
+
330
+ basic_bitmap_tests
331
+
332
+ test_expect_success '--no-bitmap is respected when bitmaps exist' '
333
+ git multi-pack-index write --bitmap &&
334
+
335
+ test_commit respect--no-bitmap &&
336
+ git repack -d &&
337
+
338
+ test_path_is_file $midx &&
339
+ test_path_is_file $midx-$(midx_checksum $objdir).bitmap &&
340
+
341
+ git multi-pack-index write --no-bitmap &&
342
+
343
+ test_path_is_file $midx &&
344
+ test_path_is_missing $midx-$(midx_checksum $objdir).bitmap &&
345
+ test_path_is_missing $midx-$(midx_checksum $objdir).rev
346
+ '
347
+
348
+ test_expect_success 'setup midx with base from later pack' '
349
+ # Write a and b so that "a" is a delta on top of base "b", since Git
350
+ # prefers to delete contents out of a base rather than add to a shorter
351
+ # object.
352
+ test_seq 1 128 >a &&
353
+ test_seq 1 130 >b &&
354
+
355
+ git add a b &&
356
+ git commit -m "initial commit" &&
357
+
358
+ a=$(git rev-parse HEAD:a) &&
359
+ b=$(git rev-parse HEAD:b) &&
360
+
361
+ # In the first pack, "a" is stored as a delta to "b".
362
+ p1=$(git pack-objects .git/objects/pack/pack <<-EOF
363
+ $a
364
+ $b
365
+ EOF
366
+ ) &&
367
+
368
+ # In the second pack, "a" is missing, and "b" is not a delta nor base to
369
+ # any other object.
370
+ p2=$(git pack-objects .git/objects/pack/pack <<-EOF
371
+ $b
372
+ $(git rev-parse HEAD)
373
+ $(git rev-parse HEAD^{tree})
374
+ EOF
375
+ ) &&
376
+
377
+ git prune-packed &&
378
+ # Use the second pack as the preferred source, so that "b" occurs
379
+ # earlier in the MIDX object order, rendering "a" unusable for pack
380
+ # reuse.
381
+ git multi-pack-index write --bitmap --preferred-pack=pack-$p2.idx &&
382
+
383
+ have_delta $a $b &&
384
+ test $(midx_pack_source $a) != $(midx_pack_source $b)
385
+ '
386
+
387
+ rev_list_tests 'full bitmap with backwards delta'
388
+
389
+ test_expect_success 'clone with bitmaps enabled' '
390
+ git clone --no-local --bare . clone-reverse-delta.git &&
391
+ test_when_finished "rm -fr clone-reverse-delta.git" &&
392
+
393
+ git rev-parse HEAD >expect &&
394
+ git --git-dir=clone-reverse-delta.git rev-parse HEAD >actual &&
395
+ test_cmp expect actual
396
+ '
397
+
398
+ test_expect_success 'changing the preferred pack does not corrupt bitmaps' '
399
+ rm -fr repo &&
400
+ git init repo &&
401
+ test_when_finished "rm -fr repo" &&
402
+ (
403
+ cd repo &&
404
+
405
+ test_commit A &&
406
+ test_commit B &&
407
+
408
+ git rev-list --objects --no-object-names HEAD^ >A.objects &&
409
+ git rev-list --objects --no-object-names HEAD^.. >B.objects &&
410
+
411
+ A=$(git pack-objects $objdir/pack/pack <A.objects) &&
412
+ B=$(git pack-objects $objdir/pack/pack <B.objects) &&
413
+
414
+ cat >indexes <<-EOF &&
415
+ pack-$A.idx
416
+ pack-$B.idx
417
+ EOF
418
+
419
+ git multi-pack-index write --bitmap --stdin-packs \
420
+ --preferred-pack=pack-$A.pack <indexes &&
421
+ git rev-list --test-bitmap A &&
422
+
423
+ git multi-pack-index write --bitmap --stdin-packs \
424
+ --preferred-pack=pack-$B.pack <indexes &&
425
+ git rev-list --test-bitmap A
426
+ )
427
+ '
428
+}
429
+
430
+midx_bitmap_partial_tests () {
431
+ test_expect_success 'setup partial bitmaps' '
432
+ test_commit packed &&
433
+ git repack &&
434
+ test_commit loose &&
435
+ git multi-pack-index write --bitmap 2>err &&
436
+ test_path_is_file $midx &&
437
+ test_path_is_file $midx-$(midx_checksum $objdir).bitmap
438
+ '
439
+
440
+ test_rev_exists HEAD~
441
+
442
+ basic_bitmap_tests HEAD~
443
+}