Skip to content

Commit d222530

Browse files
ttaylorrgitster
authored andcommitted
midx-write.c: extract inner loop from fill_packs_from_midx()
The function fill_packs_from_midx() does relatively little, but ends up in a doubly-nested loop because we're enumerating each pack within each layer of the incremental MIDX chain. Let's de-dent the inner loop of fill_packs_from_midx() by extracting its contents into a separate function, and calling that. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb2a1ce commit d222530

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

midx-write.c

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,38 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r,
938938
return result;
939939
}
940940

941+
static int fill_packs_from_midx_1(struct write_midx_context *ctx,
942+
struct multi_pack_index *m,
943+
uint32_t flags)
944+
{
945+
for (uint32_t i = 0; i < m->num_packs; i++) {
946+
ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
947+
948+
/*
949+
* If generating a reverse index, need to have
950+
* packed_git's loaded to compare their
951+
* mtimes and object count.
952+
*/
953+
if (flags & MIDX_WRITE_REV_INDEX) {
954+
if (prepare_midx_pack(ctx->repo, m,
955+
m->num_packs_in_base + i)) {
956+
error(_("could not load pack"));
957+
return 1;
958+
}
959+
960+
if (open_pack_index(m->packs[i]))
961+
die(_("could not open index for %s"),
962+
m->packs[i]->pack_name);
963+
}
964+
965+
fill_pack_info(&ctx->info[ctx->nr++], m->packs[i],
966+
m->pack_names[i],
967+
m->num_packs_in_base + i);
968+
}
969+
970+
return 0;
971+
}
972+
941973
static int fill_packs_from_midx(struct write_midx_context *ctx,
942974
const char *preferred_pack_name, uint32_t flags)
943975
{
@@ -957,33 +989,11 @@ static int fill_packs_from_midx(struct write_midx_context *ctx,
957989
}
958990

959991
for (m = ctx->m; m; m = m->base_midx) {
960-
uint32_t i;
961-
962-
for (i = 0; i < m->num_packs; i++) {
963-
ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc);
964-
965-
/*
966-
* If generating a reverse index, need to have
967-
* packed_git's loaded to compare their
968-
* mtimes and object count.
969-
*/
970-
if (flags & MIDX_WRITE_REV_INDEX) {
971-
if (prepare_midx_pack(ctx->repo, m,
972-
m->num_packs_in_base + i)) {
973-
error(_("could not load pack"));
974-
return 1;
975-
}
976-
977-
if (open_pack_index(m->packs[i]))
978-
die(_("could not open index for %s"),
979-
m->packs[i]->pack_name);
980-
}
981-
982-
fill_pack_info(&ctx->info[ctx->nr++], m->packs[i],
983-
m->pack_names[i],
984-
m->num_packs_in_base + i);
985-
}
992+
int ret = fill_packs_from_midx_1(ctx, m, flags);
993+
if (ret)
994+
return ret;
986995
}
996+
987997
return 0;
988998
}
989999

0 commit comments

Comments
 (0)