setup: stop using `the_repository` in `setup_git_directory()`

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>

Patrick Steinhardt committed May 19, 2026 at 11:52 UTC f9210dbc8add0ddd6bf31eb479d0d1d40a42850c
40 files changed +49 -47
archive.c
+1 -1
@@ -786,7 +786,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
786 * die ourselves; but its error message will be more specific
787 * than what we could write here.
788 */
789 - setup_git_directory();
789 + setup_git_directory(the_repository);
790 }
791
792 parse_treeish_arg(argv, &args, remote);
builtin/grep.c
+1 -1
@@ -1064,7 +1064,7 @@ int cmd_grep(int argc,
1064 use_index = 0;
1065 else
1066 /* die the same way as if we did it at the beginning */
1067 - setup_git_directory();
1067 + setup_git_directory(the_repository);
1068 }
1069 /* Ignore --recurse-submodules if --no-index is given or implied */
1070 if (!use_index)
builtin/hash-object.c
+1 -1
@@ -100,7 +100,7 @@ int cmd_hash_object(int argc,
100 hash_object_usage, 0);
101
102 if (flags & INDEX_WRITE_OBJECT)
103 - prefix = setup_git_directory();
103 + prefix = setup_git_directory(the_repository);
104 else
105 prefix = setup_git_directory_gently(the_repository, &nongit);
106
builtin/merge-file.c
+1 -1
@@ -110,7 +110,7 @@ int cmd_merge_file(int argc,
110
111 if (!repo && object_id)
112 /* emit the correct "not a git repo" error in this case */
113 - setup_git_directory();
113 + setup_git_directory(the_repository);
114
115 for (i = 0; i < 3; i++) {
116 char *fname;
builtin/rev-parse.c
+2 -2
@@ -739,7 +739,7 @@ int cmd_rev_parse(int argc,
739
740 /* No options; just report on whether we're in a git repo or not. */
741 if (argc == 1) {
742 - setup_git_directory();
742 + setup_git_directory(the_repository);
743 repo_config(the_repository, git_default_config, NULL);
744 return 0;
745 }
@@ -774,7 +774,7 @@ int cmd_rev_parse(int argc,
774
775 /* The rest of the options require a git repository. */
776 if (!did_repo_setup) {
777 - prefix = setup_git_directory();
777 + prefix = setup_git_directory(the_repository);
778 repo_config(the_repository, git_default_config, NULL);
779 did_repo_setup = 1;
780
git.c
+1 -1
@@ -477,7 +477,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
477 run_setup = RUN_SETUP_GENTLY;
478
479 if (run_setup & RUN_SETUP) {
480 - prefix = setup_git_directory();
480 + prefix = setup_git_directory(the_repository);
481 no_repo = 0;
482 } else if (run_setup & RUN_SETUP_GENTLY) {
483 prefix = setup_git_directory_gently(the_repository, &no_repo);
http-push.c
+1 -1
@@ -1788,7 +1788,7 @@ int cmd_main(int argc, const char **argv)
1788 if (delete_branch && rs.nr != 1)
1789 die("You must specify only one branch name when deleting a remote branch");
1790
1791 - gitdir = setup_git_directory();
1791 + gitdir = setup_git_directory(the_repository);
1792
1793 memset(remote_dir_exists, -1, 256);
1794
scalar.c
+2 -2
@@ -58,7 +58,7 @@ static void setup_enlistment_directory(int argc, const char **argv,
58 }
59 strbuf_setlen(&path, len);
60
61 - setup_git_directory();
61 + setup_git_directory(the_repository);
62
63 if (!the_repository->worktree)
64 die(_("Scalar enlistments require a worktree"));
@@ -514,7 +514,7 @@ static int cmd_clone(int argc, const char **argv)
514 goto cleanup;
515 }
516
517 - setup_git_directory();
517 + setup_git_directory(the_repository);
518
519 /* common-main already logs `argv` */
520 trace2_def_repo(the_repository);
setup.c
+2 -2
@@ -2136,9 +2136,9 @@ void check_repository_format(struct repository_format *fmt)
2136 * directory is not a strict subdirectory of the work tree root. The
2137 * prefix always ends with a '/' character.
2138 */
2139 -const char *setup_git_directory(void)
2139 +const char *setup_git_directory(struct repository *repo)
2140 {
2141 - return setup_git_directory_gently(the_repository, NULL);
2141 + return setup_git_directory_gently(repo, NULL);
2142 }
2143
2144 const char *resolve_gitdir_gently(const char *suspect, int *return_error_code)
setup.h
+1 -1
@@ -137,7 +137,7 @@ enum {
137 const char *enter_repo(struct repository *repo, const char *path, unsigned flags);
138
139 const char *setup_git_directory_gently(struct repository *repo, int *);
140 -const char *setup_git_directory(void);
140 +const char *setup_git_directory(struct repository *repo);
141 char *prefix_path(struct repository *repo, const char *prefix, int len, const char *path);
142 char *prefix_path_gently(struct repository *repo, const char *prefix, int len, int *remaining, const char *path);
143
t/helper/test-advise.c
+1 -1
@@ -11,7 +11,7 @@ int cmd__advise_if_enabled(int argc, const char **argv)
11 if (argc != 2)
12 die("usage: %s <advice>", argv[0]);
13
14 - setup_git_directory();
14 + setup_git_directory(the_repository);
15 repo_config(the_repository, git_default_config, NULL);
16
17 /*
t/helper/test-bitmap.c
+1 -1
@@ -37,7 +37,7 @@ static int bitmap_dump_pseudo_merge_objects(uint32_t n)
37
38 int cmd__bitmap(int argc, const char **argv)
39 {
40 - setup_git_directory();
40 + setup_git_directory(the_repository);
41
42 if (argc == 2 && !strcmp(argv[1], "list-commits"))
43 return bitmap_list_commits();
t/helper/test-bloom.c
+1 -1
@@ -52,7 +52,7 @@ static const char *const bloom_usage = "\n"
52
53 int cmd__bloom(int argc, const char **argv)
54 {
55 - setup_git_directory();
55 + setup_git_directory(the_repository);
56
57 if (argc < 2)
58 usage(bloom_usage);
t/helper/test-cache-tree.c
+1 -1
@@ -33,7 +33,7 @@ int cmd__cache_tree(int argc, const char **argv)
33 OPT_END()
34 };
35
36 - setup_git_directory();
36 + setup_git_directory(the_repository);
37
38 argc = parse_options(argc, argv, NULL, options, test_cache_tree_usage, 0);
39
t/helper/test-config.c
+1 -1
@@ -102,7 +102,7 @@ int cmd__config(int argc, const char **argv)
102 return 0;
103 }
104
105 - setup_git_directory();
105 + setup_git_directory(the_repository);
106
107 git_configset_init(&cs);
108
t/helper/test-dump-cache-tree.c
+1 -1
@@ -66,7 +66,7 @@ int cmd__dump_cache_tree(int ac UNUSED, const char **av UNUSED)
66 struct cache_tree *another = cache_tree();
67 int ret;
68
69 - setup_git_directory();
69 + setup_git_directory(the_repository);
70 if (repo_read_index(the_repository) < 0)
71 die("unable to read index file");
72 istate = *the_repository->index;
t/helper/test-dump-fsmonitor.c
+1 -1
@@ -9,7 +9,7 @@ int cmd__dump_fsmonitor(int ac UNUSED, const char **av UNUSED)
9 {
10 struct index_state *istate = the_repository->index;
11
12 - setup_git_directory();
12 + setup_git_directory(the_repository);
13 if (do_read_index(istate, the_repository->index_file, 0) < 0)
14 die("unable to read index file");
15 if (!istate->fsmonitor_last_update) {
t/helper/test-dump-split-index.c
+1 -1
@@ -17,7 +17,7 @@ int cmd__dump_split_index(int ac UNUSED, const char **av)
17 {
18 struct split_index *si;
19
20 - setup_git_directory();
20 + setup_git_directory(the_repository);
21
22 do_read_index(the_repository->index, av[1], 1);
23 printf("own %s\n", oid_to_hex(&the_repository->index->oid));
t/helper/test-dump-untracked-cache.c
+1 -1
@@ -54,7 +54,7 @@ int cmd__dump_untracked_cache(int ac UNUSED, const char **av UNUSED)
54 xsetenv("GIT_CONFIG_KEY_0", "core.untrackedCache", 1);
55 xsetenv("GIT_CONFIG_VALUE_0", "keep", 1);
56
57 - setup_git_directory();
57 + setup_git_directory(the_repository);
58 if (repo_read_index(the_repository) < 0)
59 die("unable to read index file");
60 uc = the_repository->index->untracked;
t/helper/test-find-pack.c
+1 -1
@@ -25,7 +25,7 @@ int cmd__find_pack(int argc, const char **argv)
25 struct object_id oid;
26 struct packed_git *p;
27 int count = -1, actual_count = 0;
28 - const char *prefix = setup_git_directory();
28 + const char *prefix = setup_git_directory(the_repository);
29
30 struct option options[] = {
31 OPT_INTEGER('c', "check-count", &count, "expected number of packs"),
t/helper/test-fsmonitor-client.c
+1 -1
@@ -210,7 +210,7 @@ int cmd__fsmonitor_client(int argc, const char **argv)
210
211 subcmd = argv[0];
212
213 - setup_git_directory();
213 + setup_git_directory(the_repository);
214
215 if (!strcmp(subcmd, "query"))
216 return !!do_send_query(token);
t/helper/test-lazy-init-name-hash.c
+1 -1
@@ -211,7 +211,7 @@ int cmd__lazy_init_name_hash(int argc, const char **argv)
211 const char *prefix;
212 uint64_t avg_single, avg_multi;
213
214 - prefix = setup_git_directory();
214 + prefix = setup_git_directory(the_repository);
215
216 argc = parse_options(argc, argv, prefix, options, usage, 0);
217
t/helper/test-match-trees.c
+1 -1
@@ -13,7 +13,7 @@ int cmd__match_trees(int ac UNUSED, const char **av)
13 struct object_id hash1, hash2, shifted;
14 struct tree *one, *two;
15
16 - setup_git_directory();
16 + setup_git_directory(the_repository);
17
18 if (repo_get_oid(the_repository, av[1], &hash1))
19 die("cannot parse %s as an object name", av[1]);
t/helper/test-pack-deltas.c
+1 -1
@@ -95,7 +95,7 @@ int cmd__pack_deltas(int argc, const char **argv)
95 if (argc || num_objects < 0)
96 usage_with_options(usage_str, options);
97
98 - setup_git_directory();
98 + setup_git_directory(the_repository);
99
100 f = hashfd(the_repository->hash_algo, 1, "<stdout>");
101 write_pack_header(f, num_objects);
t/helper/test-pack-mtimes.c
+1 -1
@@ -32,7 +32,7 @@ int cmd__pack_mtimes(int argc, const char **argv)
32 struct strbuf buf = STRBUF_INIT;
33 struct packed_git *p;
34
35 - setup_git_directory();
35 + setup_git_directory(the_repository);
36
37 if (argc != 2)
38 usage(pack_mtimes_usage);
t/helper/test-partial-clone.c
+3 -1
@@ -1,3 +1,5 @@
1 +#define USE_THE_REPOSITORY_VARIABLE
2 +
3 #include "test-tool.h"
4 #include "hex.h"
5 #include "repository.h"
@@ -32,7 +34,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
34
35 int cmd__partial_clone(int argc, const char **argv)
36 {
35 - setup_git_directory();
37 + setup_git_directory(the_repository);
38
39 if (argc < 4)
40 die("too few arguments");
t/helper/test-path-walk.c
+1 -1
@@ -89,7 +89,7 @@ int cmd__path_walk(int argc, const char **argv)
89 OPT_END(),
90 };
91
92 - setup_git_directory();
92 + setup_git_directory(the_repository);
93 revs.repo = the_repository;
94
95 argc = parse_options(argc, argv, NULL,
t/helper/test-reach.c
+1 -1
@@ -39,7 +39,7 @@ int cmd__reach(int ac, const char **av)
39 struct strbuf buf = STRBUF_INIT;
40 struct repository *r = the_repository;
41
42 - setup_git_directory();
42 + setup_git_directory(the_repository);
43
44 if (ac < 2)
45 exit(1);
t/helper/test-read-cache.c
+1 -1
@@ -19,7 +19,7 @@ int cmd__read_cache(int argc, const char **argv)
19
20 if (argc == 2)
21 cnt = strtol(argv[1], NULL, 0);
22 - setup_git_directory();
22 + setup_git_directory(the_repository);
23 repo_config(the_repository, git_default_config, NULL);
24
25 for (i = 0; i < cnt; i++) {
t/helper/test-read-graph.c
+1 -1
@@ -76,7 +76,7 @@ int cmd__read_graph(int argc, const char **argv)
76 struct odb_source *source;
77 int ret = 0;
78
79 - setup_git_directory();
79 + setup_git_directory(the_repository);
80 source = the_repository->objects->sources;
81
82 prepare_repo_settings(the_repository);
t/helper/test-read-midx.c
+1 -1
@@ -14,7 +14,7 @@
14 static struct multi_pack_index *setup_midx(const char *object_dir)
15 {
16 struct odb_source *source;
17 - setup_git_directory();
17 + setup_git_directory(the_repository);
18 source = odb_find_source(the_repository->objects, object_dir);
19 if (!source)
20 source = odb_add_to_alternates_memory(the_repository->objects,
t/helper/test-ref-store.c
+1 -1
@@ -340,7 +340,7 @@ int cmd__ref_store(int argc UNUSED, const char **argv)
340 const char *func;
341 struct command *cmd;
342
343 - setup_git_directory();
343 + setup_git_directory(the_repository);
344
345 argv = get_store(argv + 1, &refs);
346
t/helper/test-revision-walking.c
+1 -1
@@ -56,7 +56,7 @@ int cmd__revision_walking(int argc, const char **argv)
56 if (argc < 2)
57 return 1;
58
59 - setup_git_directory();
59 + setup_git_directory(the_repository);
60
61 if (!strcmp(argv[1], "run-twice")) {
62 printf("1st\n");
t/helper/test-scrap-cache-tree.c
+1 -1
@@ -12,7 +12,7 @@ int cmd__scrap_cache_tree(int ac UNUSED, const char **av UNUSED)
12 {
13 struct lock_file index_lock = LOCK_INIT;
14
15 - setup_git_directory();
15 + setup_git_directory(the_repository);
16 repo_hold_locked_index(the_repository, &index_lock, LOCK_DIE_ON_ERROR);
17 if (repo_read_index(the_repository) < 0)
18 die("unable to read index file");
t/helper/test-serve-v2.c
+1 -1
@@ -23,7 +23,7 @@ int cmd__serve_v2(int argc, const char **argv)
23 N_("exit immediately after advertising capabilities")),
24 OPT_END()
25 };
26 - const char *prefix = setup_git_directory();
26 + const char *prefix = setup_git_directory(the_repository);
27
28 /* ignore all unknown cmdline switches for now */
29 argc = parse_options(argc, argv, prefix, options, serve_usage,
t/helper/test-submodule-config.c
+1 -1
@@ -34,7 +34,7 @@ int cmd__submodule_config(int argc, const char **argv)
34 if (my_argc % 2 != 0)
35 die_usage(argc, argv, "Wrong number of arguments.");
36
37 - setup_git_directory();
37 + setup_git_directory(the_repository);
38
39 while (*arg) {
40 struct object_id commit_oid;
t/helper/test-submodule-nested-repo-config.c
+1 -1
@@ -19,7 +19,7 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv)
19 if (argc < 3)
20 die_usage(argv, "Wrong number of arguments.");
21
22 - setup_git_directory();
22 + setup_git_directory(the_repository);
23
24 if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid(the_hash_algo))) {
25 die_usage(argv, "Submodule not found.");
t/helper/test-submodule.c
+5 -5
@@ -99,7 +99,7 @@ static int cmd__submodule_is_active(int argc, const char **argv)
99 if (argc != 1)
100 usage_with_options(submodule_is_active_usage, options);
101
102 - setup_git_directory();
102 + setup_git_directory(the_repository);
103
104 return !is_submodule_active(the_repository, argv[0]);
105 }
@@ -142,7 +142,7 @@ static int cmd__submodule_config_list(int argc, const char **argv)
142 argc = parse_options(argc, argv, "test-tools", options, usage,
143 PARSE_OPT_KEEP_ARGV0);
144
145 - setup_git_directory();
145 + setup_git_directory(the_repository);
146
147 if (argc == 2)
148 return print_config_from_gitmodules(the_repository, argv[1]);
@@ -161,7 +161,7 @@ static int cmd__submodule_config_set(int argc, const char **argv)
161 argc = parse_options(argc, argv, "test-tools", options, usage,
162 PARSE_OPT_KEEP_ARGV0);
163
164 - setup_git_directory();
164 + setup_git_directory(the_repository);
165
166 /* Equivalent to ACTION_SET in builtin/config.c */
167 if (argc == 3) {
@@ -183,7 +183,7 @@ static int cmd__submodule_config_unset(int argc, const char **argv)
183 NULL
184 };
185
186 - setup_git_directory();
186 + setup_git_directory(the_repository);
187
188 if (argc == 2) {
189 if (!is_writing_gitmodules_ok())
@@ -202,7 +202,7 @@ static int cmd__submodule_config_writeable(int argc, const char **argv UNUSED)
202 "test-tool submodule config-writeable",
203 NULL
204 };
205 - setup_git_directory();
205 + setup_git_directory(the_repository);
206
207 if (argc == 1)
208 return is_writing_gitmodules_ok() ? 0 : -1;
t/helper/test-userdiff.c
+1 -1
@@ -40,7 +40,7 @@ int cmd__userdiff(int argc, const char **argv)
40 return error("unknown argument %s", argv[1]);
41
42 if (want & USERDIFF_DRIVER_TYPE_CUSTOM) {
43 - setup_git_directory();
43 + setup_git_directory(the_repository);
44 repo_config(the_repository, cmd__userdiff_config, NULL);
45 }
46
t/helper/test-write-cache.c
+1 -1
@@ -12,7 +12,7 @@ int cmd__write_cache(int argc, const char **argv)
12 int i, cnt = 1;
13 if (argc == 2)
14 cnt = strtol(argv[1], NULL, 0);
15 - setup_git_directory();
15 + setup_git_directory(the_repository);
16 repo_read_index(the_repository);
17 for (i = 0; i < cnt; i++) {
18 repo_hold_locked_index(the_repository, &index_lock,