]> git.ipfire.org Git - thirdparty/git.git/blobdiff - worktree.c
worktree: expose interface to look up worktree by name
[thirdparty/git.git] / worktree.c
index cc34a3419b4c68ebe89290ae9108fe1de3cff1ea..5d5dd466096de172f783cc0cf18daaadae6703c2 100644 (file)
 #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;