diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-06-23 21:21:17 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-06-23 21:21:17 +0300 |
commit | 1d15be363ccf0ff4337886568087d0467c93c9a9 (patch) | |
tree | 3fd02937071ffdc5a3b70a7a55757cfd6d622292 | |
parent | 58ecb2e3838b1dfd9c3705de88dcd491fa4e44fc (diff) | |
parent | 06f38678654eb40c46fe09ec52ae9f864ccafa03 (diff) |
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
-rw-r--r-- | pack-bitmap.c | 8 | ||||
-rwxr-xr-x | t/t5326-multi-pack-bitmaps.sh | 35 |
2 files changed, 40 insertions, 3 deletions
diff --git a/pack-bitmap.c b/pack-bitmap.c index 894bff02c5..35669e2478 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -387,9 +387,11 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git, } for (i = 0; i < bitmap_git->midx->num_packs; i++) { - if (prepare_midx_pack(the_repository, bitmap_git->midx, i)) - die(_("could not open pack %s"), - bitmap_git->midx->pack_names[i]); + if (prepare_midx_pack(the_repository, bitmap_git->midx, i)) { + warning(_("could not open pack %s"), + bitmap_git->midx->pack_names[i]); + goto cleanup; + } } preferred = bitmap_git->midx->packs[midx_preferred_pack(bitmap_git)]; diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh index f771c442d4..70d1b58709 100755 --- a/t/t5326-multi-pack-bitmaps.sh +++ b/t/t5326-multi-pack-bitmaps.sh @@ -478,4 +478,39 @@ test_expect_success 'git fsck correctly identifies good and bad bitmaps' ' grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err ' +test_expect_success 'corrupt MIDX with bitmap causes fallback' ' + git init corrupt-midx-bitmap && + ( + cd corrupt-midx-bitmap && + + test_commit first && + git repack -d && + test_commit second && + git repack -d && + + git multi-pack-index write --bitmap && + checksum=$(midx_checksum $objdir) && + for f in $midx $midx-$checksum.bitmap + do + mv $f $f.bak || return 1 + done && + + # pack everything together, invalidating the MIDX + git repack -ad && + # then restore the now-stale MIDX + for f in $midx $midx-$checksum.bitmap + do + mv $f.bak $f || return 1 + done && + + git rev-list --count --objects --use-bitmap-index HEAD >out 2>err && + # should attempt opening the broken pack twice (once + # from the attempt to load it via the stale bitmap, and + # again when attempting to load it from the stale MIDX) + # before falling back to the non-MIDX case + test 2 -eq $(grep -c "could not open pack" err) && + test 6 -eq $(cat out) + ) +' + test_done |