run-command: wean start_command() off the_repository

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>

Burak Kaan Karaçay committed Mar 12, 2026 at 17:44 UTC 05c324b92fe723674cbf9ae1b0b1675821b6c275
4 files changed +14 -10
builtin/gc.c
+9 -5
@@ -1030,7 +1030,7 @@ int cmd_gc(int argc,
1030 struct child_process repack_cmd = CHILD_PROCESS_INIT;
1031
1032 repack_cmd.git_cmd = 1;
1033 - repack_cmd.close_object_store = 1;
1033 + repack_cmd.odb_to_close = the_repository->objects;
1034 strvec_pushv(&repack_cmd.args, repack_args.v);
1035 if (run_command(&repack_cmd))
1036 die(FAILED_RUN, repack_args.v[0]);
@@ -1199,7 +1199,8 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
1199 {
1200 struct child_process child = CHILD_PROCESS_INIT;
1201
1202 - child.git_cmd = child.close_object_store = 1;
1202 + child.git_cmd = 1;
1203 + child.odb_to_close = the_repository->objects;
1204 strvec_pushl(&child.args, "commit-graph", "write",
1205 "--split", "--reachable", NULL);
1206
@@ -1268,7 +1269,8 @@ static int maintenance_task_gc_background(struct maintenance_run_opts *opts,
1269 {
1270 struct child_process child = CHILD_PROCESS_INIT;
1271
1271 - child.git_cmd = child.close_object_store = 1;
1272 + child.git_cmd = 1;
1273 + child.odb_to_close = the_repository->objects;
1274 strvec_push(&child.args, "gc");
1275
1276 if (opts->auto_flag)
@@ -1484,7 +1486,8 @@ static int multi_pack_index_expire(struct maintenance_run_opts *opts)
1486 {
1487 struct child_process child = CHILD_PROCESS_INIT;
1488
1487 - child.git_cmd = child.close_object_store = 1;
1489 + child.git_cmd = 1;
1490 + child.odb_to_close = the_repository->objects;
1491 strvec_pushl(&child.args, "multi-pack-index", "expire", NULL);
1492
1493 if (opts->quiet)
@@ -1542,7 +1545,8 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
1545 {
1546 struct child_process child = CHILD_PROCESS_INIT;
1547
1545 - child.git_cmd = child.close_object_store = 1;
1548 + child.git_cmd = 1;
1549 + child.odb_to_close = the_repository->objects;
1550 strvec_pushl(&child.args, "multi-pack-index", "repack", NULL);
1551
1552 if (opts->quiet)
builtin/pull.c
+1 -1
@@ -454,7 +454,7 @@ static int run_fetch(const char *repo, const char **refspecs)
454 } else if (*refspecs)
455 BUG("refspecs without repo?");
456 cmd.git_cmd = 1;
457 - cmd.close_object_store = 1;
457 + cmd.odb_to_close = the_repository->objects;
458 return run_command(&cmd);
459 }
460
run-command.c
+3 -3
@@ -742,8 +742,8 @@ fail_pipe:
742
743 fflush(NULL);
744
745 - if (cmd->close_object_store)
746 - odb_close(the_repository->objects);
745 + if (cmd->odb_to_close)
746 + odb_close(cmd->odb_to_close);
747
748 #ifndef GIT_WINDOWS_NATIVE
749 {
@@ -1955,7 +1955,7 @@ int prepare_auto_maintenance(int quiet, struct child_process *maint)
1955 auto_detach = git_env_bool("GIT_TEST_MAINT_AUTO_DETACH", true);
1956
1957 maint->git_cmd = 1;
1958 - maint->close_object_store = 1;
1958 + maint->odb_to_close = the_repository->objects;
1959 strvec_pushl(&maint->args, "maintenance", "run", "--auto", NULL);
1960 strvec_push(&maint->args, quiet ? "--quiet" : "--no-quiet");
1961 strvec_push(&maint->args, auto_detach ? "--detach" : "--no-detach");
run-command.h
+1 -1
@@ -136,7 +136,7 @@ struct child_process {
136 * want to repack because that would delete `.pack` files (and on
137 * Windows, you cannot delete files that are still in use).
138 */
139 - unsigned close_object_store:1;
139 + struct object_database *odb_to_close;
140
141 unsigned stdout_to_stderr:1;
142 unsigned clean_on_exit:1;