Skip to content

Commit 5f3e7f7

Browse files
ttaylorrgitster
authored andcommitted
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>
1 parent 4f85432 commit 5f3e7f7

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

midx-write.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,21 @@ static int write_midx_bitmap(struct write_midx_context *ctx,
913913
return ret;
914914
}
915915

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+
916931
static int fill_packs_from_midx(struct write_midx_context *ctx)
917932
{
918933
struct multi_pack_index *m;
@@ -921,13 +936,13 @@ static int fill_packs_from_midx(struct write_midx_context *ctx)
921936
uint32_t i;
922937

923938
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-
927939
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++;
931946
}
932947
}
933948
return 0;

0 commit comments

Comments
 (0)