]> git.ipfire.org Git - thirdparty/git.git/commitdiff
midx-write.c: factor fanout layering from `compute_sorted_entries()`
authorTaylor Blau <me@ttaylorr.com>
Sat, 6 Dec 2025 20:31:40 +0000 (15:31 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sat, 6 Dec 2025 22:38:10 +0000 (07:38 +0900)
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>
midx-write.c

index d3644276aad1ae48d7ac73f2641c45cc06b57bc5..7854561359dede426c1f6f69c37ffadbfe1d75e7 100644 (file)
@@ -323,6 +323,30 @@ static void midx_fanout_add_pack_fanout(struct midx_fanout *fanout,
        }
 }
 
+static void midx_fanout_add(struct midx_fanout *fanout,
+                           struct write_midx_context *ctx,
+                           uint32_t start_pack,
+                           uint32_t cur_fanout)
+{
+       uint32_t cur_pack;
+
+       if (ctx->m && !ctx->incremental)
+               midx_fanout_add_midx_fanout(fanout, ctx->m, cur_fanout,
+                                           ctx->preferred_pack_idx);
+
+       for (cur_pack = start_pack; cur_pack < ctx->nr; cur_pack++) {
+               int preferred = cur_pack == ctx->preferred_pack_idx;
+               midx_fanout_add_pack_fanout(fanout, ctx->info, cur_pack,
+                                           preferred, cur_fanout);
+       }
+
+       if (ctx->preferred_pack_idx != NO_PREFERRED_PACK &&
+           ctx->preferred_pack_idx < start_pack)
+               midx_fanout_add_pack_fanout(fanout, ctx->info,
+                                           ctx->preferred_pack_idx, 1,
+                                           cur_fanout);
+}
+
 /*
  * It is possible to artificially get into a state where there are many
  * 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,
        for (cur_fanout = 0; cur_fanout < 256; cur_fanout++) {
                fanout.nr = 0;
 
-               if (ctx->m && !ctx->incremental)
-                       midx_fanout_add_midx_fanout(&fanout, ctx->m, cur_fanout,
-                                                   ctx->preferred_pack_idx);
-
-               for (cur_pack = start_pack; cur_pack < ctx->nr; cur_pack++) {
-                       int preferred = cur_pack == ctx->preferred_pack_idx;
-                       midx_fanout_add_pack_fanout(&fanout,
-                                                   ctx->info, cur_pack,
-                                                   preferred, cur_fanout);
-               }
-
-               if (ctx->preferred_pack_idx != NO_PREFERRED_PACK &&
-                   ctx->preferred_pack_idx < start_pack)
-                       midx_fanout_add_pack_fanout(&fanout, ctx->info,
-                                                   ctx->preferred_pack_idx, 1,
-                                                   cur_fanout);
-
+               midx_fanout_add(&fanout, ctx, start_pack, cur_fanout);
                midx_fanout_sort(&fanout);
 
                /*