Re: [PATCH] grep: provide a noop --recursive option
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Oct 5, 2018, 12:49 UTC
- Message-ID
- <87h8i0h83g.fsf@evledraar.gmail.com>
- In-Reply-To
- <xmqqmurszu2d.fsf@gitster-ct.c.googlers.com>
On Fri, Oct 05 2018, Junio C Hamano wrote:
Show 31 quoted lines
> René Scharfe <l.s.r@web.de> 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.FWIW I'm not going to carry this series forward, I wrote it more as a "here's how this could be done". But if Christoph / René wants to hack on it...