environment: make get_git_dir() accept a repository

The `get_git_dir()` function retrieves the path to the Git directory for
`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:24 +02:00
committed by Junio C Hamano
parent 17d4b10aea
commit 246deeac95
21 changed files with 56 additions and 38 deletions

View File

@ -57,7 +57,7 @@ static void add_head_info(struct worktree *wt)
static int is_current_worktree(struct worktree *wt)
{
char *git_dir = absolute_pathdup(get_git_dir());
char *git_dir = absolute_pathdup(repo_get_git_dir(the_repository));
const char *wt_git_dir = get_worktree_git_dir(wt);
int is_current = !fspathcmp(git_dir, absolute_path(wt_git_dir));
free(git_dir);
@ -171,7 +171,7 @@ struct worktree **get_worktrees(void)
const char *get_worktree_git_dir(const struct worktree *wt)
{
if (!wt)
return get_git_dir();
return repo_get_git_dir(the_repository);
else if (!wt->id)
return get_git_common_dir();
else