From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 9B3DC1F4D7 for ; Wed, 22 Jun 2022 06:42:19 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; secure) header.d=protonmail.com header.i=@protonmail.com header.b="x1bUp+VY"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231675AbiFVGmF (ORCPT ); Wed, 22 Jun 2022 02:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbiFVGmE (ORCPT ); Wed, 22 Jun 2022 02:42:04 -0400 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 737C83464E for ; Tue, 21 Jun 2022 23:42:03 -0700 (PDT) Date: Wed, 22 Jun 2022 06:41:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1655880119; x=1656139319; bh=7anMuSCzcDYJfwbD4sigq67egisfhEKwLJkTQkRww84=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:Feedback-ID:From:To:Cc:Date:Subject:Reply-To: Feedback-ID:Message-ID; b=x1bUp+VYy0FhTXl/R+03e4+g7ulkohHInx/jjdgsCRRBsfhYb5C5zDZXT433D/EnA 65XUDKmTL/WM8bRamNDk7NIoMEQLFOGwc2my1wxNAOoxWK7O+RMC3xavt5Ejo4oJcY /68mseLYV1imBlgKVS85l3ykCgPop5yJ9/oOkoAZQ1968Hd+NpPnE3CzuR2S2dv1bf O17b1dTVO+BCSVycWApIwDinGM9hkdNS3k5EuNyE8Fuuq2imjVHl1HO3Z+F9AEGzJB xGKhuGiHaheQVPeFANXOtTlTiJrNvlWBy1TEcKgHtAQCbAEEM5PD4X38KvEXfZalip h6u05hkO+tUag== To: Junio C Hamano From: "Carlos L." <00xc@protonmail.com> Cc: "Carlos L. via GitGitGadget" , git@vger.kernel.org, =?utf-8?Q?Martin_=C3=85gren_=5B_=5D?= , "Paul Eggert [ ]" Reply-To: "Carlos L." <00xc@protonmail.com> Subject: Re: [PATCH v2] grep: add --max-count command line option Message-ID: In-Reply-To: References: Feedback-ID: 24333956:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Hi, Just a couple of questions. On Tuesday, June 21st, 2022 at 18:27, Junio C Hamano wr= ote: > "Carlos L. via GitGitGadget" gitgitgadget@gmail.com writes: > > > From: =3D?UTF-8?q?Carlos=3D20L=3DC3=3DB3pez?=3D 00xc@protonmail.com > > > > This patch adds a command line option analogous to that of GNU > > grep(1)'s -m / --max-count, which users might already be used to. > > This makes it possible to limit the amount of matches shown in the > > output while keeping the functionality of other options such as -C > > (show code context) or -p (show containing function), which would be > > difficult to do with a shell pipeline (e.g. head(1)). > > > > Signed-off-by: Carlos L=C3=B3pez 00xc@protonmail.com > > --- > > ... > > Documentation/git-grep.txt | 8 ++++++++ > > builtin/grep.c | 9 +++++++++ > > grep.c | 2 ++ > > grep.h | 2 ++ > > 4 files changed, 21 insertions(+) > > > Tests? Right. Is it OK if I include my test(s) in t/t7810-grep.sh, or should it be= a different/new file? > > diff --git a/grep.c b/grep.c > > index 82eb7da1022..b32ab75cb6b 100644 > > --- a/grep.c > > +++ b/grep.c > > @@ -1686,6 +1686,8 @@ static int grep_source_1(struct grep_opt *opt, st= ruct grep_source *gs, int colle > > bol =3D eol + 1; > > if (!left) > > break; > > + if (opt->max_count !=3D -1 && count =3D=3D opt->max_count) > > + break; > > > I would have written it "if (0 <=3D opt->max_count && ...)". What > > happens when a trickster asks you to do "git grep -m -2"? Fair enough. Since it's already optimized out above, is there any reason we= need to include zero (<=3D)? > I guess what I am getting at is if we are better off saying that > negative means unlimited, instead of special casing -1 like this. I > didn't think it through so it may be perfectly possible that what > you wrote makes more sense than "anything negative is unlimited". > > I dunno. I think you're right, I'll adjust my patch. Best, Carlos