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>

Burak Kaan Karaçay committed Mar 12, 2026 at 17:44 UTC 9df3be8e2e7e2c9bf200de4bcfbd4e690a57f033
8 files changed +21 -16
builtin/am.c
+1 -1
@@ -1937,7 +1937,7 @@ next:
1937 */
1938 if (!state->rebasing) {
1939 am_destroy(state);
1940 - run_auto_maintenance(state->quiet);
1940 + run_auto_maintenance(the_repository, state->quiet);
1941 }
1942 }
1943
builtin/commit.c
+1 -1
@@ -1958,7 +1958,7 @@ int cmd_commit(int argc,
1958 git_test_write_commit_graph_or_die(the_repository->objects->sources);
1959
1960 repo_rerere(the_repository, 0);
1961 - run_auto_maintenance(quiet);
1961 + run_auto_maintenance(the_repository, quiet);
1962 run_commit_hook(use_editor, repo_get_index_file(the_repository),
1963 NULL, "post-commit", NULL);
1964 if (amend && !no_post_rewrite) {
builtin/fetch.c
+1 -1
@@ -2873,7 +2873,7 @@ int cmd_fetch(int argc,
2873 if (opt_val != 0)
2874 git_config_push_parameter("maintenance.incremental-repack.auto=-1");
2875 }
2876 - run_auto_maintenance(verbosity < 0);
2876 + run_auto_maintenance(the_repository, verbosity < 0);
2877 }
2878
2879 cleanup:
builtin/merge.c
+1 -1
@@ -506,7 +506,7 @@ static void finish(struct commit *head_commit,
506 * We ignore errors in 'gc --auto', since the
507 * user should see them.
508 */
509 - run_auto_maintenance(verbosity < 0);
509 + run_auto_maintenance(the_repository, verbosity < 0);
510 }
511 }
512 if (new_head && show_diffstat) {
builtin/rebase.c
+3 -1
@@ -562,7 +562,9 @@ static int finish_rebase(struct rebase_options *opts)
562 * We ignore errors in 'git maintenance run --auto', since the
563 * user should see them.
564 */
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 +
568 if (opts->type == REBASE_MERGE) {
569 struct replay_opts replay = REPLAY_OPTS_INIT;
570
builtin/receive-pack.c
+1 -1
@@ -2727,7 +2727,7 @@ int cmd_receive_pack(int argc,
2727 if (auto_gc) {
2728 struct child_process proc = CHILD_PROCESS_INIT;
2729
2730 - if (prepare_auto_maintenance(1, &proc)) {
2730 + if (prepare_auto_maintenance(the_repository, 1, &proc)) {
2731 proc.no_stdin = 1;
2732 proc.stdout_to_stderr = 1;
2733 proc.err = use_sideband ? -1 : 0;
run-command.c
+8 -8
@@ -1,4 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
1 #define DISABLE_SIGN_COMPARE_WARNINGS
2
3 #include "git-compat-util.h"
@@ -1937,11 +1936,12 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
1936 trace2_region_leave(tr2_category, tr2_label, NULL);
1937 }
1938
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)
1941 {
1942 int enabled, auto_detach;
1943
1944 - if (!repo_config_get_bool(the_repository, "maintenance.auto", &enabled) &&
1944 + if (!repo_config_get_bool(r, "maintenance.auto", &enabled) &&
1945 !enabled)
1946 return 0;
1947
@@ -1950,12 +1950,12 @@ int prepare_auto_maintenance(int quiet, struct child_process *maint)
1950 * honoring `gc.autoDetach`. This is somewhat weird, but required to
1951 * retain behaviour from when we used to run git-gc(1) here.
1952 */
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))
1955 auto_detach = git_env_bool("GIT_TEST_MAINT_AUTO_DETACH", true);
1956
1957 maint->git_cmd = 1;
1958 - maint->odb_to_close = the_repository->objects;
1958 + maint->odb_to_close = r->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");
@@ -1963,10 +1963,10 @@ int prepare_auto_maintenance(int quiet, struct child_process *maint)
1963 return 1;
1964 }
1965
1966 -int run_auto_maintenance(int quiet)
1966 +int run_auto_maintenance(struct repository *r, int quiet)
1967 {
1968 struct child_process maint = CHILD_PROCESS_INIT;
1969 - if (!prepare_auto_maintenance(quiet, &maint))
1969 + if (!prepare_auto_maintenance(r, quiet, &maint))
1970 return 0;
1971 return run_command(&maint);
1972 }
run-command.h
+5 -2
@@ -5,6 +5,8 @@
5
6 #include "strvec.h"
7
8 +struct repository;
9 +
10 /**
11 * The run-command API offers a versatile tool to run sub-processes with
12 * redirected input and output as well as with a modified environment
@@ -227,12 +229,13 @@ int run_command(struct child_process *);
229 * process has been prepared and is ready to run, or 0 in case auto-maintenance
230 * should be skipped.
231 */
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);
234
235 /*
236 * Trigger an auto-gc
237 */
235 -int run_auto_maintenance(int quiet);
238 +int run_auto_maintenance(struct repository *r, int quiet);
239
240 /**
241 * Execute the given command, sending "in" to its stdin, and capturing its