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>
This commit is contained in:
Patrick Steinhardt
2026-05-19 11:52:08 +02:00
committed by Junio C Hamano
parent 8da5ecdb4d
commit 2c46e933fa
12 changed files with 26 additions and 23 deletions

15
setup.c
View File

@@ -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;