environment: make get_git_work_tree() accept a repository

The `get_git_work_tree()` function retrieves the path of the work tree
of `the_repository`. Make it accept a `struct repository` such that it
can work on arbitrary repositories and make it part of the repository
subsystem. This reduces our reliance on `the_repository` and clarifies
scope.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-09-12 13:29:40 +02:00
committed by Junio C Hamano
parent 14c90ac088
commit edc2c92624
18 changed files with 36 additions and 34 deletions

16
setup.c
View File

@@ -51,7 +51,7 @@ static int abspath_part_inside_repo(char *path)
size_t wtlen;
char *path0;
int off;
const char *work_tree = precompose_string_if_needed(get_git_work_tree());
const char *work_tree = precompose_string_if_needed(repo_get_work_tree(the_repository));
struct strbuf realpath = STRBUF_INIT;
if (!work_tree)
@@ -147,7 +147,7 @@ char *prefix_path(const char *prefix, int len, const char *path)
{
char *r = prefix_path_gently(prefix, len, NULL, path);
if (!r) {
const char *hint_path = get_git_work_tree();
const char *hint_path = repo_get_work_tree(the_repository);
if (!hint_path)
hint_path = repo_get_git_dir(the_repository);
die(_("'%s' is outside repository at '%s'"), path,
@@ -475,7 +475,7 @@ int is_inside_git_dir(void)
int is_inside_work_tree(void)
{
if (inside_work_tree < 0)
inside_work_tree = is_inside_dir(get_git_work_tree());
inside_work_tree = is_inside_dir(repo_get_work_tree(the_repository));
return inside_work_tree;
}
@@ -490,7 +490,7 @@ void setup_work_tree(void)
if (work_tree_config_is_bogus)
die(_("unable to set up work tree using invalid config"));
work_tree = get_git_work_tree();
work_tree = repo_get_work_tree(the_repository);
if (!work_tree || chdir_notify(work_tree))
die(_("this operation must be run in a work tree"));
@@ -547,7 +547,7 @@ static void setup_original_cwd(void)
* Get our worktree; we only protect the current working directory
* if it's in the worktree.
*/
worktree = get_git_work_tree();
worktree = repo_get_work_tree(the_repository);
if (!worktree)
goto no_prevention_needed;
@@ -1062,9 +1062,9 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
set_git_work_tree(".");
/* set_git_work_tree() must have been called by now */
worktree = get_git_work_tree();
worktree = repo_get_work_tree(the_repository);
/* both get_git_work_tree() and cwd are already normalized */
/* both repo_get_work_tree() and cwd are already normalized */
if (!strcmp(cwd->buf, worktree)) { /* cwd == worktree */
set_git_dir(gitdirenv, 0);
free(gitfile);
@@ -2192,7 +2192,7 @@ static int create_default_files(const char *template_path,
char *path;
int reinit;
int filemode;
const char *work_tree = get_git_work_tree();
const char *work_tree = repo_get_work_tree(the_repository);
/*
* First copy the templates -- we might have the default