Skip to content

Commit c5e204a

Browse files
ttaylorrgitster
authored andcommitted
midx-write.c: extract fill_packs_from_midx()
When write_midx_internal() loads an existing MIDX, all packs are copied forward into the new MIDX. Improve the readability of write_midx_internal() by extracting this functionality out into a separate function. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 364c0ff commit c5e204a

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

midx-write.c

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,40 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
882882
return result;
883883
}
884884

885+
static int fill_packs_from_midx(struct write_midx_context *ctx,
886+
const char *preferred_pack_name, uint32_t flags)
887+
{
888+
uint32_t i;
889+
890+
for (i = 0; i < ctx->m->num_packs; i++) {
891+
ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
892+
893+
if (flags & MIDX_WRITE_REV_INDEX || preferred_pack_name) {
894+
/*
895+
* If generating a reverse index, need to have
896+
* packed_git's loaded to compare their
897+
* mtimes and object count.
898+
*
899+
*
900+
* If a preferred pack is specified, need to
901+
* have packed_git's loaded to ensure the chosen
902+
* preferred pack has a non-zero object count.
903+
*/
904+
if (prepare_midx_pack(the_repository, ctx->m, i))
905+
return error(_("could not load pack"));
906+
907+
if (open_pack_index(ctx->m->packs[i]))
908+
die(_("could not open index for %s"),
909+
ctx->m->packs[i]->pack_name);
910+
}
911+
912+
fill_pack_info(&ctx->info[ctx->nr++], ctx->m->packs[i],
913+
ctx->m->pack_names[i], i);
914+
}
915+
916+
return 0;
917+
}
918+
885919
static int write_midx_internal(const char *object_dir,
886920
struct string_list *packs_to_include,
887921
struct string_list *packs_to_drop,
@@ -927,36 +961,10 @@ static int write_midx_internal(const char *object_dir,
927961
ctx.info = NULL;
928962
ALLOC_ARRAY(ctx.info, ctx.alloc);
929963

930-
if (ctx.m) {
931-
for (i = 0; i < ctx.m->num_packs; i++) {
932-
ALLOC_GROW(ctx.info, ctx.nr + 1, ctx.alloc);
933-
934-
if (flags & MIDX_WRITE_REV_INDEX ||
935-
preferred_pack_name) {
936-
/*
937-
* If generating a reverse index, need to have
938-
* packed_git's loaded to compare their
939-
* mtimes and object count.
940-
*
941-
* If a preferred pack is specified,
942-
* need to have packed_git's loaded to
943-
* ensure the chosen preferred pack has
944-
* a non-zero object count.
945-
*/
946-
if (prepare_midx_pack(the_repository, ctx.m, i)) {
947-
error(_("could not load pack"));
948-
result = 1;
949-
goto cleanup;
950-
}
951-
952-
if (open_pack_index(ctx.m->packs[i]))
953-
die(_("could not open index for %s"),
954-
ctx.m->packs[i]->pack_name);
955-
}
956-
957-
fill_pack_info(&ctx.info[ctx.nr++], ctx.m->packs[i],
958-
ctx.m->pack_names[i], i);
959-
}
964+
if (ctx.m && fill_packs_from_midx(&ctx, preferred_pack_name,
965+
flags) < 0) {
966+
result = 1;
967+
goto cleanup;
960968
}
961969

962970
start_pack = ctx.nr;

0 commit comments

Comments
 (0)