repack-midx: factor out `repack_prepare_midx_command()`

The `write_midx_included_packs()` function assembles and executes a `git multi-pack-index write` command, constructing the argument list inline. Future commits will introduce additional callers that need to construct similar `git multi-pack-index` commands (for both `write` and `compact` subcommands), so extract the common portions of the command setup into a reusable `repack_prepare_midx_command()` helper. The extracted helper sets `git_cmd`, pushes `multi-pack-index` and a subcommand, and handles `--progress`/`--no-progress` and `--bitmap` flags. The remaining arguments that are specific to the `write` subcommand (such as `--stdin-packs`) are left to the caller. No functional changes are included in this patch. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed May 19, 2026 at 11:58 UTC 1505990d72585cbdf35cd596a2167c2a8a4edda1
1 file changed +19 -11
repack-midx.c
+19 -11
@@ -275,6 +275,23 @@ static void remove_redundant_bitmaps(struct string_list *include,
275 strbuf_release(&path);
276 }
277
278 +static void repack_prepare_midx_command(struct child_process *cmd,
279 + struct repack_write_midx_opts *opts,
280 + const char *subcommand)
281 +{
282 + cmd->git_cmd = 1;
283 +
284 + strvec_pushl(&cmd->args, "multi-pack-index", subcommand, NULL);
285 +
286 + if (opts->show_progress)
287 + strvec_push(&cmd->args, "--progress");
288 + else
289 + strvec_push(&cmd->args, "--no-progress");
290 +
291 + if (opts->write_bitmaps)
292 + strvec_push(&cmd->args, "--bitmap");
293 +}
294 +
295 int write_midx_included_packs(struct repack_write_midx_opts *opts)
296 {
297 struct child_process cmd = CHILD_PROCESS_INIT;
@@ -289,18 +306,9 @@ int write_midx_included_packs(struct repack_write_midx_opts *opts)
306 goto done;
307
308 cmd.in = -1;
292 - cmd.git_cmd = 1;
309
294 - strvec_push(&cmd.args, "multi-pack-index");
295 - strvec_pushl(&cmd.args, "write", "--stdin-packs", NULL);
296 -
297 - if (opts->show_progress)
298 - strvec_push(&cmd.args, "--progress");
299 - else
300 - strvec_push(&cmd.args, "--no-progress");
301 -
302 - if (opts->write_bitmaps)
303 - strvec_push(&cmd.args, "--bitmap");
310 + repack_prepare_midx_command(&cmd, opts, "write");
311 + strvec_push(&cmd.args, "--stdin-packs");
312
313 if (preferred)
314 strvec_pushf(&cmd.args, "--preferred-pack=%s",