Re: [PATCH v3 2/6] worktree.c: find_worktree() learns to identify worktrees by basename
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Jun 3, 2016, 11:11 UTC
- Message-ID
- <CACsJy8BF_KKXdMNW_aOs522wBbW9BQhbrZ_0hx+f2MCW-VPUzg@mail.gmail.com>
- In-Reply-To
- <xmqqfusvv8lq.fsf@gitster.mtv.corp.google.com>
On Thu, Jun 2, 2016 at 11:49 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 24 quoted lines
> +static struct worktree *find_worktree_by_basename(struct worktree **list,
> + const char *base_name)
> +{
> + struct worktree *found = NULL;
> + int nr_found = 0;
> +
> + for (; *list && nr_found < 2; list++) {
> + char *path = xstrdup((*list)->path);
> + if (!fspathcmp(base_name, basename(path))) {
> + found = *list;
> + nr_found++;
> + }
> + free(path);
> + }
> + return nr_found == 1 ? found : NULL;
> +}
>
>
>> If we always split at '/' boundary though (e.g. "abc/def/ghi",
>> "def/ghi" or "ghi" but never "ef/ghi") then it should be ok.
>
> Does "basename()" used here know '/' and '\' can both be a directory
> separator, or does worktree->path have a normalized representation
> of the path, i.e. '/' is the only directory separator?basename() does (or I think so because Windows has its own version). worktree->path always uses '/' but the command line option can come with either '/' or '\'. Probably safest to accept both.
-- Duy