When enumerating packs within fill_packs_from_midx(), we open the pack's index iff we are either writing a reverse index, have a preferred pack (by name) or both. Let's simplify this into a single case by setting the MIDX_WRITE_REV_INDEX flag bit when we have a preferred_pack_name. This is a little bit of a shortcut to reduce the line length in the loop below. But it sets us up nicely to extract the inner loop of this function out into its own function, where we will no longer have to pass the preferred_pack_name. Signed-off-by: Taylor Blau <me@xxxxxxxxxxxx> --- midx-write.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/midx-write.c b/midx-write.c index e4a3830d45..7802a4b694 100644 --- a/midx-write.c +++ b/midx-write.c @@ -943,6 +943,19 @@ static int fill_packs_from_midx(struct write_midx_context *ctx, { struct multi_pack_index *m; + if (preferred_pack_name) { + /* + * If a preferred pack is specified, need to have + * packed_git's loaded to ensure the chosen preferred + * pack has a non-zero object count. + * + * Trick ourselves into thinking that we're writing a + * reverse index in this case in order to open up the + * pack index file. + */ + flags |= MIDX_WRITE_REV_INDEX; + } + for (m = ctx->m; m; m = m->base_midx) { uint32_t i; @@ -953,13 +966,8 @@ static int fill_packs_from_midx(struct write_midx_context *ctx, * If generating a reverse index, need to have * packed_git's loaded to compare their * mtimes and object count. - * - * If a preferred pack is specified, need to - * have packed_git's loaded to ensure the chosen - * preferred pack has a non-zero object count. */ - if (flags & MIDX_WRITE_REV_INDEX || - preferred_pack_name) { + if (flags & MIDX_WRITE_REV_INDEX) { if (prepare_midx_pack(ctx->repo, m, m->num_packs_in_base + i)) { error(_("could not load pack")); -- 2.49.0.641.gb9c9c4c3bd