Re: [PATCH 04/17] ls-tree: convert show_recursive to use the pathspec struct interface
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Dec 7, 2016, 10:38 UTC
- Message-ID
- <CACsJy8DELy5JsJmcyDtwT-O9qGa9+hR1UfcKWRY1cmCnTALixA@mail.gmail.com>
- In-Reply-To
- <1481061106-117775-5-git-send-email-bmwill@google.com>
On Wed, Dec 7, 2016 at 4:51 AM, Brandon Williams <bmwill@google.com> wrote:
> Convert 'show_recursive()' to use the pathspec struct interface from > using the '_raw' entry in the pathspec struct.
Slightly off-topic (sorry, but you made me look at this code! :D), could you update the magic_mask argument of parse_pathspec() in this file to PATHSPEC_ALL_MAGIC & ~(PATHSPEC_FROMTOP | PATHSPEC_LITERAL)? It makes sure all future magic will be caught as unsupported (and I think Stefan is adding one, but understandably he did not find this code).
I think it's in the spirit of renaming _raw to match too. By limiting magic to fromtop and literal, we are sure match can only be path and nothing else, which is good because this show_recursive can't handle anything else either.
Show 47 quoted lines
>
> Signed-off-by: Brandon Williams <bmwill@google.com>
> ---
> builtin/ls-tree.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
> index 0e30d86..e0f4307 100644
> --- a/builtin/ls-tree.c
> +++ b/builtin/ls-tree.c
> @@ -31,21 +31,18 @@ static const char * const ls_tree_usage[] = {
>
> static int show_recursive(const char *base, int baselen, const char *pathname)
> {
> - const char **s;
> + int i;
>
> if (ls_options & LS_RECURSIVE)
> return 1;
>
> - s = pathspec._raw;
> - if (!s)
> + if (!pathspec.nr)
> return 0;
>
> - for (;;) {
> - const char *spec = *s++;
> + for (i = 0; i < pathspec.nr; i++) {
> + const char *spec = pathspec.items[i].match;
> int len, speclen;
>
> - if (!spec)
> - return 0;
> if (strncmp(base, spec, baselen))
> continue;
> len = strlen(pathname);
> @@ -59,6 +56,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname)
> continue;
> return 1;
> }
> + return 0;
> }
>
> static int show_tree(const unsigned char *sha1, struct strbuf *base,
> --
> 2.8.0.rc3.226.g39d4020
>-- Duy