]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: stop using `the_repository` in `setup_git_directory_gently()`
authorPatrick Steinhardt <ps@pks.im>
Tue, 19 May 2026 09:52:16 +0000 (11:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2026 10:36:24 +0000 (19:36 +0900)
Stop using `the_repository` in `setup_git_directory_gently()` and
instead accept the repository as a parameter. The injection of
`the_repository` is thus bumped one level higher, where callers now pass
it in explicitly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
13 files changed:
builtin/check-ref-format.c
builtin/diff.c
builtin/hash-object.c
builtin/help.c
builtin/stripspace.c
git.c
http-fetch.c
imap-send.c
remote-curl.c
setup.c
setup.h
t/helper/test-path-utils.c
t/helper/test-subprocess.c

index 5d80afeec05e3d75e5dad203e70c403bd1b10072..e42b0444ead269478d8953910669e20e71abcacf 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * GIT - The information manager from hell
  */
+
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
 #include "refs.h"
 #include "setup.h"
@@ -41,7 +44,7 @@ static int check_ref_format_branch(const char *arg)
        const char *name;
        int nongit;
 
-       setup_git_directory_gently(&nongit);
+       setup_git_directory_gently(the_repository, &nongit);
        if (check_branch_ref(&sb, arg) ||
            !skip_prefix(sb.buf, "refs/heads/", &name))
                die("'%s' is not a valid branch name", arg);
index 1ede873ac1895df335e8cae4f6ee707520aea39c..4b46e394cecb8dc4679a000d73c659394724dcbf 100644 (file)
@@ -455,7 +455,7 @@ int cmd_diff(int argc,
                        break;
        }
 
-       prefix = setup_git_directory_gently(&nongit);
+       prefix = setup_git_directory_gently(the_repository, &nongit);
 
        if (!nongit) {
                prepare_repo_settings(the_repository);
index 5d900a6b8c953ecc6451aaeaa67fd223ddd5e3c4..d7905bedc2dfd395c7d36c9c50609d37ca598e73 100644 (file)
@@ -102,7 +102,7 @@ int cmd_hash_object(int argc,
        if (flags & INDEX_WRITE_OBJECT)
                prefix = setup_git_directory();
        else
-               prefix = setup_git_directory_gently(&nongit);
+               prefix = setup_git_directory_gently(the_repository, &nongit);
 
        if (nongit && !the_hash_algo)
                repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
index c0aece4da39c81e14e3854674b41beac1b53dcf2..a140339999debef94036b841740bafe25980f885 100644 (file)
@@ -740,7 +740,7 @@ int cmd_help(int argc,
                return 0;
        }
 
-       setup_git_directory_gently(&nongit);
+       setup_git_directory_gently(the_repository, &nongit);
        repo_config(the_repository, git_help_config, NULL);
 
        if (parsed_help_format != HELP_FORMAT_NONE)
index 4a566cbc5de672fd25c96494287c001908a6a984..18705f1a5b11506e6b5efa0a6dcf20e8649a6072 100644 (file)
@@ -54,7 +54,7 @@ int cmd_stripspace(int argc,
                usage_with_options(stripspace_usage, options);
 
        if (mode == STRIP_COMMENTS || mode == COMMENT_LINES) {
-               setup_git_directory_gently(&nongit);
+               setup_git_directory_gently(the_repository, &nongit);
                repo_config(the_repository, git_default_config, NULL);
        }
 
diff --git a/git.c b/git.c
index eaede42c4e864491cf4ad393e240e0296c2f7c85..2cc018fc5cc1127a6c4aa2e163c904c435deef19 100644 (file)
--- a/git.c
+++ b/git.c
@@ -84,7 +84,7 @@ static int list_cmds(const char *spec)
        * Set up the repository so we can pick up any repo-level config (like
        * completion.commands).
        */
-       setup_git_directory_gently(&nongit);
+       setup_git_directory_gently(the_repository, &nongit);
 
        while (*spec) {
                const char *sep = strchrnul(spec, ',');
@@ -386,7 +386,7 @@ static int handle_alias(struct strvec *args, struct string_list *expanded_aliase
                        int nongit_ok;
 
                        /* Aliases expect GIT_PREFIX, GIT_DIR etc to be set */
-                       setup_git_directory_gently(&nongit_ok);
+                       setup_git_directory_gently(the_repository, &nongit_ok);
 
                        commit_pager_choice();
 
@@ -480,7 +480,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
                prefix = setup_git_directory();
                no_repo = 0;
        } else if (run_setup & RUN_SETUP_GENTLY) {
-               prefix = setup_git_directory_gently(&no_repo);
+               prefix = setup_git_directory_gently(the_repository, &no_repo);
        } else {
                prefix = NULL;
        }
index 1922e23fcd3f979d6def1676cda6b23fd1a1c93d..f9b6ecb0616fe0a5634e75ac581702b57619e1c5 100644 (file)
@@ -109,7 +109,7 @@ int cmd_main(int argc, const char **argv)
        struct strvec index_pack_args = STRVEC_INIT;
        int ret;
 
-       setup_git_directory_gently(&nongit);
+       setup_git_directory_gently(the_repository, &nongit);
 
        while (arg < argc && argv[arg][0] == '-') {
                const char *p;
index af02c6a689495e8c64faa78c3772ceb6e7fae5cc..cfd6a5120c50e42293a581752eb3119489880a96 100644 (file)
@@ -1799,7 +1799,7 @@ int cmd_main(int argc, const char **argv)
        int nongit_ok;
        int ret;
 
-       setup_git_directory_gently(&nongit_ok);
+       setup_git_directory_gently(the_repository, &nongit_ok);
        repo_config(the_repository, git_imap_config, &server);
 
        argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0);
index aba60d571282d39287cb8434de72af8c9a8a7a05..a84fc860ec0dd4f4170e3e9e819ff5ac12e28350 100644 (file)
@@ -1557,7 +1557,7 @@ int cmd_main(int argc, const char **argv)
        int nongit;
        int ret = 1;
 
-       setup_git_directory_gently(&nongit);
+       setup_git_directory_gently(the_repository, &nongit);
        if (argc < 2) {
                error(_("remote-curl: usage: git remote-curl <remote> [<url>]"));
                goto cleanup;
@@ -1605,7 +1605,7 @@ int cmd_main(int argc, const char **argv)
                        break;
                if (starts_with(buf.buf, "fetch ")) {
                        if (nongit) {
-                               setup_git_directory_gently(&nongit);
+                               setup_git_directory_gently(the_repository, &nongit);
                                if (nongit)
                                        die(_("remote-curl: fetch attempted without a local repo"));
                        }
diff --git a/setup.c b/setup.c
index 8965f8ccaf20b18e9accf8d894531cc9321564f0..c12c6cbda2fa990d6c7265c548dab066d0390aa4 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -1862,7 +1862,7 @@ void set_git_work_tree(struct repository *repo, const char *new_work_tree)
        repo_set_worktree(repo, new_work_tree);
 }
 
-const char *setup_git_directory_gently(int *nongit_ok)
+const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
 {
        static struct strbuf cwd = STRBUF_INIT;
        struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT, report = STRBUF_INIT;
@@ -1877,7 +1877,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
         * configuration (including the per-repo config file that we
         * ignored previously).
         */
-       repo_config_clear(the_repository);
+       repo_config_clear(repo);
 
        /*
         * Let's assume that we are in a git repository.
@@ -1893,18 +1893,18 @@ const char *setup_git_directory_gently(int *nongit_ok)
 
        switch (setup_git_directory_gently_1(&dir, &gitdir, &report, 1)) {
        case GIT_DIR_EXPLICIT:
-               prefix = setup_explicit_git_dir(the_repository, gitdir.buf, &cwd, &repo_fmt, nongit_ok);
+               prefix = setup_explicit_git_dir(repo, gitdir.buf, &cwd, &repo_fmt, nongit_ok);
                break;
        case GIT_DIR_DISCOVERED:
                if (dir.len < cwd.len && chdir(dir.buf))
                        die(_("cannot change to '%s'"), dir.buf);
-               prefix = setup_discovered_git_dir(the_repository, gitdir.buf, &cwd, dir.len,
+               prefix = setup_discovered_git_dir(repo, gitdir.buf, &cwd, dir.len,
                                                  &repo_fmt, nongit_ok);
                break;
        case GIT_DIR_BARE:
                if (dir.len < cwd.len && chdir(dir.buf))
                        die(_("cannot change to '%s'"), dir.buf);
-               prefix = setup_bare_git_dir(the_repository, &cwd, dir.len, &repo_fmt, nongit_ok);
+               prefix = setup_bare_git_dir(repo, &cwd, dir.len, &repo_fmt, nongit_ok);
                break;
        case GIT_DIR_HIT_CEILING:
                if (!nongit_ok)
@@ -1984,30 +1984,30 @@ const char *setup_git_directory_gently(int *nongit_ok)
            startup_info->have_repository ||
            /* GIT_DIR_EXPLICIT */
            getenv(GIT_DIR_ENVIRONMENT)) {
-               if (!the_repository->gitdir) {
+               if (!repo->gitdir) {
                        const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
                        if (!gitdir)
                                gitdir = DEFAULT_GIT_DIR_ENVIRONMENT;
-                       setup_git_env(the_repository, gitdir);
+                       setup_git_env(repo, gitdir);
                }
                if (startup_info->have_repository) {
-                       repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
-                       repo_set_compat_hash_algo(the_repository,
+                       repo_set_hash_algo(repo, repo_fmt.hash_algo);
+                       repo_set_compat_hash_algo(repo,
                                                  repo_fmt.compat_hash_algo);
-                       repo_set_ref_storage_format(the_repository,
+                       repo_set_ref_storage_format(repo,
                                                    repo_fmt.ref_storage_format,
                                                    repo_fmt.ref_storage_payload);
-                       the_repository->repository_format_worktree_config =
+                       repo->repository_format_worktree_config =
                                repo_fmt.worktree_config;
-                       the_repository->repository_format_relative_worktrees =
+                       repo->repository_format_relative_worktrees =
                                repo_fmt.relative_worktrees;
-                       the_repository->repository_format_submodule_path_cfg =
+                       repo->repository_format_submodule_path_cfg =
                                repo_fmt.submodule_path_cfg;
                        /* take ownership of repo_fmt.partial_clone */
-                       the_repository->repository_format_partial_clone =
+                       repo->repository_format_partial_clone =
                                repo_fmt.partial_clone;
                        repo_fmt.partial_clone = NULL;
-                       the_repository->repository_format_precious_objects =
+                       repo->repository_format_precious_objects =
                                repo_fmt.precious_objects;
                }
        }
@@ -2040,13 +2040,13 @@ const char *setup_git_directory_gently(int *nongit_ok)
                format = ref_storage_format_by_name(backend);
                if (format == REF_STORAGE_FORMAT_UNKNOWN)
                        die(_("unknown ref storage format: '%s'"), backend);
-               repo_set_ref_storage_format(the_repository, format, payload);
+               repo_set_ref_storage_format(repo, format, payload);
 
                free(backend);
                free(payload);
        }
 
-       setup_original_cwd(the_repository);
+       setup_original_cwd(repo);
 
        strbuf_release(&dir);
        strbuf_release(&gitdir);
@@ -2138,7 +2138,7 @@ void check_repository_format(struct repository_format *fmt)
  */
 const char *setup_git_directory(void)
 {
-       return setup_git_directory_gently(NULL);
+       return setup_git_directory_gently(the_repository, NULL);
 }
 
 const char *resolve_gitdir_gently(const char *suspect, int *return_error_code)
diff --git a/setup.h b/setup.h
index 1a37089fa0aa54b1b77fddcbf82afb5630a6bf1b..18092fbf1630f585b78bd3cd977e8d3230e01869 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -136,7 +136,7 @@ enum {
  */
 const char *enter_repo(struct repository *repo, const char *path, unsigned flags);
 
-const char *setup_git_directory_gently(int *);
+const char *setup_git_directory_gently(struct repository *repo, int *);
 const char *setup_git_directory(void);
 char *prefix_path(struct repository *repo, const char *prefix, int len, const char *path);
 char *prefix_path_gently(struct repository *repo, const char *prefix, int len, int *remaining, const char *path);
index 163fdeefb0f7d9ca760f440922fc2daffb3a8e09..15eb44485cda3d51e615f3a83aadccc11716e173 100644 (file)
@@ -377,7 +377,7 @@ int cmd__path_utils(int argc, const char **argv)
                const char *prefix = argv[2];
                int prefix_len = strlen(prefix);
                int nongit_ok;
-               setup_git_directory_gently(&nongit_ok);
+               setup_git_directory_gently(the_repository, &nongit_ok);
                while (argc > 3) {
                        char *pfx = prefix_path(the_repository, prefix, prefix_len, argv[3]);
 
index 8a070e47cddb519b2f07f8e7743de55bdf3f514b..a8194d24b31db2b39d6c8ac98a4ec6296dc18151 100644 (file)
@@ -9,7 +9,7 @@ int cmd__subprocess(int argc, const char **argv)
        struct child_process cp = CHILD_PROCESS_INIT;
        int nogit = 0;
 
-       setup_git_directory_gently(&nogit);
+       setup_git_directory_gently(the_repository, &nogit);
        if (nogit)
                die("No git repo found");
        if (argc > 1 && !strcmp(argv[1], "--setup-work-tree")) {