aboutsummaryrefslogtreecommitdiffstats
path: root/refs.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-05-17 10:18:44 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-17 10:33:38 -0700
commitdc7fb4f72c2e39ffbb98aee55ad7ea4c3f8e12fc (patch)
treeac6fe8d4aaff5edae0cf79545f9cdce1be9e8590 /refs.c
parentrefs: refactor `resolve_gitlink_ref()` to accept a repository (diff)
downloadgit-dc7fb4f72c2e39ffbb98aee55ad7ea4c3f8e12fc.tar.gz
git-dc7fb4f72c2e39ffbb98aee55ad7ea4c3f8e12fc.zip
refs: retrieve worktree ref stores via associated repository
Similar as with the preceding commit, the worktree ref stores are always looked up via `the_repository`. Also, again, those ref stores are stored in a global map. Refactor the code so that worktrees have a pointer to their repository. Like this, we can move the global map into `struct repository` and stop using `the_repository`. With this change, we can now in theory look up worktree ref stores for repositories other than `the_repository`. In practice, the worktree code will need further changes to look up arbitrary worktrees. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/refs.c b/refs.c
index 7703b7781c..70e712fcef 100644
--- a/refs.c
+++ b/refs.c
@@ -1960,9 +1960,6 @@ int repo_resolve_gitlink_ref(struct repository *r,
return 0;
}
-/* A strmap of ref_stores, stored by worktree id: */
-static struct strmap worktree_ref_stores;
-
/*
* Look up a ref store by name. If that ref_store hasn't been
* registered yet, return NULL.
@@ -2091,25 +2088,29 @@ struct ref_store *get_worktree_ref_store(const struct worktree *wt)
const char *id;
if (wt->is_current)
- return get_main_ref_store(the_repository);
+ return get_main_ref_store(wt->repo);
id = wt->id ? wt->id : "/";
- refs = lookup_ref_store_map(&worktree_ref_stores, id);
+ refs = lookup_ref_store_map(&wt->repo->worktree_ref_stores, id);
if (refs)
return refs;
- if (wt->id)
- refs = ref_store_init(the_repository,
- git_common_path("worktrees/%s", wt->id),
+ if (wt->id) {
+ struct strbuf common_path = STRBUF_INIT;
+ strbuf_git_common_path(&common_path, wt->repo,
+ "worktrees/%s", wt->id);
+ refs = ref_store_init(wt->repo, common_path.buf,
REF_STORE_ALL_CAPS);
- else
- refs = ref_store_init(the_repository,
- get_git_common_dir(),
+ strbuf_release(&common_path);
+ } else {
+ refs = ref_store_init(wt->repo, wt->repo->commondir,
REF_STORE_ALL_CAPS);
+ }
if (refs)
- register_ref_store_map(&worktree_ref_stores, "worktree",
- refs, id);
+ register_ref_store_map(&wt->repo->worktree_ref_stores,
+ "worktree", refs, id);
+
return refs;
}