Skip to content

Commit a7a079c

Browse files
committed
Merge branch 'bk/run-command-wo-the-repository'
The run_command() API lost its implicit dependencyon the singleton `the_repository` instance. * bk/run-command-wo-the-repository: run-command: wean auto_maintenance() functions off the_repository run-command: wean start_command() off the_repository
2 parents 2ca397f + 9df3be8 commit a7a079c

File tree

10 files changed

+34
-25
lines changed

10 files changed

+34
-25
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@ static void am_run(struct am_state *state, int resume)
19371937
*/
19381938
if (!state->rebasing) {
19391939
am_destroy(state);
1940-
run_auto_maintenance(state->quiet);
1940+
run_auto_maintenance(the_repository, state->quiet);
19411941
}
19421942
}
19431943

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ int cmd_commit(int argc,
19581958
git_test_write_commit_graph_or_die(the_repository->objects->sources);
19591959

19601960
repo_rerere(the_repository, 0);
1961-
run_auto_maintenance(quiet);
1961+
run_auto_maintenance(the_repository, quiet);
19621962
run_commit_hook(use_editor, repo_get_index_file(the_repository),
19631963
NULL, "post-commit", NULL);
19641964
if (amend && !no_post_rewrite) {

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2873,7 +2873,7 @@ int cmd_fetch(int argc,
28732873
if (opt_val != 0)
28742874
git_config_push_parameter("maintenance.incremental-repack.auto=-1");
28752875
}
2876-
run_auto_maintenance(verbosity < 0);
2876+
run_auto_maintenance(the_repository, verbosity < 0);
28772877
}
28782878

28792879
cleanup:

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/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static void finish(struct commit *head_commit,
506506
* We ignore errors in 'gc --auto', since the
507507
* user should see them.
508508
*/
509-
run_auto_maintenance(verbosity < 0);
509+
run_auto_maintenance(the_repository, verbosity < 0);
510510
}
511511
}
512512
if (new_head && show_diffstat) {

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

builtin/rebase.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,9 @@ static int finish_rebase(struct rebase_options *opts)
562562
* We ignore errors in 'git maintenance run --auto', since the
563563
* user should see them.
564564
*/
565-
run_auto_maintenance(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
565+
run_auto_maintenance(the_repository,
566+
!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
567+
566568
if (opts->type == REBASE_MERGE) {
567569
struct replay_opts replay = REPLAY_OPTS_INIT;
568570

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2727,7 +2727,7 @@ int cmd_receive_pack(int argc,
27272727
if (auto_gc) {
27282728
struct child_process proc = CHILD_PROCESS_INIT;
27292729

2730-
if (prepare_auto_maintenance(1, &proc)) {
2730+
if (prepare_auto_maintenance(the_repository, 1, &proc)) {
27312731
proc.no_stdin = 1;
27322732
proc.stdout_to_stderr = 1;
27332733
proc.err = use_sideband ? -1 : 0;

run-command.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "git-compat-util.h"
@@ -742,8 +741,8 @@ int start_command(struct child_process *cmd)
742741

743742
fflush(NULL);
744743

745-
if (cmd->close_object_store)
746-
odb_close(the_repository->objects);
744+
if (cmd->odb_to_close)
745+
odb_close(cmd->odb_to_close);
747746

748747
#ifndef GIT_WINDOWS_NATIVE
749748
{
@@ -1937,11 +1936,12 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
19371936
trace2_region_leave(tr2_category, tr2_label, NULL);
19381937
}
19391938

1940-
int prepare_auto_maintenance(int quiet, struct child_process *maint)
1939+
int prepare_auto_maintenance(struct repository *r, int quiet,
1940+
struct child_process *maint)
19411941
{
19421942
int enabled, auto_detach;
19431943

1944-
if (!repo_config_get_bool(the_repository, "maintenance.auto", &enabled) &&
1944+
if (!repo_config_get_bool(r, "maintenance.auto", &enabled) &&
19451945
!enabled)
19461946
return 0;
19471947

@@ -1950,23 +1950,23 @@ int prepare_auto_maintenance(int quiet, struct child_process *maint)
19501950
* honoring `gc.autoDetach`. This is somewhat weird, but required to
19511951
* retain behaviour from when we used to run git-gc(1) here.
19521952
*/
1953-
if (repo_config_get_bool(the_repository, "maintenance.autodetach", &auto_detach) &&
1954-
repo_config_get_bool(the_repository, "gc.autodetach", &auto_detach))
1953+
if (repo_config_get_bool(r, "maintenance.autodetach", &auto_detach) &&
1954+
repo_config_get_bool(r, "gc.autodetach", &auto_detach))
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 = r->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");
19621962

19631963
return 1;
19641964
}
19651965

1966-
int run_auto_maintenance(int quiet)
1966+
int run_auto_maintenance(struct repository *r, int quiet)
19671967
{
19681968
struct child_process maint = CHILD_PROCESS_INIT;
1969-
if (!prepare_auto_maintenance(quiet, &maint))
1969+
if (!prepare_auto_maintenance(r, quiet, &maint))
19701970
return 0;
19711971
return run_command(&maint);
19721972
}

run-command.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "strvec.h"
77

8+
struct repository;
9+
810
/**
911
* The run-command API offers a versatile tool to run sub-processes with
1012
* redirected input and output as well as with a modified environment
@@ -136,7 +138,7 @@ struct child_process {
136138
* want to repack because that would delete `.pack` files (and on
137139
* Windows, you cannot delete files that are still in use).
138140
*/
139-
unsigned close_object_store:1;
141+
struct object_database *odb_to_close;
140142

141143
unsigned stdout_to_stderr:1;
142144
unsigned clean_on_exit:1;
@@ -227,12 +229,13 @@ int run_command(struct child_process *);
227229
* process has been prepared and is ready to run, or 0 in case auto-maintenance
228230
* should be skipped.
229231
*/
230-
int prepare_auto_maintenance(int quiet, struct child_process *maint);
232+
int prepare_auto_maintenance(struct repository *r, int quiet,
233+
struct child_process *maint);
231234

232235
/*
233236
* Trigger an auto-gc
234237
*/
235-
int run_auto_maintenance(int quiet);
238+
int run_auto_maintenance(struct repository *r, int quiet);
236239

237240
/**
238241
* Execute the given command, sending "in" to its stdin, and capturing its

0 commit comments

Comments
 (0)