diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-05-17 10:18:44 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-05-17 10:33:38 -0700 |
| commit | dc7fb4f72c2e39ffbb98aee55ad7ea4c3f8e12fc (patch) | |
| tree | ac6fe8d4aaff5edae0cf79545f9cdce1be9e8590 /refs.c | |
| parent | refs: refactor `resolve_gitlink_ref()` to accept a repository (diff) | |
| download | git-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.c | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -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; } |
