From: Junio C Hamano <gitster@pobox.com> To: "Carlos L." <00xc@protonmail.com> Cc: Paul Eggert <eggert@cs.ucla.edu>, "Carlos L. via GitGitGadget" <gitgitgadget@gmail.com>, git@vger.kernel.org, GNU grep developers <grep-devel@gnu.org> Subject: Re: [PATCH] grep: add --max-count command line option Date: Mon, 16 May 2022 08:36:09 -0700 [thread overview] Message-ID: <xmqq1qwt5w2e.fsf@gitster.g> (raw) In-Reply-To: <MHNbacVw7D6ZU3OJvgIqqRMu70HlgYIYQPduUEUnzWCqkGUsUGRLopGGWj-CbyjNilDcUfLB6elfSRgDOaob9cPpjeAf-I6xuMArQZ0y3io=@protonmail.com> (Carlos L.'s message of "Mon, 16 May 2022 08:38:05 +0000") "Carlos L." <00xc@protonmail.com> writes: >> Even if we want to handle the zero just like you do, I think this patch >> needs a few tests. We should make sure to test the 0-case (whatever we >> end up wanting it to behave like), and probably the "suppress an earlier >> -m by giving --no-max-count" case. It also seems wise to set up some >> test scenario where there are several files involved so that we can see >> that we don't just print the first m matches globally, but that the >> counter is really handled per file. > > This seems sound. Is there any documentation on how to write tests for git? t/README and Documentation/MyFirstContribution would be two good places to start. >> 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. > > I would favor treating it as an error. As mentioned above, using 0 > to describe "unlimited matches" (e.g. the default) is my > preference, but I am willing to concede if someone can think of a > good use for `-m 0`. With Devil's advocate hat on. "GNU grep has been doing so for the past 20 years and existing users of the command expects '-m 0' to behave that way" is a good enough reason, especially if '-m 0' is not the only possible way to say "unlimited". > Also, from the implementation side (although > not as important) it looks better: if we allow negative values, we > need to distinguish between -1 (unlimited) and -4 (display error > to user, probably) If we are going to document "you can pass a negative value to explicitly say 'unlimited', which is a useful way to countermand another `-m <num>` that appear earlier on the command line", then -1 and -4 would equally be 'unlimited' and there is no need to distinguish anything. Devil's advocate hat off. I personally do not mind if "-m <non-positive>" means "unlimited", as long as that is clearly documented and tested, but for long time "GNU grep" users "-m 0" might appear surprising (not necessarily because they would find that the "-m 0" that immediately fails is useful, but because the behaviour is deliberately made different). Thanks.
next prev parent reply other threads:[~2022-05-16 15:37 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-12 13:20 Carlos L. via GitGitGadget 2022-05-14 18:16 ` Martin Ågren 2022-05-16 5:57 ` Junio C Hamano 2022-05-16 7:28 ` Paul Eggert 2022-05-16 8:38 ` Carlos L. 2022-05-16 15:36 ` Junio C Hamano [this message] 2022-05-17 5:53 ` Paul Eggert 2022-05-16 15:18 ` Junio C Hamano 2022-06-20 15:49 Carlos L. via GitGitGadget 2022-06-20 15:57 ` Paul Eggert 2022-06-20 16:25 ` Carlos L. 2022-06-20 16:32 ` Paul Eggert
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=xmqq1qwt5w2e.fsf@gitster.g \ --to=gitster@pobox.com \ --cc=00xc@protonmail.com \ --cc=eggert@cs.ucla.edu \ --cc=git@vger.kernel.org \ --cc=gitgitgadget@gmail.com \ --cc=grep-devel@gnu.org \ --subject='Re: [PATCH] grep: add --max-count command line option' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://80x24.org/mirrors/git.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).