Skip to content

Commit 9aea84c

Browse files
ttaylorrgitster
authored andcommitted
midx-write.c: factor fanout layering from compute_sorted_entries()
When computing the set of objects to appear in a MIDX, we use compute_sorted_entries(), which handles objects from various existing sources one fanout layer at a time. The process for computing this set is slightly different during MIDX compaction, so factor out the existing functionality into its own routine to prevent `compute_sorted_entries()` from becoming too difficult to read. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 93c67df commit 9aea84c

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

midx-write.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,30 @@ static void midx_fanout_add_pack_fanout(struct midx_fanout *fanout,
328328
}
329329
}
330330

331+
static void midx_fanout_add(struct midx_fanout *fanout,
332+
struct write_midx_context *ctx,
333+
uint32_t start_pack,
334+
uint32_t cur_fanout)
335+
{
336+
uint32_t cur_pack;
337+
338+
if (ctx->m && !ctx->incremental)
339+
midx_fanout_add_midx_fanout(fanout, ctx->m, cur_fanout,
340+
ctx->preferred_pack_idx);
341+
342+
for (cur_pack = start_pack; cur_pack < ctx->nr; cur_pack++) {
343+
int preferred = cur_pack == ctx->preferred_pack_idx;
344+
midx_fanout_add_pack_fanout(fanout, ctx->info, cur_pack,
345+
preferred, cur_fanout);
346+
}
347+
348+
if (ctx->preferred_pack_idx != NO_PREFERRED_PACK &&
349+
ctx->preferred_pack_idx < start_pack)
350+
midx_fanout_add_pack_fanout(fanout, ctx->info,
351+
ctx->preferred_pack_idx, 1,
352+
cur_fanout);
353+
}
354+
331355
/*
332356
* It is possible to artificially get into a state where there are many
333357
* duplicate copies of objects. That can create high memory pressure if
@@ -364,23 +388,7 @@ static void compute_sorted_entries(struct write_midx_context *ctx,
364388
for (cur_fanout = 0; cur_fanout < 256; cur_fanout++) {
365389
fanout.nr = 0;
366390

367-
if (ctx->m && !ctx->incremental)
368-
midx_fanout_add_midx_fanout(&fanout, ctx->m, cur_fanout,
369-
ctx->preferred_pack_idx);
370-
371-
for (cur_pack = start_pack; cur_pack < ctx->nr; cur_pack++) {
372-
int preferred = cur_pack == ctx->preferred_pack_idx;
373-
midx_fanout_add_pack_fanout(&fanout,
374-
ctx->info, cur_pack,
375-
preferred, cur_fanout);
376-
}
377-
378-
if (ctx->preferred_pack_idx != NO_PREFERRED_PACK &&
379-
ctx->preferred_pack_idx < start_pack)
380-
midx_fanout_add_pack_fanout(&fanout, ctx->info,
381-
ctx->preferred_pack_idx, 1,
382-
cur_fanout);
383-
391+
midx_fanout_add(&fanout, ctx, start_pack, cur_fanout);
384392
midx_fanout_sort(&fanout);
385393

386394
/*

0 commit comments

Comments
 (0)