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 <me@xxxxxxxxxxxx> --- midx-write.c | 62 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/midx-write.c b/midx-write.c index 7802a4b694..2afb67d728 100644 --- a/midx-write.c +++ b/midx-write.c @@ -938,6 +938,38 @@ static struct multi_pack_index *lookup_multi_pack_index(struct repository *r, return result; } +static int fill_packs_from_midx_1(struct write_midx_context *ctx, + struct multi_pack_index *m, + uint32_t flags) +{ + for (uint32_t i = 0; i < m->num_packs; i++) { + ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc); + + /* + * If generating a reverse index, need to have + * packed_git's loaded to compare their + * mtimes and object count. + */ + if (flags & MIDX_WRITE_REV_INDEX) { + if (prepare_midx_pack(ctx->repo, m, + m->num_packs_in_base + i)) { + error(_("could not load pack")); + return 1; + } + + if (open_pack_index(m->packs[i])) + die(_("could not open index for %s"), + m->packs[i]->pack_name); + } + + fill_pack_info(&ctx->info[ctx->nr++], m->packs[i], + m->pack_names[i], + m->num_packs_in_base + i); + } + + return 0; +} + static int fill_packs_from_midx(struct write_midx_context *ctx, const char *preferred_pack_name, uint32_t flags) { @@ -957,33 +989,11 @@ static int fill_packs_from_midx(struct write_midx_context *ctx, } for (m = ctx->m; m; m = m->base_midx) { - uint32_t i; - - for (i = 0; i < m->num_packs; i++) { - ALLOC_GROW(ctx->info, ctx->nr + 1, ctx->alloc); - - /* - * If generating a reverse index, need to have - * packed_git's loaded to compare their - * mtimes and object count. - */ - if (flags & MIDX_WRITE_REV_INDEX) { - if (prepare_midx_pack(ctx->repo, m, - m->num_packs_in_base + i)) { - error(_("could not load pack")); - return 1; - } - - if (open_pack_index(m->packs[i])) - die(_("could not open index for %s"), - m->packs[i]->pack_name); - } - - fill_pack_info(&ctx->info[ctx->nr++], m->packs[i], - m->pack_names[i], - m->num_packs_in_base + i); - } + int ret = fill_packs_from_midx_1(ctx, m, flags); + if (ret) + return ret; } + return 0; } -- 2.49.0.641.gb9c9c4c3bd