]> git.ipfire.org Git - thirdparty/git.git/commitdiff
run-command: wean start_command() off the_repository
authorBurak Kaan Karaçay <bkkaracay@gmail.com>
Thu, 12 Mar 2026 14:44:36 +0000 (17:44 +0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Mar 2026 15:30:57 +0000 (08:30 -0700)
The start_command() relies on the_repository due to the
close_object_store flag in 'struct child_process'. When this flag is
set, start_command() closes the object store associated with
the_repository before spawning a child process.

To eliminate this dependency, replace the 'close_object_store' with the
new 'struct object_database *odb_to_close' field. This allows callers to
specify the object store that needs to be closed.

Suggested-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Burak Kaan Karaçay <bkkaracay@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c
builtin/pull.c
run-command.c
run-command.h

index fb329c2cffab807128e497227433c0ace0be06c7..5d8d358f7a511db16455243bbebb01f3b279b7d7 100644 (file)
@@ -1030,7 +1030,7 @@ int cmd_gc(int argc,
                struct child_process repack_cmd = CHILD_PROCESS_INIT;
 
                repack_cmd.git_cmd = 1;
-               repack_cmd.close_object_store = 1;
+               repack_cmd.odb_to_close = the_repository->objects;
                strvec_pushv(&repack_cmd.args, repack_args.v);
                if (run_command(&repack_cmd))
                        die(FAILED_RUN, repack_args.v[0]);
@@ -1199,7 +1199,8 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
 {
        struct child_process child = CHILD_PROCESS_INIT;
 
-       child.git_cmd = child.close_object_store = 1;
+       child.git_cmd = 1;
+       child.odb_to_close = the_repository->objects;
        strvec_pushl(&child.args, "commit-graph", "write",
                     "--split", "--reachable", NULL);
 
@@ -1268,7 +1269,8 @@ static int maintenance_task_gc_background(struct maintenance_run_opts *opts,
 {
        struct child_process child = CHILD_PROCESS_INIT;
 
-       child.git_cmd = child.close_object_store = 1;
+       child.git_cmd = 1;
+       child.odb_to_close = the_repository->objects;
        strvec_push(&child.args, "gc");
 
        if (opts->auto_flag)
@@ -1484,7 +1486,8 @@ static int multi_pack_index_expire(struct maintenance_run_opts *opts)
 {
        struct child_process child = CHILD_PROCESS_INIT;
 
-       child.git_cmd = child.close_object_store = 1;
+       child.git_cmd = 1;
+       child.odb_to_close = the_repository->objects;
        strvec_pushl(&child.args, "multi-pack-index", "expire", NULL);
 
        if (opts->quiet)
@@ -1542,7 +1545,8 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
 {
        struct child_process child = CHILD_PROCESS_INIT;
 
-       child.git_cmd = child.close_object_store = 1;
+       child.git_cmd = 1;
+       child.odb_to_close = the_repository->objects;
        strvec_pushl(&child.args, "multi-pack-index", "repack", NULL);
 
        if (opts->quiet)
index 6ad420ce6f9b41e9de96e04abd134735ee914550..7e67fdce97fd1d8543d6412e36c6c3ce41df9430 100644 (file)
@@ -454,7 +454,7 @@ static int run_fetch(const char *repo, const char **refspecs)
        } else if (*refspecs)
                BUG("refspecs without repo?");
        cmd.git_cmd = 1;
-       cmd.close_object_store = 1;
+       cmd.odb_to_close = the_repository->objects;
        return run_command(&cmd);
 }
 
index b27064ef5788a51adc050b26af970be88fd5591e..ed5e8be9761bcb4171e356ec157c467bc4aa553a 100644 (file)
@@ -742,8 +742,8 @@ fail_pipe:
 
        fflush(NULL);
 
-       if (cmd->close_object_store)
-               odb_close(the_repository->objects);
+       if (cmd->odb_to_close)
+               odb_close(cmd->odb_to_close);
 
 #ifndef GIT_WINDOWS_NATIVE
 {
@@ -1955,7 +1955,7 @@ int prepare_auto_maintenance(int quiet, struct child_process *maint)
                auto_detach = git_env_bool("GIT_TEST_MAINT_AUTO_DETACH", true);
 
        maint->git_cmd = 1;
-       maint->close_object_store = 1;
+       maint->odb_to_close = the_repository->objects;
        strvec_pushl(&maint->args, "maintenance", "run", "--auto", NULL);
        strvec_push(&maint->args, quiet ? "--quiet" : "--no-quiet");
        strvec_push(&maint->args, auto_detach ? "--detach" : "--no-detach");
index e1ca965b5b19882ef1c16b9407eec13ff3e926fe..af4c9da279594ab703d2c7f51178e6583933b79d 100644 (file)
@@ -136,7 +136,7 @@ struct child_process {
         * want to repack because that would delete `.pack` files (and on
         * Windows, you cannot delete files that are still in use).
         */
-       unsigned close_object_store:1;
+       struct object_database *odb_to_close;
 
        unsigned stdout_to_stderr:1;
        unsigned clean_on_exit:1;