Re: [PATCH 1/5] worktree.c: add find_worktree_by_path()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 10, 2016 at 10:17 AM, Nguyễn Thái Ngọc Duy
<pclouds@xxxxxxxxx> 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 <pclouds@xxxxxxxxx>
> ---
> 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 majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]