aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-01-26 08:54:46 -0800
committerJunio C Hamano <gitster@pobox.com>2024-01-26 08:54:46 -0800
commitdc8ce995a2ad203ffb5ef335682b64da955e645a (patch)
tree5fb18d234cc42148bbd37754477fded0bff1cca4 /worktree.c
parentf95bafbaed2d9f9c891e04c3680c1aa0da30629e (diff)
parent8f4c00de954f809e83daf8b1425de82561f3721e (diff)
downloadgit-dc8ce995a2ad203ffb5ef335682b64da955e645a.tar.gz
Merge branch 'ps/worktree-refdb-initialization'
Instead of manually creating refs/ hierarchy on disk upon a creation of a secondary worktree, which is only usable via the files backend, use the refs API to populate it. * ps/worktree-refdb-initialization: builtin/worktree: create refdb via ref backend worktree: expose interface to look up worktree by name builtin/worktree: move setup of commondir file earlier refs/files: skip creation of "refs/{heads,tags}" for worktrees setup: move creation of "refs/" into the files backend refs: prepare `refs_init_db()` for initializing worktree refs
Diffstat (limited to 'worktree.c')
-rw-r--r--worktree.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/worktree.c b/worktree.c
index dbc670d369..b02a05a74a 100644
--- a/worktree.c
+++ b/worktree.c
@@ -12,18 +12,23 @@
#include "wt-status.h"
#include "config.h"
+void free_worktree(struct worktree *worktree)
+{
+ if (!worktree)
+ return;
+ free(worktree->path);
+ free(worktree->id);
+ free(worktree->head_ref);
+ free(worktree->lock_reason);
+ free(worktree->prune_reason);
+ free(worktree);
+}
+
void free_worktrees(struct worktree **worktrees)
{
int i = 0;
-
- for (i = 0; worktrees[i]; i++) {
- free(worktrees[i]->path);
- free(worktrees[i]->id);
- free(worktrees[i]->head_ref);
- free(worktrees[i]->lock_reason);
- free(worktrees[i]->prune_reason);
- free(worktrees[i]);
- }
+ for (i = 0; worktrees[i]; i++)
+ free_worktree(worktrees[i]);
free (worktrees);
}
@@ -75,8 +80,8 @@ static struct worktree *get_main_worktree(int skip_reading_head)
return worktree;
}
-static struct worktree *get_linked_worktree(const char *id,
- int skip_reading_head)
+struct worktree *get_linked_worktree(const char *id,
+ int skip_reading_head)
{
struct worktree *worktree = NULL;
struct strbuf path = STRBUF_INIT;