Skip to content

Commit 9df3be8

Browse files
bkkaracaygitster
authored andcommitted
run-command: wean auto_maintenance() functions off the_repository
The prepare_auto_maintenance() relies on the_repository to read configurations. Since run_auto_maintenance() calls prepare_auto_maintenance(), it also implicitly depends the_repository. Add 'struct repository *' as a parameter to both functions and update all callers to pass the_repository. With no global repository dependencies left in this file, remove the USE_THE_REPOSITORY_VARIABLE macro. Suggested-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Burak Kaan Karaçay <bkkaracay@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 05c324b commit 9df3be8

File tree

8 files changed

+21
-16
lines changed

8 files changed

+21
-16
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/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/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: 8 additions & 8 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"
@@ -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->odb_to_close = the_repository->objects;
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: 5 additions & 2 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
@@ -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)