[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] grep: add --max-count command line option

From: Paul Eggert
Subject: Re: [PATCH] grep: add --max-count command line option
Date: Mon, 16 May 2022 00:28:16 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1

On 5/15/22 22:57, Junio C Hamano wrote:

It indeed is curious why GNU grep chose to immediately exit with 1
when "-m 0" was given,

As I vaguely recall, if "-m 1" stops before "-m 2" does, then the idea was that it's reasonable for "-m 0" to stop before "-m 1" does, and the logical place to stop is right at the start, before any matches are found (i.e., exit with status 1).

What would be more useful for 'grep -m 0' to do? (Sorry, I came into this conversation just now.) Perhaps GNU 'grep -m 0' should change, if there's something better for it to do.

What "git grep -m -1" should do?  IIRC, OPT_INTEGER is for signed
integer but the new .max_count member, as well as the existing
"count" that is compared with it, are of "unsigned" type.  Either
erroring out or treating it as unlimited is probably fine, but
whatever we do, we should document and have a test for it.

'grep -m -1' treats the count as being unlimited, but this isn't documented and (from the code) appears to be accidental. It'd make sense for it to be documented.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]