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

Stop using `the_repository` in `prefix_path()` 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 2c46e933fa1c2f4ea7e49a26d5dcabaadcfcecb6
12 files changed +26 -23
builtin/blame.c
+1 -1
@@ -708,7 +708,7 @@ static unsigned parse_score(const char *arg)
708
709 static char *add_prefix(const char *prefix, const char *path)
710 {
711 - return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
711 + return prefix_path(the_repository, prefix, prefix ? strlen(prefix) : 0, path);
712 }
713
714 static int git_blame_config(const char *var, const char *value,
builtin/check-attr.c
+1 -1
@@ -67,7 +67,7 @@ static void check_attr(const char *prefix, struct attr_check *check,
67
68 {
69 char *full_path =
70 - prefix_path(prefix, prefix ? strlen(prefix) : 0, file);
70 + prefix_path(the_repository, prefix, prefix ? strlen(prefix) : 0, file);
71
72 if (collect_all) {
73 git_all_attrs(the_repository->index, full_path, check);
builtin/checkout-index.c
+2 -2
@@ -303,7 +303,7 @@ int cmd_checkout_index(int argc,
303 die("git checkout-index: don't mix '--all' and explicit filenames");
304 if (read_from_stdin)
305 die("git checkout-index: don't mix '--stdin' and explicit filenames");
306 - p = prefix_path(prefix, prefix_length, arg);
306 + p = prefix_path(repo, prefix, prefix_length, arg);
307 err |= checkout_file(repo->index, p, prefix);
308 free(p);
309 }
@@ -325,7 +325,7 @@ int cmd_checkout_index(int argc,
325 die("line is badly quoted");
326 strbuf_swap(&buf, &unquoted);
327 }
328 - p = prefix_path(prefix, prefix_length, buf.buf);
328 + p = prefix_path(repo, prefix, prefix_length, buf.buf);
329 err |= checkout_file(repo->index, p, prefix);
330 free(p);
331 }
builtin/mv.c
+3 -2
@@ -71,7 +71,7 @@ static void internal_prefix_pathspec(struct strvec *out,
71
72 trimmed = xmemdupz(pathspec[i], to_copy);
73 maybe_basename = (flags & DUP_BASENAME) ? basename(trimmed) : trimmed;
74 - prefixed_path = prefix_path(prefix, prefixlen, maybe_basename);
74 + prefixed_path = prefix_path(the_repository, prefix, prefixlen, maybe_basename);
75 strvec_push(out, prefixed_path);
76
77 free(prefixed_path);
@@ -394,7 +394,8 @@ dir_check:
394 for (j = 0; j < last - first; j++) {
395 const struct cache_entry *ce = the_repository->index->cache[first + j];
396 const char *path = ce->name;
397 - char *prefixed_path = prefix_path(dst_with_slash, dst_with_slash_len, path + length + 1);
397 + char *prefixed_path = prefix_path(the_repository, dst_with_slash,
398 + dst_with_slash_len, path + length + 1);
399
400 strvec_push(&sources, path);
401 strvec_push(&destinations, prefixed_path);
builtin/sparse-checkout.c
+2 -1
@@ -735,7 +735,8 @@ static void sanitize_paths(struct repository *repo,
735 int prefix_len = strlen(prefix);
736
737 for (i = 0; i < args->nr; i++) {
738 - char *prefixed_path = prefix_path(prefix, prefix_len, args->v[i]);
738 + char *prefixed_path = prefix_path(the_repository, prefix,
739 + prefix_len, args->v[i]);
740 strvec_replace(args, i, prefixed_path);
741 free(prefixed_path);
742 }
builtin/update-index.c
+3 -3
@@ -655,7 +655,7 @@ static int do_unresolve(int ac, const char **av,
655
656 for (i = 1; i < ac; i++) {
657 const char *arg = av[i];
658 - char *p = prefix_path(prefix, prefix_length, arg);
658 + char *p = prefix_path(the_repository, prefix, prefix_length, arg);
659 err |= unresolve_one(p);
660 free(p);
661 }
@@ -1158,7 +1158,7 @@ int cmd_update_index(int argc,
1158 }
1159
1160 setup_work_tree();
1161 - p = prefix_path(prefix, prefix_length, path);
1161 + p = prefix_path(the_repository, prefix, prefix_length, path);
1162 update_one(p);
1163 if (set_executable_bit)
1164 chmod_path(set_executable_bit, p);
@@ -1208,7 +1208,7 @@ int cmd_update_index(int argc,
1208 die("line is badly quoted");
1209 strbuf_swap(&buf, &unquoted);
1210 }
1211 - p = prefix_path(prefix, prefix_length, buf.buf);
1211 + p = prefix_path(the_repository, prefix, prefix_length, buf.buf);
1212 update_one(p);
1213 if (set_executable_bit)
1214 chmod_path(set_executable_bit, p);
line-log.c
+1 -1
@@ -589,7 +589,7 @@ parse_lines(struct repository *r, struct commit *commit,
589 range_part = xstrndup(item->string, name_part - item->string);
590 name_part++;
591
592 - full_name = prefix_path(prefix, prefix ? strlen(prefix) : 0,
592 + full_name = prefix_path(r, prefix, prefix ? strlen(prefix) : 0,
593 name_part);
594
595 spec = alloc_filespec(full_name);
object-name.c
+1 -1
@@ -1707,7 +1707,7 @@ static char *resolve_relative_path(struct repository *r, const char *rel)
1707 die(_("relative path syntax can't be used outside working tree"));
1708
1709 /* die() inside prefix_path() if resolved path is outside worktree */
1710 - return prefix_path(startup_info->prefix,
1710 + return prefix_path(the_repository, startup_info->prefix,
1711 startup_info->prefix ? strlen(startup_info->prefix) : 0,
1712 rel);
1713 }
pathspec.c
+1 -1
@@ -486,7 +486,7 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
486 match = xstrdup(copyfrom);
487 prefixlen = 0;
488 } else {
489 - match = prefix_path_gently(prefix, prefixlen,
489 + match = prefix_path_gently(the_repository, prefix, prefixlen,
490 &prefixlen, copyfrom);
491 if (!match) {
492 const char *hint_path;
setup.c
+8 -7
@@ -117,7 +117,8 @@ static int abspath_part_inside_repo(struct repository *repo, char *path)
117 * ../../sub1/sub2/foo -> sub1/sub2/foo (but no remaining prefix)
118 * `pwd`/../bar -> sub1/bar (no remaining prefix)
119 */
120 -char *prefix_path_gently(const char *prefix, int len,
120 +char *prefix_path_gently(struct repository *repo,
121 + const char *prefix, int len,
122 int *remaining_prefix, const char *path)
123 {
124 const char *orig = path;
@@ -130,7 +131,7 @@ char *prefix_path_gently(const char *prefix, int len,
131 free(sanitized);
132 return NULL;
133 }
133 - if (abspath_part_inside_repo(the_repository, sanitized)) {
134 + if (abspath_part_inside_repo(repo, sanitized)) {
135 free(sanitized);
136 return NULL;
137 }
@@ -146,13 +147,13 @@ char *prefix_path_gently(const char *prefix, int len,
147 return sanitized;
148 }
149
149 -char *prefix_path(const char *prefix, int len, const char *path)
150 +char *prefix_path(struct repository *repo, const char *prefix, int len, const char *path)
151 {
151 - char *r = prefix_path_gently(prefix, len, NULL, path);
152 + char *r = prefix_path_gently(repo, prefix, len, NULL, path);
153 if (!r) {
153 - const char *hint_path = repo_get_work_tree(the_repository);
154 + const char *hint_path = repo_get_work_tree(repo);
155 if (!hint_path)
155 - hint_path = repo_get_git_dir(the_repository);
156 + hint_path = repo_get_git_dir(repo);
157 die(_("'%s' is outside repository at '%s'"), path,
158 absolute_path(hint_path));
159 }
@@ -162,7 +163,7 @@ char *prefix_path(const char *prefix, int len, const char *path)
163 int path_inside_repo(const char *prefix, const char *path)
164 {
165 int len = prefix ? strlen(prefix) : 0;
165 - char *r = prefix_path_gently(prefix, len, NULL, path);
166 + char *r = prefix_path_gently(the_repository, prefix, len, NULL, path);
167 if (r) {
168 free(r);
169 return 1;
setup.h
+2 -2
@@ -138,8 +138,8 @@ const char *enter_repo(const char *path, unsigned flags);
138
139 const char *setup_git_directory_gently(int *);
140 const char *setup_git_directory(void);
141 -char *prefix_path(const char *prefix, int len, const char *path);
142 -char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path);
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
144 int check_filename(const char *prefix, const char *name);
145 void verify_filename(const char *prefix,
t/helper/test-path-utils.c
+1 -1
@@ -379,7 +379,7 @@ int cmd__path_utils(int argc, const char **argv)
379 int nongit_ok;
380 setup_git_directory_gently(&nongit_ok);
381 while (argc > 3) {
382 - char *pfx = prefix_path(prefix, prefix_len, argv[3]);
382 + char *pfx = prefix_path(the_repository, prefix, prefix_len, argv[3]);
383
384 puts(pfx);
385 free(pfx);