Web lists-archives.com

Re: [PATCH] grep: provide a noop --recursive option




René Scharfe <l.s.r@xxxxxx> writes:

>
> 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.