Re: [PATCH 08/19] pathspec: mark wildcard pathspecs from the beginning
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
Show 22 quoted lines
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> diff --git a/dir.c b/dir.c
> index 646c79f..0987d0c 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -1089,8 +1089,17 @@ int init_pathspec(struct pathspec *pathspec, const char **paths)
> pathspec->items = xmalloc(sizeof(struct pathspec_item)*pathspec->nr);
> for (i = 0; i < pathspec->nr; i++) {
> struct pathspec_item *item = pathspec->items+i;
> -
> - item->len = strlen(paths[i]);
> + const char *path = paths[i];
> +
> + item->len = strlen(path);
> + item->has_wildcard = !no_wildcard(path);
> + if (item->has_wildcard) {
> + pathspec->has_wildcard = 1;
> + item->prefix_len = 0;
> + while (item->prefix_len < item->len &&
> + strchr("*?[{\\", path[item->prefix_len]) == NULL)
> + item->prefix_len++;
> + }Would it make sense to use strcspn(3) here?
Show 5 quoted lines
> }
> return 0;
> }
> --
> 1.7.3.3.476.g10a82