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.
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;
}
ref_store_release(e->value);
strmap_clear(&repo->submodule_ref_stores, 1);
+ strmap_for_each_entry(&repo->worktree_ref_stores, &iter, e)
+ ref_store_release(e->value);
+ strmap_clear(&repo->worktree_ref_stores, 1);
+
repo_clear_path_cache(&repo->cached_paths);
}
*/
struct strmap submodule_ref_stores;
+ /*
+ * A strmap of ref_stores, stored by worktree id, accessible via
+ * `get_worktree_ref_store()`.
+ */
+ struct strmap worktree_ref_stores;
+
/*
* Contains path to often used file names.
*/
strbuf_strip_suffix(&worktree_path, "/.git");
CALLOC_ARRAY(worktree, 1);
+ worktree->repo = the_repository;
worktree->path = strbuf_detach(&worktree_path, NULL);
/*
* NEEDSWORK: If this function is called from a secondary worktree and
strbuf_strip_suffix(&worktree_path, "/.git");
CALLOC_ARRAY(worktree, 1);
+ worktree->repo = the_repository;
worktree->path = strbuf_detach(&worktree_path, NULL);
worktree->id = xstrdup(id);
if (!skip_reading_head)