Skip to content

Commit 5672931

Browse files
committed
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
2 parents c9f1f88 + 795006f commit 5672931

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

midx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
170170

171171
pair_chunk(cf, MIDX_CHUNKID_LARGEOFFSETS, &m->chunk_large_offsets,
172172
&m->chunk_large_offsets_len);
173-
pair_chunk(cf, MIDX_CHUNKID_BITMAPPEDPACKS,
174-
(const unsigned char **)&m->chunk_bitmapped_packs,
175-
&m->chunk_bitmapped_packs_len);
173+
if (git_env_bool("GIT_TEST_MIDX_READ_BTMP", 1))
174+
pair_chunk(cf, MIDX_CHUNKID_BITMAPPEDPACKS,
175+
(const unsigned char **)&m->chunk_bitmapped_packs,
176+
&m->chunk_bitmapped_packs_len);
176177

177178
if (git_env_bool("GIT_TEST_MIDX_READ_RIDX", 1))
178179
pair_chunk(cf, MIDX_CHUNKID_REVINDEX, &m->chunk_revindex,

pack-bitmap.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,7 +2049,10 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
20492049

20502050
load_reverse_index(r, bitmap_git);
20512051

2052-
if (bitmap_is_midx(bitmap_git)) {
2052+
if (!bitmap_is_midx(bitmap_git) || !bitmap_git->midx->chunk_bitmapped_packs)
2053+
multi_pack_reuse = 0;
2054+
2055+
if (multi_pack_reuse) {
20532056
for (i = 0; i < bitmap_git->midx->num_packs; i++) {
20542057
struct bitmapped_pack pack;
20552058
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,
20622065
if (!pack.bitmap_nr)
20632066
continue;
20642067

2065-
if (!multi_pack_reuse && pack.bitmap_pos) {
2066-
/*
2067-
* If we're only reusing a single pack, skip
2068-
* over any packs which are not positioned at
2069-
* the beginning of the MIDX bitmap.
2070-
*
2071-
* This is consistent with the existing
2072-
* single-pack reuse behavior, which only reuses
2073-
* parts of the MIDX's preferred pack.
2074-
*/
2075-
continue;
2076-
}
2077-
20782068
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
20792069
memcpy(&packs[packs_nr++], &pack, sizeof(pack));
20802070

20812071
objects_nr += pack.p->num_objects;
2082-
2083-
if (!multi_pack_reuse)
2084-
break;
20852072
}
20862073

20872074
QSORT(packs, packs_nr, bitmapped_pack_cmp);
20882075
} else {
2089-
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
2076+
struct packed_git *pack;
2077+
2078+
if (bitmap_is_midx(bitmap_git)) {
2079+
uint32_t preferred_pack_pos;
2080+
2081+
if (midx_preferred_pack(bitmap_git->midx, &preferred_pack_pos) < 0) {
2082+
warning(_("unable to compute preferred pack, disabling pack-reuse"));
2083+
return;
2084+
}
20902085

2091-
packs[packs_nr].p = bitmap_git->pack;
2092-
packs[packs_nr].bitmap_nr = bitmap_git->pack->num_objects;
2086+
pack = bitmap_git->midx->packs[preferred_pack_pos];
2087+
} else {
2088+
pack = bitmap_git->pack;
2089+
}
2090+
2091+
ALLOC_GROW(packs, packs_nr + 1, packs_alloc);
2092+
packs[packs_nr].p = pack;
2093+
packs[packs_nr].bitmap_nr = pack->num_objects;
20932094
packs[packs_nr].bitmap_pos = 0;
20942095

20952096
objects_nr = packs[packs_nr++].bitmap_nr;

t/t5326-multi-pack-bitmaps.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,4 +513,21 @@ test_expect_success 'corrupt MIDX with bitmap causes fallback' '
513513
)
514514
'
515515

516+
for allow_pack_reuse in single multi
517+
do
518+
test_expect_success "reading MIDX without BTMP chunk does not complain with $allow_pack_reuse pack reuse" '
519+
test_when_finished "rm -rf midx-without-btmp" &&
520+
git init midx-without-btmp &&
521+
(
522+
cd midx-without-btmp &&
523+
test_commit initial &&
524+
525+
git repack -Adbl --write-bitmap-index --write-midx &&
526+
GIT_TEST_MIDX_READ_BTMP=false git -c pack.allowPackReuse=$allow_pack_reuse \
527+
pack-objects --all --use-bitmap-index --stdout </dev/null >/dev/null 2>err &&
528+
test_must_be_empty err
529+
)
530+
'
531+
done
532+
516533
test_done

0 commit comments

Comments
 (0)