On Tue, May 10, 2016 at 10:17 AM, Nguyễn Thái Ngọc Duy
<[email protected]> wrote:
> So far we haven't needed to identify an existing worktree from command
> line. Future commands such as lock or move will need it. There are of
> course other options for identifying a worktree, for example by branch
> or even by internal id. They may be added later if proved useful.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]>
> ---
> diff --git a/worktree.c b/worktree.c
> @@ -222,6 +222,22 @@ const char *get_worktree_git_dir(const struct worktree
> *wt)
> +struct worktree *find_worktree_by_path(struct worktree **list,
> + const char *path_)
> +{
> + char *path = xstrdup(real_path(path_));
> + struct worktree *wt = NULL;
> +
> + while (*list) {
> + wt = *list++;
> + if (!fspathcmp(path, real_path(wt->path)))
> + break;
> + wt = NULL;
> + }
> + free(path);
> + return wt;
> +}
Very slightly shorter and perhaps idiomatic (but not at all worth a re-roll):
for (; *list; list++)
if (!fspathcmp(path, real_path((*list)->path)))
break;
free(path);
return *list;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html