repack-midx: extract `repack_fill_midx_stdin_packs()`

The function `write_midx_included_packs()` manages the lifecycle of writing packs to stdin when running `git multi-pack-index write` as a child process. Extract a standalone `repack_fill_midx_stdin_packs()` helper, which handles `--stdin-packs` argument setup, starting the command, writing pack names to its standard input, and finishing the command. This simplifies `write_midx_included_packs()` and prepares for a subsequent commit where the same helper is called with `cmd->out = -1` to capture the MIDX's checksum from the command's standard output, which is needed when writing MIDX layers with `--no-write-chain-file`. 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 6e38bcc51014e89a430bbd4f708170f5f7795b76
1 file changed +24 -14
repack-midx.c
+24 -14
@@ -292,23 +292,42 @@ static void repack_prepare_midx_command(struct child_process *cmd,
292 strvec_push(&cmd->args, "--bitmap");
293 }
294
295 +static int repack_fill_midx_stdin_packs(struct child_process *cmd,
296 + struct string_list *include)
297 +{
298 + struct string_list_item *item;
299 + FILE *in;
300 + int ret;
301 +
302 + cmd->in = -1;
303 +
304 + strvec_push(&cmd->args, "--stdin-packs");
305 +
306 + ret = start_command(cmd);
307 + if (ret)
308 + return ret;
309 +
310 + in = xfdopen(cmd->in, "w");
311 + for_each_string_list_item(item, include)
312 + fprintf(in, "%s\n", item->string);
313 + fclose(in);
314 +
315 + return finish_command(cmd);
316 +}
317 +
318 int write_midx_included_packs(struct repack_write_midx_opts *opts)
319 {
320 struct child_process cmd = CHILD_PROCESS_INIT;
321 struct string_list include = STRING_LIST_INIT_DUP;
322 struct string_list_item *item;
323 struct packed_git *preferred = pack_geometry_preferred_pack(opts->geometry);
301 - FILE *in;
324 int ret = 0;
325
326 midx_included_packs(&include, opts);
327 if (!include.nr)
328 goto done;
329
308 - cmd.in = -1;
309 -
330 repack_prepare_midx_command(&cmd, opts, "write");
311 - strvec_push(&cmd.args, "--stdin-packs");
331
332 if (preferred)
333 strvec_pushf(&cmd.args, "--preferred-pack=%s",
@@ -350,16 +369,7 @@ int write_midx_included_packs(struct repack_write_midx_opts *opts)
369 strvec_pushf(&cmd.args, "--refs-snapshot=%s",
370 opts->refs_snapshot);
371
353 - ret = start_command(&cmd);
354 - if (ret)
355 - goto done;
356 -
357 - in = xfdopen(cmd.in, "w");
358 - for_each_string_list_item(item, &include)
359 - fprintf(in, "%s\n", item->string);
360 - fclose(in);
361 -
362 - ret = finish_command(&cmd);
372 + ret = repack_fill_midx_stdin_packs(&cmd, &include);
373 done:
374 if (!ret && opts->write_bitmaps)
375 remove_redundant_bitmaps(&include, opts->packdir);