Skip to content

Commit 1d15be3

Browse files
committed
Merge branch 'tb/open-midx-bitmap-fallback'
Gracefully deal with a stale MIDX file that lists a packfile that no longer exists. * tb/open-midx-bitmap-fallback: pack-bitmap.c: gracefully degrade on failure to load MIDX'd pack
2 parents 58ecb2e + 06f3867 commit 1d15be3

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

pack-bitmap.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,11 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
387387
}
388388

389389
for (i = 0; i < bitmap_git->midx->num_packs; i++) {
390-
if (prepare_midx_pack(the_repository, bitmap_git->midx, i))
391-
die(_("could not open pack %s"),
392-
bitmap_git->midx->pack_names[i]);
390+
if (prepare_midx_pack(the_repository, bitmap_git->midx, i)) {
391+
warning(_("could not open pack %s"),
392+
bitmap_git->midx->pack_names[i]);
393+
goto cleanup;
394+
}
393395
}
394396

395397
preferred = bitmap_git->midx->packs[midx_preferred_pack(bitmap_git)];

t/t5326-multi-pack-bitmaps.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,39 @@ test_expect_success 'git fsck correctly identifies good and bad bitmaps' '
478478
grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err
479479
'
480480

481+
test_expect_success 'corrupt MIDX with bitmap causes fallback' '
482+
git init corrupt-midx-bitmap &&
483+
(
484+
cd corrupt-midx-bitmap &&
485+
486+
test_commit first &&
487+
git repack -d &&
488+
test_commit second &&
489+
git repack -d &&
490+
491+
git multi-pack-index write --bitmap &&
492+
checksum=$(midx_checksum $objdir) &&
493+
for f in $midx $midx-$checksum.bitmap
494+
do
495+
mv $f $f.bak || return 1
496+
done &&
497+
498+
# pack everything together, invalidating the MIDX
499+
git repack -ad &&
500+
# then restore the now-stale MIDX
501+
for f in $midx $midx-$checksum.bitmap
502+
do
503+
mv $f.bak $f || return 1
504+
done &&
505+
506+
git rev-list --count --objects --use-bitmap-index HEAD >out 2>err &&
507+
# should attempt opening the broken pack twice (once
508+
# from the attempt to load it via the stale bitmap, and
509+
# again when attempting to load it from the stale MIDX)
510+
# before falling back to the non-MIDX case
511+
test 2 -eq $(grep -c "could not open pack" err) &&
512+
test 6 -eq $(cat out)
513+
)
514+
'
515+
481516
test_done

0 commit comments

Comments
 (0)