Skip to content

Commit 1820bd8

Browse files
ttaylorrgitster
authored andcommitted
midx: teach prepare_midx_pack() about incremental MIDXs
The function `prepare_midx_pack()` is part of the midx.h API and loads the pack identified by the MIDX-local 'pack_int_id'. This patch prepares that function to be aware of an incremental MIDX world. To do this, introduce the second of the two general purpose helpers mentioned in the previous commit. This commit introduces `midx_for_pack()`, which is the pack-specific analog of `midx_for_object()`, and works in the same fashion. Like `midx_for_object()`, this function chases down the '->base_midx' field until it finds the MIDX layer within the chain that contains the given pack. Use this function within `prepare_midx_pack()` so that the `pack_int_id` it expects is now relative to the entire MIDX chain, and that it prepares the given pack in the appropriate MIDX. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1941982 commit 1820bd8

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

midx.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,32 @@ static uint32_t midx_for_object(struct multi_pack_index **_m, uint32_t pos)
259259
return pos - m->num_objects_in_base;
260260
}
261261

262-
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id)
262+
static uint32_t midx_for_pack(struct multi_pack_index **_m,
263+
uint32_t pack_int_id)
264+
{
265+
struct multi_pack_index *m = *_m;
266+
while (m && pack_int_id < m->num_packs_in_base)
267+
m = m->base_midx;
268+
269+
if (!m)
270+
BUG("NULL multi-pack-index for pack ID: %"PRIu32, pack_int_id);
271+
272+
if (pack_int_id >= m->num_packs + m->num_packs_in_base)
273+
die(_("bad pack-int-id: %u (%u total packs)"),
274+
pack_int_id, m->num_packs + m->num_packs_in_base);
275+
276+
*_m = m;
277+
278+
return pack_int_id - m->num_packs_in_base;
279+
}
280+
281+
int prepare_midx_pack(struct repository *r, struct multi_pack_index *m,
282+
uint32_t pack_int_id)
263283
{
264284
struct strbuf pack_name = STRBUF_INIT;
265285
struct packed_git *p;
266286

267-
if (pack_int_id >= m->num_packs)
268-
die(_("bad pack-int-id: %u (%u total packs)"),
269-
pack_int_id, m->num_packs);
287+
pack_int_id = midx_for_pack(&m, pack_int_id);
270288

271289
if (m->packs[pack_int_id])
272290
return 0;

0 commit comments

Comments
 (0)