diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2016-04-22 20:01:27 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-04-22 14:09:37 -0700 |
commit | d3b9ac07eb44974bb619d71fc6c81c9f2036b96c (patch) | |
tree | ff18f60eb58addac7e2a2008d4d9f1aa43ad3b30 /worktree.c | |
parent | 69dfe3b9420eb2a7f479a0a4cad663111af2b1f9 (diff) | |
download | git-d3b9ac07eb44974bb619d71fc6c81c9f2036b96c.tar.gz |
worktree.c: make find_shared_symref() return struct worktree *
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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; } |