midx-write.c: extract `fill_pack_from_midx()`

When filling packs from an existing MIDX, `fill_packs_from_midx()` handles preparing a MIDX'd pack, and reading out its pack name from the existing MIDX. MIDX compaction will want to perform an identical operation, though the caller will look quite different than `fill_packs_from_midx()`. To reduce any future code duplication, extract `fill_pack_from_midx()` from `fill_packs_from_midx()` to prepare to call our new helper function in a future change. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Feb 24, 2026 at 14:00 UTC 5f3e7f7279da72b20f99a2bcd26d146f7edaef9d
1 file changed +21 -6
midx-write.c
+21 -6
@@ -913,6 +913,21 @@ cleanup:
913 return ret;
914 }
915
916 +static int fill_pack_from_midx(struct pack_info *info,
917 + struct multi_pack_index *m,
918 + uint32_t pack_int_id)
919 +{
920 + if (prepare_midx_pack(m, pack_int_id))
921 + return error(_("could not load pack %d"), pack_int_id);
922 +
923 + fill_pack_info(info,
924 + m->packs[pack_int_id - m->num_packs_in_base],
925 + m->pack_names[pack_int_id - m->num_packs_in_base],
926 + pack_int_id);
927 +
928 + return 0;
929 +}
930 +
931 static int fill_packs_from_midx(struct write_midx_context *ctx)
932 {
933 struct multi_pack_index *m;
@@ -921,13 +936,13 @@ static int fill_packs_from_midx(struct write_midx_context *ctx)
936 uint32_t i;
937
938 for (i = 0; i < m->num_packs; i++) {
924 - if (prepare_midx_pack(m, m->num_packs_in_base + i))
925 - return error(_("could not load pack"));
926 -
939 ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
928 - fill_pack_info(&ctx->info[ctx->nr++], m->packs[i],
929 - m->pack_names[i],
930 - m->num_packs_in_base + i);
940 +
941 + if (fill_pack_from_midx(&ctx->info[ctx->nr], m,
942 + m->num_packs_in_base + i) < 0)
943 + return -1;
944 +
945 + ctx->nr++;
946 }
947 }
948 return 0;