aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-04-23 11:52:40 -0700
committerJunio C Hamano <gitster@pobox.com>2024-04-23 11:52:40 -0700
commit567293123d874bfb0607de7e8d6c65642107f132 (patch)
treedff83afc28af9860d073b6f67d9a5a8bc1ab154b
parentc9f1f88bb09676706f344b41cc80821ee2859984 (diff)
parent795006fff45fb2b5e92be0121f92a876c409a1a3 (diff)
Merge branch 'ps/missing-btmp-fix'
GIt 2.44 introduced a regression that makes the updated code to barf in repositories with multi-pack index written by older versions of Git, which has been corrected. * ps/missing-btmp-fix: pack-bitmap: gracefully handle missing BTMP chunks
-rw-r--r--midx.c7
-rw-r--r--pack-bitmap.c41
-rwxr-xr-xt/t5326-multi-pack-bitmaps.sh17
3 files changed, 42 insertions, 23 deletions
diff --git a/midx.c b/midx.c
index ae3b49166c..6f07de3688 100644
--- a/midx.c
+++ b/midx.c
@@ -170,9 +170,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
pair_chunk(cf, MIDX_CHUNKID_LARGEOFFSETS, &m->chunk_large_offsets,
&m->chunk_large_offsets_len);
- pair_chunk(cf, MIDX_CHUNKID_BITMAPPEDPACKS,
- (const unsigned char **)&m->chunk_bitmapped_packs,
- &m->chunk_bitmapped_packs_len);
+ if (git_env_bool("GIT_TEST_MIDX_READ_BTMP", 1))
+ pair_chunk(cf, MIDX_CHUNKID_BITMAPPEDPACKS,
+ (const unsigned char **)&m->chunk_bitmapped_packs,
+ &m->chunk_bitmapped_packs_len);
if (git_env_bool("GIT_TEST_MIDX_READ_RIDX", 1))
pair_chunk(cf, MIDX_CHUNKID_REVINDEX, &m->chunk_revindex,
diff --git a/pack-bitmap.c b/pack-bitmap.c
index 2baeabacee..35c5ef9d3c 100644
--- a/pack-bitmap.c
+++ b/pack-bitmap.c
@@ -2049,7 +2049,10 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
load_reverse_index(r, bitmap_git);
- if (bitmap_is_midx(bitmap_git)) {
+ if (!bitmap_is_midx(bitmap_git) || !bitmap_git->midx->chunk_bitmapped_packs)
+ multi_pack_reuse = 0;
+
+ if (multi_pack_reuse) {
for (i = 0; i < bitmap_git->midx->num_packs; i++) {
struct bitmapped_pack pack;
if (nth_bitmapped_pack(r, bitmap_git->midx, &pack, i) < 0) {
@@ -2062,34 +2065,32 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
if (!pack.bitmap_nr)
continue;
- if (!multi_pack_reuse && pack.bitmap_pos) {
- /*
- * If we're only reusing a single pack, skip
- * over any packs which are not positioned at
- * the beginning of the MIDX bitmap.
- *
- * This is consistent with the existing
- * single-pack reuse behavior, which only reuses
- * parts of the MIDX's preferred pack.
- */
- continue;
- }
-
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
memcpy(&packs[packs_nr++], &pack, sizeof(pack));
objects_nr += pack.p->num_objects;
-
- if (!multi_pack_reuse)
- break;
}
QSORT(packs, packs_nr, bitmapped_pack_cmp);
} else {
- ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
+ struct packed_git *pack;
+
+ if (bitmap_is_midx(bitmap_git)) {
+ uint32_t preferred_pack_pos;
+
+ if (midx_preferred_pack(bitmap_git->midx, &preferred_pack_pos) < 0) {
+ warning(_("unable to compute preferred pack, disabling pack-reuse"));
+ return;
+ }
- packs[packs_nr].p = bitmap_git->pack;
- packs[packs_nr].bitmap_nr = bitmap_git->pack->num_objects;
+ pack = bitmap_git->midx->packs[preferred_pack_pos];
+ } else {
+ pack = bitmap_git->pack;
+ }
+
+ ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
+ packs[packs_nr].p = pack;
+ packs[packs_nr].bitmap_nr = pack->num_objects;
packs[packs_nr].bitmap_pos = 0;
objects_nr = packs[packs_nr++].bitmap_nr;
diff --git a/t/t5326-multi-pack-bitmaps.sh b/t/t5326-multi-pack-bitmaps.sh
index 70d1b58709..5d7d321840 100755
--- a/t/t5326-multi-pack-bitmaps.sh
+++ b/t/t5326-multi-pack-bitmaps.sh
@@ -513,4 +513,21 @@ test_expect_success 'corrupt MIDX with bitmap causes fallback' '
)
'
+for allow_pack_reuse in single multi
+do
+ test_expect_success "reading MIDX without BTMP chunk does not complain with $allow_pack_reuse pack reuse" '
+ test_when_finished "rm -rf midx-without-btmp" &&
+ git init midx-without-btmp &&
+ (
+ cd midx-without-btmp &&
+ test_commit initial &&
+
+ git repack -Adbl --write-bitmap-index --write-midx &&
+ GIT_TEST_MIDX_READ_BTMP=false git -c pack.allowPackReuse=$allow_pack_reuse \
+ pack-objects --all --use-bitmap-index --stdout </dev/null >/dev/null 2>err &&
+ test_must_be_empty err
+ )
+ '
+done
+
test_done