]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack-midx: extract `repack_fill_midx_stdin_packs()`
authorTaylor Blau <me@ttaylorr.com>
Tue, 19 May 2026 15:58:07 +0000 (11:58 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 May 2026 02:31:14 +0000 (11:31 +0900)
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>
repack-midx.c

index 5634dc186d0cadce761cf3b7c940a1c1e070e443..3fe83715da420f386addafa498a39db455efd25d 100644 (file)
@@ -292,23 +292,42 @@ static void repack_prepare_midx_command(struct child_process *cmd,
                strvec_push(&cmd->args, "--bitmap");
 }
 
+static int repack_fill_midx_stdin_packs(struct child_process *cmd,
+                                       struct string_list *include)
+{
+       struct string_list_item *item;
+       FILE *in;
+       int ret;
+
+       cmd->in = -1;
+
+       strvec_push(&cmd->args, "--stdin-packs");
+
+       ret = start_command(cmd);
+       if (ret)
+               return ret;
+
+       in = xfdopen(cmd->in, "w");
+       for_each_string_list_item(item, include)
+               fprintf(in, "%s\n", item->string);
+       fclose(in);
+
+       return finish_command(cmd);
+}
+
 int write_midx_included_packs(struct repack_write_midx_opts *opts)
 {
        struct child_process cmd = CHILD_PROCESS_INIT;
        struct string_list include = STRING_LIST_INIT_DUP;
        struct string_list_item *item;
        struct packed_git *preferred = pack_geometry_preferred_pack(opts->geometry);
-       FILE *in;
        int ret = 0;
 
        midx_included_packs(&include, opts);
        if (!include.nr)
                goto done;
 
-       cmd.in = -1;
-
        repack_prepare_midx_command(&cmd, opts, "write");
-       strvec_push(&cmd.args, "--stdin-packs");
 
        if (preferred)
                strvec_pushf(&cmd.args, "--preferred-pack=%s",
@@ -350,16 +369,7 @@ int write_midx_included_packs(struct repack_write_midx_opts *opts)
                strvec_pushf(&cmd.args, "--refs-snapshot=%s",
                             opts->refs_snapshot);
 
-       ret = start_command(&cmd);
-       if (ret)
-               goto done;
-
-       in = xfdopen(cmd.in, "w");
-       for_each_string_list_item(item, &include)
-               fprintf(in, "%s\n", item->string);
-       fclose(in);
-
-       ret = finish_command(&cmd);
+       ret = repack_fill_midx_stdin_packs(&cmd, &include);
 done:
        if (!ret && opts->write_bitmaps)
                remove_redundant_bitmaps(&include, opts->packdir);