summaryrefslogtreecommitdiff
path: root/midx.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2022-08-22 15:50:43 -0400
committerJunio C Hamano <gitster@pobox.com>2022-08-22 13:04:22 -0700
commit1d6f4c64084f31bd1be558ae72f25e7600c39f4d (patch)
tree838d82b36c1dddc95403bbcba2d8d0d87e6d2bc1 /midx.c
parent852c530102c5ca5b69ae863acaa1acb50cbba861 (diff)
downloadgit-1d6f4c64084f31bd1be558ae72f25e7600c39f4d.tar.gz
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>
Diffstat (limited to 'midx.c')
-rw-r--r--midx.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/midx.c b/midx.c
index 17bdceed25..b2ef4ece64 100644
--- a/midx.c
+++ b/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
* 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);
for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++) {
- uint32_t start = 0, end;
int preferred = cur_pack == preferred_pack;
-
- if (cur_fanout)
- start = get_pack_fanout(info[cur_pack].p, cur_fanout - 1);
- 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_add_pack_fanout(&fanout,
+ info, cur_pack,
+ preferred, cur_fanout);
}
midx_fanout_sort(&fanout);