Skip to content

Commit 9ced91c

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 363485a commit 9ced91c

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
@@ -910,6 +910,21 @@ static int write_midx_bitmap(struct write_midx_context *ctx,
910910
return ret;
911911
}
912912

913+
static int fill_pack_from_midx(struct pack_info *info,
914+
struct multi_pack_index *m,
915+
uint32_t pack_int_id)
916+
{
917+
if (prepare_midx_pack(m, pack_int_id))
918+
return error(_("could not load pack %d"), pack_int_id);
919+
920+
fill_pack_info(info,
921+
m->packs[pack_int_id - m->num_packs_in_base],
922+
m->pack_names[pack_int_id - m->num_packs_in_base],
923+
pack_int_id);
924+
925+
return 0;
926+
}
927+
913928
static int fill_packs_from_midx(struct write_midx_context *ctx)
914929
{
915930
struct multi_pack_index *m;
@@ -918,13 +933,13 @@ static int fill_packs_from_midx(struct write_midx_context *ctx)
918933
uint32_t i;
919934

920935
for (i = 0; i < m->num_packs; i++) {
921-
if (prepare_midx_pack(m, m->num_packs_in_base + i))
922-
return error(_("could not load pack"));
923-
924936
ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
925-
fill_pack_info(&ctx->info[ctx->nr++], m->packs[i],
926-
m->pack_names[i],
927-
m->num_packs_in_base + i);
937+
938+
if (fill_pack_from_midx(&ctx->info[ctx->nr], m,
939+
m->num_packs_in_base + i) < 0)
940+
return -1;
941+
942+
ctx->nr++;
928943
}
929944
}
930945
return 0;

0 commit comments

Comments
 (0)