]> git.ipfire.org Git - thirdparty/git.git/commitdiff
setup: stop using `the_repository` in `setup_git_directory()`
authorPatrick Steinhardt <ps@pks.im>
Tue, 19 May 2026 09:52:17 +0000 (11:52 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 May 2026 10:36:25 +0000 (19:36 +0900)
Stop using `the_repository` in `setup_git_directory()` 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>
40 files changed:
archive.c
builtin/grep.c
builtin/hash-object.c
builtin/merge-file.c
builtin/rev-parse.c
git.c
http-push.c
scalar.c
setup.c
setup.h
t/helper/test-advise.c
t/helper/test-bitmap.c
t/helper/test-bloom.c
t/helper/test-cache-tree.c
t/helper/test-config.c
t/helper/test-dump-cache-tree.c
t/helper/test-dump-fsmonitor.c
t/helper/test-dump-split-index.c
t/helper/test-dump-untracked-cache.c
t/helper/test-find-pack.c
t/helper/test-fsmonitor-client.c
t/helper/test-lazy-init-name-hash.c
t/helper/test-match-trees.c
t/helper/test-pack-deltas.c
t/helper/test-pack-mtimes.c
t/helper/test-partial-clone.c
t/helper/test-path-walk.c
t/helper/test-reach.c
t/helper/test-read-cache.c
t/helper/test-read-graph.c
t/helper/test-read-midx.c
t/helper/test-ref-store.c
t/helper/test-revision-walking.c
t/helper/test-scrap-cache-tree.c
t/helper/test-serve-v2.c
t/helper/test-submodule-config.c
t/helper/test-submodule-nested-repo-config.c
t/helper/test-submodule.c
t/helper/test-userdiff.c
t/helper/test-write-cache.c

index fcd474c682ffe5d7ba5fc5ea9abf466f4f7015d3..51229107a57495b7b2bae34f53efa79c84f9c317 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -786,7 +786,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
                 * die ourselves; but its error message will be more specific
                 * than what we could write here.
                 */
-               setup_git_directory();
+               setup_git_directory(the_repository);
        }
 
        parse_treeish_arg(argv, &args, remote);
index 679f8b567a15782efb0f9377f81d29d37bab97cf..560133feb8878324c2aeea941de5ead3151301bb 100644 (file)
@@ -1064,7 +1064,7 @@ int cmd_grep(int argc,
                        use_index = 0;
                else
                        /* die the same way as if we did it at the beginning */
-                       setup_git_directory();
+                       setup_git_directory(the_repository);
        }
        /* Ignore --recurse-submodules if --no-index is given or implied */
        if (!use_index)
index d7905bedc2dfd395c7d36c9c50609d37ca598e73..f306b0643f4a04c35db281cc50a2c00c9fcbc8a8 100644 (file)
@@ -100,7 +100,7 @@ int cmd_hash_object(int argc,
                             hash_object_usage, 0);
 
        if (flags & INDEX_WRITE_OBJECT)
-               prefix = setup_git_directory();
+               prefix = setup_git_directory(the_repository);
        else
                prefix = setup_git_directory_gently(the_repository, &nongit);
 
index 59a97922086a582ccf0cb97bc06ce06b29b8f2e7..8fa576523927e828d5ce167fd5ef17b92d661df3 100644 (file)
@@ -110,7 +110,7 @@ int cmd_merge_file(int argc,
 
        if (!repo && object_id)
                /* emit the correct "not a git repo" error in this case */
-               setup_git_directory();
+               setup_git_directory(the_repository);
 
        for (i = 0; i < 3; i++) {
                char *fname;
index 8fdb75413d33a6ac139845b1100cd281f903f178..0a01ff7a75393822b5790ad473c6fdceda94d3c6 100644 (file)
@@ -739,7 +739,7 @@ int cmd_rev_parse(int argc,
 
        /* No options; just report on whether we're in a git repo or not. */
        if (argc == 1) {
-               setup_git_directory();
+               setup_git_directory(the_repository);
                repo_config(the_repository, git_default_config, NULL);
                return 0;
        }
@@ -774,7 +774,7 @@ int cmd_rev_parse(int argc,
 
                /* The rest of the options require a git repository. */
                if (!did_repo_setup) {
-                       prefix = setup_git_directory();
+                       prefix = setup_git_directory(the_repository);
                        repo_config(the_repository, git_default_config, NULL);
                        did_repo_setup = 1;
 
diff --git a/git.c b/git.c
index 2cc018fc5cc1127a6c4aa2e163c904c435deef19..42cd5f5b3c5f4da20811c38ca8c95589c4719c6f 100644 (file)
--- a/git.c
+++ b/git.c
@@ -477,7 +477,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
                run_setup = RUN_SETUP_GENTLY;
 
        if (run_setup & RUN_SETUP) {
-               prefix = setup_git_directory();
+               prefix = setup_git_directory(the_repository);
                no_repo = 0;
        } else if (run_setup & RUN_SETUP_GENTLY) {
                prefix = setup_git_directory_gently(the_repository, &no_repo);
index d143fe28455623b9dfec23f98a232d62a34ea9a5..520d6c3b6ade1f3570db853979936ff4a82c5a8c 100644 (file)
@@ -1788,7 +1788,7 @@ int cmd_main(int argc, const char **argv)
        if (delete_branch && rs.nr != 1)
                die("You must specify only one branch name when deleting a remote branch");
 
-       gitdir = setup_git_directory();
+       gitdir = setup_git_directory(the_repository);
 
        memset(remote_dir_exists, -1, 256);
 
index 4efb6ac36d888e0ac6de0eb604cfde9d7b7b5996..a80d8ee3ff54a734e9c017b52a00aaf363c135bc 100644 (file)
--- a/scalar.c
+++ b/scalar.c
@@ -58,7 +58,7 @@ static void setup_enlistment_directory(int argc, const char **argv,
        }
        strbuf_setlen(&path, len);
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (!the_repository->worktree)
                die(_("Scalar enlistments require a worktree"));
@@ -514,7 +514,7 @@ static int cmd_clone(int argc, const char **argv)
                goto cleanup;
        }
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        /* common-main already logs `argv` */
        trace2_def_repo(the_repository);
diff --git a/setup.c b/setup.c
index c12c6cbda2fa990d6c7265c548dab066d0390aa4..5dc27caf156b24fe035179baf31531bb18795b49 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -2136,9 +2136,9 @@ void check_repository_format(struct repository_format *fmt)
  * directory is not a strict subdirectory of the work tree root. The
  * prefix always ends with a '/' character.
  */
-const char *setup_git_directory(void)
+const char *setup_git_directory(struct repository *repo)
 {
-       return setup_git_directory_gently(the_repository, NULL);
+       return setup_git_directory_gently(repo, NULL);
 }
 
 const char *resolve_gitdir_gently(const char *suspect, int *return_error_code)
diff --git a/setup.h b/setup.h
index 18092fbf1630f585b78bd3cd977e8d3230e01869..b779661ce7df479bf77f4a104a597a7c5d52e33b 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -137,7 +137,7 @@ enum {
 const char *enter_repo(struct repository *repo, const char *path, unsigned flags);
 
 const char *setup_git_directory_gently(struct repository *repo, int *);
-const char *setup_git_directory(void);
+const char *setup_git_directory(struct repository *repo);
 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 81ed93a05c9ac7bec8ac1c4665c2d2b1e0991458..8f9db2693ed87a52e3dc51f6467363555c732a10 100644 (file)
@@ -11,7 +11,7 @@ int cmd__advise_if_enabled(int argc, const char **argv)
        if (argc != 2)
                die("usage: %s <advice>", argv[0]);
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
        repo_config(the_repository, git_default_config, NULL);
 
        /*
index 16a01669e4149aaa9123f7f8c91f5b196d30cf70..d9b9a83b8f059629694f0b487a982ae3e2e899ec 100644 (file)
@@ -37,7 +37,7 @@ static int bitmap_dump_pseudo_merge_objects(uint32_t n)
 
 int cmd__bitmap(int argc, const char **argv)
 {
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (argc == 2 && !strcmp(argv[1], "list-commits"))
                return bitmap_list_commits();
index 3283544bd33db6538db6b425995aeaa84d2477f7..0c65befbf00f7d5656fea6b2223d8d6d8c67b4df 100644 (file)
@@ -52,7 +52,7 @@ static const char *const bloom_usage = "\n"
 
 int cmd__bloom(int argc, const char **argv)
 {
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (argc < 2)
                usage(bloom_usage);
index ff61d0ca7e2fe31cdebba06aa4b4473f6e6a9f70..d42e2600921029245f38b337bbbd7ccc59ad9521 100644 (file)
@@ -33,7 +33,7 @@ int cmd__cache_tree(int argc, const char **argv)
                OPT_END()
        };
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        argc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0);
 
index 9f8cca7c48cfe3162fc9b4b403ac91f895bc08fd..cfb3f4b111939cae08dc42a985c148e6d4968949 100644 (file)
@@ -102,7 +102,7 @@ int cmd__config(int argc, const char **argv)
                return 0;
        }
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        git_configset_init(&cs);
 
index 3f0c7d0ed07ec99a4e19573d9871e3acdd3da463..ccb41a423975f84ac6f92238c4494cf8dbfb6eb3 100644 (file)
@@ -66,7 +66,7 @@ int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)
        struct cache_tree *another = cache_tree();
        int ret;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
        if (repo_read_index(the_repository) < 0)
                die("unable to read index file");
        istate = *the_repository->index;
index efd017ca357e0b27b5bd5d07a62f1fd5d1d7d843..c991cbbb8a542c980f25274a38ce3a383590adc2 100644 (file)
@@ -9,7 +9,7 @@ int cmd__dump_fsmonitor(int ac UNUSED, const char **av UNUSED)
 {
        struct index_state *istate = the_repository->index;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
        if (do_read_index(istate, the_repository->index_file, 0) < 0)
                die("unable to read index file");
        if (!istate->fsmonitor_last_update) {
index f855a3862c97bb3af7a2a3a83c6a5a033b4a3dea..aae0a40a74bcbc1043dfc6ec0ef7ccc0e12a07c3 100644 (file)
@@ -17,7 +17,7 @@ int cmd__dump_split_index(int ac UNUSED, const char **av)
 {
        struct split_index *si;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        do_read_index(the_repository->index, av[1], 1);
        printf("own %s\n", oid_to_hex(&the_repository->index->oid));
index 01a109496bee7872d098ba3ac64c9e7e07404da7..24308bd371b6be3b48687d82fbd242a110c28615 100644 (file)
@@ -54,7 +54,7 @@ int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)
        xsetenv("GIT_CONFIG_KEY_0", "core.untrackedCache", 1);
        xsetenv("GIT_CONFIG_VALUE_0", "keep", 1);
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
        if (repo_read_index(the_repository) < 0)
                die("unable to read index file");
        uc = the_repository->index->untracked;
index fc4b8a77b3007a1f28d89fce94f579b4a6f45f9c..28d5b1fe094345bce864a11538829cf501695564 100644 (file)
@@ -25,7 +25,7 @@ int cmd__find_pack(int argc, const char **argv)
        struct object_id oid;
        struct packed_git *p;
        int count = -1, actual_count = 0;
-       const char *prefix = setup_git_directory();
+       const char *prefix = setup_git_directory(the_repository);
 
        struct option options[] = {
                OPT_INTEGER('c', "check-count", &count, "expected number of packs"),
index 02bfe92e8d55b76b83337474bb0b8d4d82b1fa2e..dc1dff23fb8ed58c43416fd3efc2630cf27fccd3 100644 (file)
@@ -210,7 +210,7 @@ int cmd__fsmonitor_client(int argc, const char **argv)
 
        subcmd = argv[0];
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (!strcmp(subcmd, "query"))
                return !!do_send_query(token);
index 40f5df4412adf1a3c35372de7f7cc64006a58037..e542985c943452687bfcfc23613061c8069221cd 100644 (file)
@@ -211,7 +211,7 @@ int cmd__lazy_init_name_hash(int argc, const char **argv)
        const char *prefix;
        uint64_t avg_single, avg_multi;
 
-       prefix = setup_git_directory();
+       prefix = setup_git_directory(the_repository);
 
        argc = parse_options(argc, argv, prefix, options, usage, 0);
 
index 2ed064b9716ac8e19411d36eac0c386c3f0c2952..006ce5278e23a09bcd7e0bbd6ff8fd12be673efe 100644 (file)
@@ -13,7 +13,7 @@ int cmd__match_trees(int ac UNUSED, const char **av)
        struct object_id hash1, hash2, shifted;
        struct tree *one, *two;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (repo_get_oid(the_repository, av[1], &hash1))
                die("cannot parse %s as an object name", av[1]);
index 4981401eaa6664981445e212a423775fe7cd0256..c493b75e02a99a59bf1444787a844275193772d3 100644 (file)
@@ -95,7 +95,7 @@ int cmd__pack_deltas(int argc, const char **argv)
        if (argc || num_objects < 0)
                usage_with_options(usage_str, options);
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        f = hashfd(the_repository->hash_algo, 1, "<stdout>");
        write_pack_header(f, num_objects);
index 7a8ee1de24ba83c1593960868a1b4dfdc57c24fa..b77405679992993916adc3fd05d7fb3dc95992db 100644 (file)
@@ -32,7 +32,7 @@ int cmd__pack_mtimes(int argc, const char **argv)
        struct strbuf buf = STRBUF_INIT;
        struct packed_git *p;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (argc != 2)
                usage(pack_mtimes_usage);
index d84880074930b268911b77314a79d536c5d19bf8..a7aab426d0194afca120c92e7365ff0b53985a8e 100644 (file)
@@ -1,3 +1,5 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "test-tool.h"
 #include "hex.h"
 #include "repository.h"
@@ -32,7 +34,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
 
 int cmd__partial_clone(int argc, const char **argv)
 {
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (argc < 4)
                die("too few arguments");
index fe63002c2be27d28ab3b0180978b97f407480cf7..69676b15a53f730bb7c1005011cd3c64ad3479c4 100644 (file)
@@ -89,7 +89,7 @@ int cmd__path_walk(int argc, const char **argv)
                OPT_END(),
        };
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
        revs.repo = the_repository;
 
        argc = parse_options(argc, argv, NULL,
index 3131b54a871c1bd61bdd99fbd84a3d3178fe8bc0..5d86a96c17e4e5be3581581e07496c71e7e914c6 100644 (file)
@@ -39,7 +39,7 @@ int cmd__reach(int ac, const char **av)
        struct strbuf buf = STRBUF_INIT;
        struct repository *r = the_repository;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (ac < 2)
                exit(1);
index 9ae71cefb302c9d5b77b96cfe06723a27c3361d7..6b08ba8f078d000e8bd5bb0a2c637085216eea15 100644 (file)
@@ -19,7 +19,7 @@ int cmd__read_cache(int argc, const char **argv)
 
        if (argc == 2)
                cnt = strtol(argv[1], NULL, 0);
-       setup_git_directory();
+       setup_git_directory(the_repository);
        repo_config(the_repository, git_default_config, NULL);
 
        for (i = 0; i < cnt; i++) {
index 6a5f64e473f2b6d97ba30e76bc2422d125c39ed2..9f07b9c25a66e3c7bc20f780d8cb8edd483c131e 100644 (file)
@@ -76,7 +76,7 @@ int cmd__read_graph(int argc, const char **argv)
        struct odb_source *source;
        int ret = 0;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
        source = the_repository->objects->sources;
 
        prepare_repo_settings(the_repository);
index 388d29e2b53db34c565a903ff4565d01d395819a..790000fb26c2701fbacb4a7db70f9b7ca6c5487f 100644 (file)
@@ -14,7 +14,7 @@
 static struct multi_pack_index *setup_midx(const char *object_dir)
 {
        struct odb_source *source;
-       setup_git_directory();
+       setup_git_directory(the_repository);
        source = odb_find_source(the_repository->objects, object_dir);
        if (!source)
                source = odb_add_to_alternates_memory(the_repository->objects,
index 74edf2029a28fcb081d522a74a30127f73f2a74e..3866d0aca49bc2ba6be5f0f5d55f25feed3e7d95 100644 (file)
@@ -340,7 +340,7 @@ int cmd__ref_store(int argc UNUSED, const char **argv)
        const char *func;
        struct command *cmd;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        argv = get_store(argv + 1, &refs);
 
index 071f5bd1e21974ba2104a76305a5156ee2c2961f..70051eeaf848e7efbda5a723beeb3a422c5d1fcd 100644 (file)
@@ -56,7 +56,7 @@ int cmd__revision_walking(int argc, const char **argv)
        if (argc < 2)
                return 1;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (!strcmp(argv[1], "run-twice")) {
                printf("1st\n");
index 64fff6e9e3ce87454d39a139dd6b5b5e4c353e8f..7b5ce501d9eec075e2ddef9a6ac8aa297436961e 100644 (file)
@@ -12,7 +12,7 @@ int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED)
 {
        struct lock_file index_lock = LOCK_INIT;
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
        repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
        if (repo_read_index(the_repository) < 0)
                die("unable to read index file");
index 63a200b8d46f68bfd69f63f844977cc8e382bb32..27f3ed89478fdefbea16e4a8ed8493e9d0ade874 100644 (file)
@@ -23,7 +23,7 @@ int cmd__serve_v2(int argc, const char **argv)
                         N_("exit immediately after advertising capabilities")),
                OPT_END()
        };
-       const char *prefix = setup_git_directory();
+       const char *prefix = setup_git_directory(the_repository);
 
        /* ignore all unknown cmdline switches for now */
        argc = parse_options(argc, argv, prefix, options, serve_usage,
index cbe93f2f9e0178d6e1b84f201a51030e504fad2d..3f30292179337893863f7a25ba26d372241405d1 100644 (file)
@@ -34,7 +34,7 @@ int cmd__submodule_config(int argc, const char **argv)
        if (my_argc % 2 != 0)
                die_usage(argc, argv, "Wrong number of arguments.");
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        while (*arg) {
                struct object_id commit_oid;
index 2710341cd5db11288ce0aeea41fb3553768531de..7e31d3fe47a105b589f63fa41e4617619b5556fb 100644 (file)
@@ -19,7 +19,7 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv)
        if (argc < 3)
                die_usage(argv, "Wrong number of arguments.");
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid(the_hash_algo))) {
                die_usage(argv, "Submodule not found.");
index 0133852e1ebfc7fa2ff3f4368133568bbd93072d..3c5c4c4a090e98bebc14ac8bd13822250b59fedc 100644 (file)
@@ -99,7 +99,7 @@ static int cmd__submodule_is_active(int argc, const char **argv)
        if (argc != 1)
                usage_with_options(submodule_is_active_usage, options);
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        return !is_submodule_active(the_repository, argv[0]);
 }
@@ -142,7 +142,7 @@ static int cmd__submodule_config_list(int argc, const char **argv)
        argc = parse_options(argc, argv, "test-tools", options, usage,
                             PARSE_OPT_KEEP_ARGV0);
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (argc == 2)
                return print_config_from_gitmodules(the_repository, argv[1]);
@@ -161,7 +161,7 @@ static int cmd__submodule_config_set(int argc, const char **argv)
        argc = parse_options(argc, argv, "test-tools", options, usage,
                             PARSE_OPT_KEEP_ARGV0);
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        /* Equivalent to ACTION_SET in builtin/config.c */
        if (argc == 3) {
@@ -183,7 +183,7 @@ static int cmd__submodule_config_unset(int argc, const char **argv)
                NULL
        };
 
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (argc == 2) {
                if (!is_writing_gitmodules_ok())
@@ -202,7 +202,7 @@ static int cmd__submodule_config_writeable(int argc, const char **argv UNUSED)
                "test-tool submodule config-writeable",
                NULL
        };
-       setup_git_directory();
+       setup_git_directory(the_repository);
 
        if (argc == 1)
                return is_writing_gitmodules_ok() ? 0 : -1;
index aa3a9894d257ef21fa5e2e73b2fe1b1db5193e8f..fc34c589b3d1068a97c033513370c7e8ceb7725f 100644 (file)
@@ -40,7 +40,7 @@ int cmd__userdiff(int argc, const char **argv)
                return error("unknown argument %s", argv[1]);
 
        if (want & USERDIFF_DRIVER_TYPE_CUSTOM) {
-               setup_git_directory();
+               setup_git_directory(the_repository);
                repo_config(the_repository, cmd__userdiff_config, NULL);
        }
 
index b37dd2c5d6db64d5ff0b8e0f6689f14fe59700d9..98e1477c98d1f7688c54f3f579289370dd6b02fa 100644 (file)
@@ -12,7 +12,7 @@ int cmd__write_cache(int argc, const char **argv)
        int i, cnt = 1;
        if (argc == 2)
                cnt = strtol(argv[1], NULL, 0);
-       setup_git_directory();
+       setup_git_directory(the_repository);
        repo_read_index(the_repository);
        for (i = 0; i < cnt; i++) {
                repo_hold_locked_index(the_repository, &index_lock,