pack-bitmap.c: support bitmap pack-reuse with incremental MIDXs

In a similar fashion as previous commits in the first phase of incremental MIDXs, enumerate not just the packs in the current incremental MIDX layer, but previous ones as well. Likewise, in reuse_partial_packfile_from_bitmap(), when reusing only a single pack from a MIDX, use the oldest layer's preferred pack as it is likely to contain the largest number of reusable sections. Signed-off-by: Taylor Blau <me@ttaylorr.com> Acked-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Mar 20, 2025 at 13:56 UTC 3886c7262170e2b7a2ed574ddefda2664695230a
1 file changed +8 -3
pack-bitmap.c
+8 -3
@@ -2335,7 +2335,8 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
2335 multi_pack_reuse = 0;
2336
2337 if (multi_pack_reuse) {
2338 - for (i = 0; i < bitmap_git->midx->num_packs; i++) {
2338 + struct multi_pack_index *m = bitmap_git->midx;
2339 + for (i = 0; i < m->num_packs + m->num_packs_in_base; i++) {
2340 struct bitmapped_pack pack;
2341 if (nth_bitmapped_pack(r, bitmap_git->midx, &pack, i) < 0) {
2342 warning(_("unable to load pack: '%s', disabling pack-reuse"),
@@ -2361,14 +2362,18 @@ void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
2362 uint32_t pack_int_id;
2363
2364 if (bitmap_is_midx(bitmap_git)) {
2365 + struct multi_pack_index *m = bitmap_git->midx;
2366 uint32_t preferred_pack_pos;
2367
2366 - if (midx_preferred_pack(bitmap_git->midx, &preferred_pack_pos) < 0) {
2368 + while (m->base_midx)
2369 + m = m->base_midx;
2370 +
2371 + if (midx_preferred_pack(m, &preferred_pack_pos) < 0) {
2372 warning(_("unable to compute preferred pack, disabling pack-reuse"));
2373 return;
2374 }
2375
2371 - pack = bitmap_git->midx->packs[preferred_pack_pos];
2376 + pack = nth_midxed_pack(m, preferred_pack_pos);
2377 pack_int_id = preferred_pack_pos;
2378 } else {
2379 pack = bitmap_git->pack;