mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
852c530102
commit
1d6f4c6408
43
midx.c
43
midx.c
@ -618,6 +618,31 @@ static void midx_fanout_add_midx_fanout(struct midx_fanout *fanout,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void midx_fanout_add_pack_fanout(struct midx_fanout *fanout,
|
||||||
|
struct pack_info *info,
|
||||||
|
uint32_t cur_pack,
|
||||||
|
int preferred,
|
||||||
|
uint32_t cur_fanout)
|
||||||
|
{
|
||||||
|
struct packed_git *pack = info[cur_pack].p;
|
||||||
|
uint32_t start = 0, end;
|
||||||
|
uint32_t cur_object;
|
||||||
|
|
||||||
|
if (cur_fanout)
|
||||||
|
start = get_pack_fanout(pack, cur_fanout - 1);
|
||||||
|
end = get_pack_fanout(pack, cur_fanout);
|
||||||
|
|
||||||
|
for (cur_object = start; cur_object < end; cur_object++) {
|
||||||
|
midx_fanout_grow(fanout, fanout->nr + 1);
|
||||||
|
fill_pack_entry(cur_pack,
|
||||||
|
info[cur_pack].p,
|
||||||
|
cur_object,
|
||||||
|
&fanout->entries[fanout->nr],
|
||||||
|
preferred);
|
||||||
|
fanout->nr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It is possible to artificially get into a state where there are many
|
* It is possible to artificially get into a state where there are many
|
||||||
* duplicate copies of objects. That can create high memory pressure if
|
* 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,
|
|||||||
cur_fanout);
|
cur_fanout);
|
||||||
|
|
||||||
for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++) {
|
for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++) {
|
||||||
uint32_t start = 0, end;
|
|
||||||
int preferred = cur_pack == preferred_pack;
|
int preferred = cur_pack == preferred_pack;
|
||||||
|
midx_fanout_add_pack_fanout(&fanout,
|
||||||
if (cur_fanout)
|
info, cur_pack,
|
||||||
start = get_pack_fanout(info[cur_pack].p, cur_fanout - 1);
|
preferred, cur_fanout);
|
||||||
end = get_pack_fanout(info[cur_pack].p, cur_fanout);
|
|
||||||
|
|
||||||
for (cur_object = start; cur_object < end; cur_object++) {
|
|
||||||
midx_fanout_grow(&fanout, fanout.nr + 1);
|
|
||||||
fill_pack_entry(cur_pack,
|
|
||||||
info[cur_pack].p,
|
|
||||||
cur_object,
|
|
||||||
&fanout.entries[fanout.nr],
|
|
||||||
preferred);
|
|
||||||
fanout.nr++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
midx_fanout_sort(&fanout);
|
midx_fanout_sort(&fanout);
|
||||||
|
Loading…
Reference in New Issue
Block a user