Skip to content

Commit 1d6f4c6

Browse files
ttaylorrgitster
authored andcommitted
midx.c: extract midx_fanout_add_pack_fanout()
Extract a routine to add all objects whose object ID's first byte is `cur_fanout` from a given pack (identified by its index into the `struct pack_info` array maintained by the MIDX writing routine). Unlike the previous extraction (for `midx_fanout_add_midx_fanout()`), this function will be called twice, once for all new packs, and again for the preferred pack (if it appears in an existing MIDX). The latter change is to resolve the bug described a few patches ago, and will be made in the subsequent commit. Similar to the previous refactoring, this function also enhances the readability of its caller in `get_sorted_entries()`. Its functionality is unchanged in this commit. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 852c530 commit 1d6f4c6

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

midx.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,31 @@ static void midx_fanout_add_midx_fanout(struct midx_fanout *fanout,
618618
}
619619
}
620620

621+
static void midx_fanout_add_pack_fanout(struct midx_fanout *fanout,
622+
struct pack_info *info,
623+
uint32_t cur_pack,
624+
int preferred,
625+
uint32_t cur_fanout)
626+
{
627+
struct packed_git *pack = info[cur_pack].p;
628+
uint32_t start = 0, end;
629+
uint32_t cur_object;
630+
631+
if (cur_fanout)
632+
start = get_pack_fanout(pack, cur_fanout - 1);
633+
end = get_pack_fanout(pack, cur_fanout);
634+
635+
for (cur_object = start; cur_object < end; cur_object++) {
636+
midx_fanout_grow(fanout, fanout->nr + 1);
637+
fill_pack_entry(cur_pack,
638+
info[cur_pack].p,
639+
cur_object,
640+
&fanout->entries[fanout->nr],
641+
preferred);
642+
fanout->nr++;
643+
}
644+
}
645+
621646
/*
622647
* It is possible to artificially get into a state where there are many
623648
* duplicate copies of objects. That can create high memory pressure if
@@ -663,22 +688,10 @@ static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
663688
cur_fanout);
664689

665690
for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++) {
666-
uint32_t start = 0, end;
667691
int preferred = cur_pack == preferred_pack;
668-
669-
if (cur_fanout)
670-
start = get_pack_fanout(info[cur_pack].p, cur_fanout - 1);
671-
end = get_pack_fanout(info[cur_pack].p, cur_fanout);
672-
673-
for (cur_object = start; cur_object < end; cur_object++) {
674-
midx_fanout_grow(&fanout, fanout.nr + 1);
675-
fill_pack_entry(cur_pack,
676-
info[cur_pack].p,
677-
cur_object,
678-
&fanout.entries[fanout.nr],
679-
preferred);
680-
fanout.nr++;
681-
}
692+
midx_fanout_add_pack_fanout(&fanout,
693+
info, cur_pack,
694+
preferred, cur_fanout);
682695
}
683696

684697
midx_fanout_sort(&fanout);

0 commit comments

Comments
 (0)