Skip to content

Commit 97fd770

Browse files
ttaylorrgitster
authored andcommitted
midx: teach midx_fanout_add_midx_fanout() about incremental MIDXs
The function `midx_fanout_add_midx_fanout()` is used to help construct the fanout table when generating a MIDX by reusing data from an existing MIDX. Prepare this function to work with incremental MIDXs by making a few changes: - The bounds checks need to be adjusted to start object lookups taking into account the number of objects in the previous MIDX layer (i.e., by starting the lookups at position `m->num_objects_in_base` instead of position 0). - Likewise, the bounds checks need to end at `m->num_objects_in_base` objects after `m->num_objects`. - Finally, `midx_fanout_add_midx_fanout()` needs to recur on earlier MIDX layers when dealing with an incremental MIDX chain by calling itself when given a MIDX with a non-NULL `base_midx`. Note that after 0c5a62f (midx-write.c: do not read existing MIDX with `packs_to_include`, 2024-06-11), we do not use this function with an existing MIDX (incremental or not) when generating a MIDX with --stdin-packs, and likewise for incremental MIDXs. But it is still used when adding the fanout table from an incremental MIDX when generating a non-incremental MIDX (without --stdin-packs, of course). Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b31f2aa commit 97fd770

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

midx-write.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static int nth_midxed_pack_midx_entry(struct multi_pack_index *m,
196196
struct pack_midx_entry *e,
197197
uint32_t pos)
198198
{
199-
if (pos >= m->num_objects)
199+
if (pos >= m->num_objects + m->num_objects_in_base)
200200
return 1;
201201

202202
nth_midxed_object_oid(&e->oid, m, pos);
@@ -247,12 +247,16 @@ static void midx_fanout_add_midx_fanout(struct midx_fanout *fanout,
247247
uint32_t cur_fanout,
248248
int preferred_pack)
249249
{
250-
uint32_t start = 0, end;
250+
uint32_t start = m->num_objects_in_base, end;
251251
uint32_t cur_object;
252252

253+
if (m->base_midx)
254+
midx_fanout_add_midx_fanout(fanout, m->base_midx, cur_fanout,
255+
preferred_pack);
256+
253257
if (cur_fanout)
254-
start = ntohl(m->chunk_oid_fanout[cur_fanout - 1]);
255-
end = ntohl(m->chunk_oid_fanout[cur_fanout]);
258+
start += ntohl(m->chunk_oid_fanout[cur_fanout - 1]);
259+
end = m->num_objects_in_base + ntohl(m->chunk_oid_fanout[cur_fanout]);
256260

257261
for (cur_object = start; cur_object < end; cur_object++) {
258262
if ((preferred_pack > -1) &&

0 commit comments

Comments
 (0)