Skip to content

Commit 477f9c1

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 cad0632 commit 477f9c1

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
@@ -323,6 +323,30 @@ static void midx_fanout_add_pack_fanout(struct midx_fanout *fanout,
323323
}
324324
}
325325

326+
static void midx_fanout_add(struct midx_fanout *fanout,
327+
struct write_midx_context *ctx,
328+
uint32_t start_pack,
329+
uint32_t cur_fanout)
330+
{
331+
uint32_t cur_pack;
332+
333+
if (ctx->m && !ctx->incremental)
334+
midx_fanout_add_midx_fanout(fanout, ctx->m, cur_fanout,
335+
ctx->preferred_pack_idx);
336+
337+
for (cur_pack = start_pack; cur_pack < ctx->nr; cur_pack++) {
338+
int preferred = cur_pack == ctx->preferred_pack_idx;
339+
midx_fanout_add_pack_fanout(fanout, ctx->info, cur_pack,
340+
preferred, cur_fanout);
341+
}
342+
343+
if (ctx->preferred_pack_idx != NO_PREFERRED_PACK &&
344+
ctx->preferred_pack_idx < start_pack)
345+
midx_fanout_add_pack_fanout(fanout, ctx->info,
346+
ctx->preferred_pack_idx, 1,
347+
cur_fanout);
348+
}
349+
326350
/*
327351
* It is possible to artificially get into a state where there are many
328352
* duplicate copies of objects. That can create high memory pressure if
@@ -359,23 +383,7 @@ static void compute_sorted_entries(struct write_midx_context *ctx,
359383
for (cur_fanout = 0; cur_fanout < 256; cur_fanout++) {
360384
fanout.nr = 0;
361385

362-
if (ctx->m && !ctx->incremental)
363-
midx_fanout_add_midx_fanout(&fanout, ctx->m, cur_fanout,
364-
ctx->preferred_pack_idx);
365-
366-
for (cur_pack = start_pack; cur_pack < ctx->nr; cur_pack++) {
367-
int preferred = cur_pack == ctx->preferred_pack_idx;
368-
midx_fanout_add_pack_fanout(&fanout,
369-
ctx->info, cur_pack,
370-
preferred, cur_fanout);
371-
}
372-
373-
if (ctx->preferred_pack_idx != NO_PREFERRED_PACK &&
374-
ctx->preferred_pack_idx < start_pack)
375-
midx_fanout_add_pack_fanout(&fanout, ctx->info,
376-
ctx->preferred_pack_idx, 1,
377-
cur_fanout);
378-
386+
midx_fanout_add(&fanout, ctx, start_pack, cur_fanout);
379387
midx_fanout_sort(&fanout);
380388

381389
/*

0 commit comments

Comments
 (0)