Skip to content

Commit 05c324b

Browse files
bkkaracaygitster
authored andcommitted
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>
1 parent 7f19e4e commit 05c324b

4 files changed

Lines changed: 14 additions & 10 deletions

File tree

builtin/gc.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ int cmd_gc(int argc,
10301030
struct child_process repack_cmd = CHILD_PROCESS_INIT;
10311031

10321032
repack_cmd.git_cmd = 1;
1033-
repack_cmd.close_object_store = 1;
1033+
repack_cmd.odb_to_close = the_repository->objects;
10341034
strvec_pushv(&repack_cmd.args, repack_args.v);
10351035
if (run_command(&repack_cmd))
10361036
die(FAILED_RUN, repack_args.v[0]);
@@ -1199,7 +1199,8 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
11991199
{
12001200
struct child_process child = CHILD_PROCESS_INIT;
12011201

1202-
child.git_cmd = child.close_object_store = 1;
1202+
child.git_cmd = 1;
1203+
child.odb_to_close = the_repository->objects;
12031204
strvec_pushl(&child.args, "commit-graph", "write",
12041205
"--split", "--reachable", NULL);
12051206

@@ -1268,7 +1269,8 @@ static int maintenance_task_gc_background(struct maintenance_run_opts *opts,
12681269
{
12691270
struct child_process child = CHILD_PROCESS_INIT;
12701271

1271-
child.git_cmd = child.close_object_store = 1;
1272+
child.git_cmd = 1;
1273+
child.odb_to_close = the_repository->objects;
12721274
strvec_push(&child.args, "gc");
12731275

12741276
if (opts->auto_flag)
@@ -1484,7 +1486,8 @@ static int multi_pack_index_expire(struct maintenance_run_opts *opts)
14841486
{
14851487
struct child_process child = CHILD_PROCESS_INIT;
14861488

1487-
child.git_cmd = child.close_object_store = 1;
1489+
child.git_cmd = 1;
1490+
child.odb_to_close = the_repository->objects;
14881491
strvec_pushl(&child.args, "multi-pack-index", "expire", NULL);
14891492

14901493
if (opts->quiet)
@@ -1542,7 +1545,8 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
15421545
{
15431546
struct child_process child = CHILD_PROCESS_INIT;
15441547

1545-
child.git_cmd = child.close_object_store = 1;
1548+
child.git_cmd = 1;
1549+
child.odb_to_close = the_repository->objects;
15461550
strvec_pushl(&child.args, "multi-pack-index", "repack", NULL);
15471551

15481552
if (opts->quiet)

builtin/pull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ static int run_fetch(const char *repo, const char **refspecs)
454454
} else if (*refspecs)
455455
BUG("refspecs without repo?");
456456
cmd.git_cmd = 1;
457-
cmd.close_object_store = 1;
457+
cmd.odb_to_close = the_repository->objects;
458458
return run_command(&cmd);
459459
}
460460

run-command.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ int start_command(struct child_process *cmd)
742742

743743
fflush(NULL);
744744

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);
747747

748748
#ifndef GIT_WINDOWS_NATIVE
749749
{
@@ -1955,7 +1955,7 @@ int prepare_auto_maintenance(int quiet, struct child_process *maint)
19551955
auto_detach = git_env_bool("GIT_TEST_MAINT_AUTO_DETACH", true);
19561956

19571957
maint->git_cmd = 1;
1958-
maint->close_object_store = 1;
1958+
maint->odb_to_close = the_repository->objects;
19591959
strvec_pushl(&maint->args, "maintenance", "run", "--auto", NULL);
19601960
strvec_push(&maint->args, quiet ? "--quiet" : "--no-quiet");
19611961
strvec_push(&maint->args, auto_detach ? "--detach" : "--no-detach");

run-command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct child_process {
136136
* want to repack because that would delete `.pack` files (and on
137137
* Windows, you cannot delete files that are still in use).
138138
*/
139-
unsigned close_object_store:1;
139+
struct object_database *odb_to_close;
140140

141141
unsigned stdout_to_stderr:1;
142142
unsigned clean_on_exit:1;

0 commit comments

Comments
 (0)