]> git.ipfire.org Git - thirdparty/git.git/commitdiff
run-command: wean auto_maintenance() functions off the_repository
authorBurak Kaan Karaçay <bkkaracay@gmail.com>
Thu, 12 Mar 2026 14:44:37 +0000 (17:44 +0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Mar 2026 15:30:57 +0000 (08:30 -0700)
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>
builtin/am.c
builtin/commit.c
builtin/fetch.c
builtin/merge.c
builtin/rebase.c
builtin/receive-pack.c
run-command.c
run-command.h

index e0c767e223dbcebf6a357ea945ec8514999e92f5..9d0b51c651924a469a075c4a43578efc5ef96983 100644 (file)
@@ -1937,7 +1937,7 @@ next:
         */
        if (!state->rebasing) {
                am_destroy(state);
-               run_auto_maintenance(state->quiet);
+               run_auto_maintenance(the_repository, state->quiet);
        }
 }
 
index 844bdcc72803b990947de9a2440eb01d69eaf9b3..7b23c1f883e718d4309cb30fb281a381d4168d90 100644 (file)
@@ -1958,7 +1958,7 @@ int cmd_commit(int argc,
        git_test_write_commit_graph_or_die(the_repository->objects->sources);
 
        repo_rerere(the_repository, 0);
-       run_auto_maintenance(quiet);
+       run_auto_maintenance(the_repository, quiet);
        run_commit_hook(use_editor, repo_get_index_file(the_repository),
                        NULL, "post-commit", NULL);
        if (amend && !no_post_rewrite) {
index 8a36cf67b5f140e957c7497aeffd8d6e58bc1389..4795b2a13c30e3c1db8450db9c39fec3ffe69f2c 100644 (file)
@@ -2873,7 +2873,7 @@ int cmd_fetch(int argc,
                        if (opt_val != 0)
                                git_config_push_parameter("maintenance.incremental-repack.auto=-1");
                }
-               run_auto_maintenance(verbosity < 0);
+               run_auto_maintenance(the_repository, verbosity < 0);
        }
 
  cleanup:
index 4e456a381c192dc136282e21d050b7bedc5ff33f..2cbce56f8da9f7027cc95ad98540084b0ee98111 100644 (file)
@@ -506,7 +506,7 @@ static void finish(struct commit *head_commit,
                         * We ignore errors in 'gc --auto', since the
                         * user should see them.
                         */
-                       run_auto_maintenance(verbosity < 0);
+                       run_auto_maintenance(the_repository, verbosity < 0);
                }
        }
        if (new_head && show_diffstat) {
index c487e1090779c2c6ee3a1464662a47178f354817..8c1316db38b48d94b9baf3ed6152a1e04c2c08d6 100644 (file)
@@ -562,7 +562,9 @@ static int finish_rebase(struct rebase_options *opts)
         * We ignore errors in 'git maintenance run --auto', since the
         * user should see them.
         */
-       run_auto_maintenance(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
+       run_auto_maintenance(the_repository,
+                       !(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE)));
+
        if (opts->type == REBASE_MERGE) {
                struct replay_opts replay = REPLAY_OPTS_INIT;
 
index d6225df890d8888c5a34578f4bb1bea57534438f..e34edff406959a9b72d3c2eae30c6c6849c31c49 100644 (file)
@@ -2727,7 +2727,7 @@ int cmd_receive_pack(int argc,
                if (auto_gc) {
                        struct child_process proc = CHILD_PROCESS_INIT;
 
-                       if (prepare_auto_maintenance(1, &proc)) {
+                       if (prepare_auto_maintenance(the_repository, 1, &proc)) {
                                proc.no_stdin = 1;
                                proc.stdout_to_stderr = 1;
                                proc.err = use_sideband ? -1 : 0;
index ed5e8be9761bcb4171e356ec157c467bc4aa553a..38f4c699f81a7a792c039e196d64a10710983a05 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "git-compat-util.h"
@@ -1937,11 +1936,12 @@ void run_processes_parallel(const struct run_process_parallel_opts *opts)
                trace2_region_leave(tr2_category, tr2_label, NULL);
 }
 
-int prepare_auto_maintenance(int quiet, struct child_process *maint)
+int prepare_auto_maintenance(struct repository *r, int quiet,
+                            struct child_process *maint)
 {
        int enabled, auto_detach;
 
-       if (!repo_config_get_bool(the_repository, "maintenance.auto", &enabled) &&
+       if (!repo_config_get_bool(r, "maintenance.auto", &enabled) &&
            !enabled)
                return 0;
 
@@ -1950,12 +1950,12 @@ int prepare_auto_maintenance(int quiet, struct child_process *maint)
         * honoring `gc.autoDetach`. This is somewhat weird, but required to
         * retain behaviour from when we used to run git-gc(1) here.
         */
-       if (repo_config_get_bool(the_repository, "maintenance.autodetach", &auto_detach) &&
-           repo_config_get_bool(the_repository, "gc.autodetach", &auto_detach))
+       if (repo_config_get_bool(r, "maintenance.autodetach", &auto_detach) &&
+           repo_config_get_bool(r, "gc.autodetach", &auto_detach))
                auto_detach = git_env_bool("GIT_TEST_MAINT_AUTO_DETACH", true);
 
        maint->git_cmd = 1;
-       maint->odb_to_close = the_repository->objects;
+       maint->odb_to_close = r->objects;
        strvec_pushl(&maint->args, "maintenance", "run", "--auto", NULL);
        strvec_push(&maint->args, quiet ? "--quiet" : "--no-quiet");
        strvec_push(&maint->args, auto_detach ? "--detach" : "--no-detach");
@@ -1963,10 +1963,10 @@ int prepare_auto_maintenance(int quiet, struct child_process *maint)
        return 1;
 }
 
-int run_auto_maintenance(int quiet)
+int run_auto_maintenance(struct repository *r, int quiet)
 {
        struct child_process maint = CHILD_PROCESS_INIT;
-       if (!prepare_auto_maintenance(quiet, &maint))
+       if (!prepare_auto_maintenance(r, quiet, &maint))
                return 0;
        return run_command(&maint);
 }
index af4c9da279594ab703d2c7f51178e6583933b79d..ad25740fe6c09231f34ba1cddea7ff17e79823b5 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "strvec.h"
 
+struct repository;
+
 /**
  * The run-command API offers a versatile tool to run sub-processes with
  * redirected input and output as well as with a modified environment
@@ -227,12 +229,13 @@ int run_command(struct child_process *);
  * process has been prepared and is ready to run, or 0 in case auto-maintenance
  * should be skipped.
  */
-int prepare_auto_maintenance(int quiet, struct child_process *maint);
+int prepare_auto_maintenance(struct repository *r, int quiet,
+                            struct child_process *maint);
 
 /*
  * Trigger an auto-gc
  */
-int run_auto_maintenance(int quiet);
+int run_auto_maintenance(struct repository *r, int quiet);
 
 /**
  * Execute the given command, sending "in" to its stdin, and capturing its