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>
This commit is contained in:

committed by
Junio C Hamano

parent
69dfe3b942
commit
d3b9ac07eb
14
worktree.c
14
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user