diff options
Diffstat (limited to 'worktree.c')
-rw-r--r-- | worktree.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/worktree.c b/worktree.c index 5ae54f0091..360ba417e8 100644 --- a/worktree.c +++ b/worktree.c @@ -191,14 +191,19 @@ const char *get_worktree_git_dir(const struct worktree *wt) return git_common_path("worktrees/%s", wt->id); } -char *find_shared_symref(const char *symref, const char *target) +const struct worktree *find_shared_symref(const char *symref, + const char *target) { - char *existing = NULL; + const struct worktree *existing = NULL; struct strbuf path = STRBUF_INIT; struct strbuf sb = STRBUF_INIT; - struct worktree **worktrees = get_worktrees(); + static struct worktree **worktrees; int i = 0; + if (worktrees) + free_worktrees(worktrees); + worktrees = get_worktrees(); + for (i = 0; worktrees[i]; i++) { strbuf_reset(&path); strbuf_reset(&sb); @@ -211,14 +216,13 @@ char *find_shared_symref(const char *symref, const char *target) } if (!strcmp(sb.buf, target)) { - existing = xstrdup(worktrees[i]->path); + existing = worktrees[i]; break; } } strbuf_release(&path); strbuf_release(&sb); - free_worktrees(worktrees); return existing; } |