Re: [PATCH] grep: provide a noop --recursive option
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Oct 5, 2018, 08:17 UTC
- Message-ID
- <xmqqmurszu2d.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <ffc574a9-cf78-2dd5-084a-a6005547d363@web.de>
René Scharfe <l.s.r@web.de> writes:
Show 21 quoted lines
>
> Recognize -r and --recursive as synonyms for --max-depth=-1 for
> compatibility with GNU grep; it's still the default for git grep.
>
> This also adds --no-recursive as synonym for --max-depth=0 for free,
> which is welcome for completeness and consistency.
>
> Fix the description for --max-depth, while we're at it -- negative
> values other than -1 actually disable recursion, i.e. they are
> equivalent to --max-depth=0.
> ...
> diff --git a/builtin/grep.c b/builtin/grep.c
> index 601f801158..f6e127f0bc 100644
> --- a/builtin/grep.c
> +++ b/builtin/grep.c
> @@ -811,6 +811,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
> GREP_BINARY_NOMATCH),
> OPT_BOOL(0, "textconv", &opt.allow_textconv,
> N_("process binary files with textconv filters")),
> + OPT_SET_INT('r', "recursive", &opt.max_depth,
> + N_("search in subdirectories (default)"), -1),Wow.
I didn't think of this trick to let OPT_SET_INT() to grok --no-* and set the variable to 0. Being able to do this without a custom callback is certainly very nice.
The patch looks good.
Thanks.