From: Patrick Steinhardt Date: Tue, 19 May 2026 09:52:08 +0000 (+0200) Subject: setup: stop using `the_repository` in `prefix_path()` X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=2c46e933fa1c2f4ea7e49a26d5dcabaadcfcecb6;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/blame.c b/builtin/blame.c index f3a11eff44..ffbd3ce5c5 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -708,7 +708,7 @@ static unsigned parse_score(const char *arg) static char *add_prefix(const char *prefix, const char *path) { - return prefix_path(prefix, prefix ? strlen(prefix) : 0, path); + return prefix_path(the_repository, prefix, prefix ? strlen(prefix) : 0, path); } static int git_blame_config(const char *var, const char *value, diff --git a/builtin/check-attr.c b/builtin/check-attr.c index 51ed48ce43..04b86e42ae 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -67,7 +67,7 @@ static void check_attr(const char *prefix, struct attr_check *check, { char *full_path = - prefix_path(prefix, prefix ? strlen(prefix) : 0, file); + prefix_path(the_repository, prefix, prefix ? strlen(prefix) : 0, file); if (collect_all) { git_all_attrs(the_repository->index, full_path, check); diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 188128aebd..311b94ff31 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -303,7 +303,7 @@ int cmd_checkout_index(int argc, die("git checkout-index: don't mix '--all' and explicit filenames"); if (read_from_stdin) die("git checkout-index: don't mix '--stdin' and explicit filenames"); - p = prefix_path(prefix, prefix_length, arg); + p = prefix_path(repo, prefix, prefix_length, arg); err |= checkout_file(repo->index, p, prefix); free(p); } @@ -325,7 +325,7 @@ int cmd_checkout_index(int argc, die("line is badly quoted"); strbuf_swap(&buf, &unquoted); } - p = prefix_path(prefix, prefix_length, buf.buf); + p = prefix_path(repo, prefix, prefix_length, buf.buf); err |= checkout_file(repo->index, p, prefix); free(p); } diff --git a/builtin/mv.c b/builtin/mv.c index 2215d34e31..948b330639 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -71,7 +71,7 @@ static void internal_prefix_pathspec(struct strvec *out, trimmed = xmemdupz(pathspec[i], to_copy); maybe_basename = (flags & DUP_BASENAME) ? basename(trimmed) : trimmed; - prefixed_path = prefix_path(prefix, prefixlen, maybe_basename); + prefixed_path = prefix_path(the_repository, prefix, prefixlen, maybe_basename); strvec_push(out, prefixed_path); free(prefixed_path); @@ -394,7 +394,8 @@ dir_check: for (j = 0; j < last - first; j++) { const struct cache_entry *ce = the_repository->index->cache[first + j]; const char *path = ce->name; - char *prefixed_path = prefix_path(dst_with_slash, dst_with_slash_len, path + length + 1); + char *prefixed_path = prefix_path(the_repository, dst_with_slash, + dst_with_slash_len, path + length + 1); strvec_push(&sources, path); strvec_push(&destinations, prefixed_path); diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index f4aa405da9..2af50fb2f9 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -735,7 +735,8 @@ static void sanitize_paths(struct repository *repo, int prefix_len = strlen(prefix); for (i = 0; i < args->nr; i++) { - char *prefixed_path = prefix_path(prefix, prefix_len, args->v[i]); + char *prefixed_path = prefix_path(the_repository, prefix, + prefix_len, args->v[i]); strvec_replace(args, i, prefixed_path); free(prefixed_path); } diff --git a/builtin/update-index.c b/builtin/update-index.c index 8a5907767b..7434112b8e 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -655,7 +655,7 @@ static int do_unresolve(int ac, const char **av, for (i = 1; i < ac; i++) { const char *arg = av[i]; - char *p = prefix_path(prefix, prefix_length, arg); + char *p = prefix_path(the_repository, prefix, prefix_length, arg); err |= unresolve_one(p); free(p); } @@ -1158,7 +1158,7 @@ int cmd_update_index(int argc, } setup_work_tree(); - p = prefix_path(prefix, prefix_length, path); + p = prefix_path(the_repository, prefix, prefix_length, path); update_one(p); if (set_executable_bit) chmod_path(set_executable_bit, p); @@ -1208,7 +1208,7 @@ int cmd_update_index(int argc, die("line is badly quoted"); strbuf_swap(&buf, &unquoted); } - p = prefix_path(prefix, prefix_length, buf.buf); + p = prefix_path(the_repository, prefix, prefix_length, buf.buf); update_one(p); if (set_executable_bit) chmod_path(set_executable_bit, p); diff --git a/line-log.c b/line-log.c index 858a899cd2..346c60c554 100644 --- a/line-log.c +++ b/line-log.c @@ -589,7 +589,7 @@ parse_lines(struct repository *r, struct commit *commit, range_part = xstrndup(item->string, name_part - item->string); name_part++; - full_name = prefix_path(prefix, prefix ? strlen(prefix) : 0, + full_name = prefix_path(r, prefix, prefix ? strlen(prefix) : 0, name_part); spec = alloc_filespec(full_name); diff --git a/object-name.c b/object-name.c index 37a9ce8e87..9ac86f19c7 100644 --- a/object-name.c +++ b/object-name.c @@ -1707,7 +1707,7 @@ static char *resolve_relative_path(struct repository *r, const char *rel) die(_("relative path syntax can't be used outside working tree")); /* die() inside prefix_path() if resolved path is outside worktree */ - return prefix_path(startup_info->prefix, + return prefix_path(the_repository, startup_info->prefix, startup_info->prefix ? strlen(startup_info->prefix) : 0, rel); } diff --git a/pathspec.c b/pathspec.c index 5993c4afa0..f78b22709c 100644 --- a/pathspec.c +++ b/pathspec.c @@ -486,7 +486,7 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags, match = xstrdup(copyfrom); prefixlen = 0; } else { - match = prefix_path_gently(prefix, prefixlen, + match = prefix_path_gently(the_repository, prefix, prefixlen, &prefixlen, copyfrom); if (!match) { const char *hint_path; diff --git a/setup.c b/setup.c index 041e08b98d..adad6ceec0 100644 --- a/setup.c +++ b/setup.c @@ -117,7 +117,8 @@ static int abspath_part_inside_repo(struct repository *repo, char *path) * ../../sub1/sub2/foo -> sub1/sub2/foo (but no remaining prefix) * `pwd`/../bar -> sub1/bar (no remaining prefix) */ -char *prefix_path_gently(const char *prefix, int len, +char *prefix_path_gently(struct repository *repo, + const char *prefix, int len, int *remaining_prefix, const char *path) { const char *orig = path; @@ -130,7 +131,7 @@ char *prefix_path_gently(const char *prefix, int len, free(sanitized); return NULL; } - if (abspath_part_inside_repo(the_repository, sanitized)) { + if (abspath_part_inside_repo(repo, sanitized)) { free(sanitized); return NULL; } @@ -146,13 +147,13 @@ char *prefix_path_gently(const char *prefix, int len, return sanitized; } -char *prefix_path(const char *prefix, int len, const char *path) +char *prefix_path(struct repository *repo, const char *prefix, int len, const char *path) { - char *r = prefix_path_gently(prefix, len, NULL, path); + char *r = prefix_path_gently(repo, prefix, len, NULL, path); if (!r) { - const char *hint_path = repo_get_work_tree(the_repository); + const char *hint_path = repo_get_work_tree(repo); if (!hint_path) - hint_path = repo_get_git_dir(the_repository); + hint_path = repo_get_git_dir(repo); die(_("'%s' is outside repository at '%s'"), path, absolute_path(hint_path)); } @@ -162,7 +163,7 @@ char *prefix_path(const char *prefix, int len, const char *path) int path_inside_repo(const char *prefix, const char *path) { int len = prefix ? strlen(prefix) : 0; - char *r = prefix_path_gently(prefix, len, NULL, path); + char *r = prefix_path_gently(the_repository, prefix, len, NULL, path); if (r) { free(r); return 1; diff --git a/setup.h b/setup.h index 71d3f91883..24034572b1 100644 --- a/setup.h +++ b/setup.h @@ -138,8 +138,8 @@ const char *enter_repo(const char *path, unsigned flags); const char *setup_git_directory_gently(int *); const char *setup_git_directory(void); -char *prefix_path(const char *prefix, int len, const char *path); -char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path); +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); int check_filename(const char *prefix, const char *name); void verify_filename(const char *prefix, diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 874542ec34..163fdeefb0 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -379,7 +379,7 @@ int cmd__path_utils(int argc, const char **argv) int nongit_ok; setup_git_directory_gently(&nongit_ok); while (argc > 3) { - char *pfx = prefix_path(prefix, prefix_len, argv[3]); + char *pfx = prefix_path(the_repository, prefix, prefix_len, argv[3]); puts(pfx); free(pfx);