From d3b9ac07eb44974bb619d71fc6c81c9f2036b96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 22 Apr 2016 20:01:27 +0700 Subject: worktree.c: make find_shared_symref() return struct worktree * MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gives the caller more information and they can answer things like, "is it the main worktree" or "is it the current worktree". The latter question is needed for the "checkout a rebase branch" case later. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- worktree.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'worktree.c') diff --git a/worktree.c b/worktree.c index 5ae54f009..360ba417e 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; } -- cgit v1.2.1