summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-05-19 11:52:08 +0200
committerJunio C Hamano <gitster@pobox.com>2026-05-19 19:36:24 +0900
commit2c46e933fa1c2f4ea7e49a26d5dcabaadcfcecb6 (patch)
treed1718d920419c0413501c74c33c28817ae9b0670 /setup.c
parent8da5ecdb4d72594ee126e949bfe813c0f89fe692 (diff)
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>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c15
1 files changed, 8 insertions, 7 deletions
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;