summaryrefslogtreecommitdiffstats
path: root/worktree.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-09-12 13:29:27 +0200
committerJunio C Hamano <gitster@pobox.com>2024-09-12 19:15:39 +0200
commit661624a4f6299b44f56df162100fdca528c119c1 (patch)
treeb210fa7d6fc0c5fc1e63bea4b5dac9ebba48e8d7 /worktree.c
parentenvironment: make `get_git_dir()` accept a repository (diff)
downloadgit-661624a4f6299b44f56df162100fdca528c119c1.tar.xz
git-661624a4f6299b44f56df162100fdca528c119c1.zip
environment: make `get_git_common_dir()` accept a repository
The `get_git_common_dir()` function retrieves the path to the common 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>
Diffstat (limited to '')
-rw-r--r--worktree.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/worktree.c b/worktree.c
index 11335c5d9a..0f032ccedf 100644
--- a/worktree.c
+++ b/worktree.c
@@ -72,7 +72,7 @@ static struct worktree *get_main_worktree(int skip_reading_head)
struct worktree *worktree = NULL;
struct strbuf worktree_path = STRBUF_INIT;
- strbuf_add_real_path(&worktree_path, get_git_common_dir());
+ strbuf_add_real_path(&worktree_path, repo_get_common_dir(the_repository));
strbuf_strip_suffix(&worktree_path, "/.git");
CALLOC_ARRAY(worktree, 1);
@@ -143,7 +143,7 @@ static struct worktree **get_worktrees_internal(int skip_reading_head)
list[counter++] = get_main_worktree(skip_reading_head);
- strbuf_addf(&path, "%s/worktrees", get_git_common_dir());
+ strbuf_addf(&path, "%s/worktrees", repo_get_common_dir(the_repository));
dir = opendir(path.buf);
strbuf_release(&path);
if (dir) {
@@ -173,7 +173,7 @@ const char *get_worktree_git_dir(const struct worktree *wt)
if (!wt)
return repo_get_git_dir(the_repository);
else if (!wt->id)
- return get_git_common_dir();
+ return repo_get_common_dir(the_repository);
else
return git_common_path("worktrees/%s", wt->id);
}
@@ -626,7 +626,7 @@ static int is_main_worktree_path(const char *path)
strbuf_add_real_path(&target, path);
strbuf_strip_suffix(&target, "/.git");
- strbuf_add_real_path(&maindir, get_git_common_dir());
+ strbuf_add_real_path(&maindir, repo_get_common_dir(the_repository));
strbuf_strip_suffix(&maindir, "/.git");
cmp = fspathcmp(maindir.buf, target.buf);