From patchwork Thu Oct 26 09:56:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13437420 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B96DE28E02 for ; Thu, 26 Oct 2023 09:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="ZlSt7Wkp"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jn/rG4w0" Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C74AA196 for ; Thu, 26 Oct 2023 02:56:46 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 03E1C32007CF; Thu, 26 Oct 2023 05:56:45 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 26 Oct 2023 05:56:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1698314205; x=1698400605; bh=AX H4vkAgDBd5Zi4eITQJDs0SX1hr46jyNzVXAzoNK3Y=; b=ZlSt7WkpDmvoELwlca pbVlwdUFZ2AGQHhHOSlccIVG37DEBT4nsBJhyw1PWgXYJqasP9MrAgS/+MMF+z/j WK0QWe5AMIbob8uIGESpGwQ6Un9qsm+tVj9XmKYnoJqsPhufPXANAw7sOkZds7OJ nIju/7AfMIcE5ZHk4qSdeG+jyQjKqq2tuK3e9cHp7BbrYTk/nIy0BC2mSSCPLUF4 hymbLbViJPKIIuiivngzezsiQ057QhE1j6XKbaLOFKfhZYSWjtEplj/Jx/OufVrr v88hgxU9GejOMU/3wYRtFJRvx3wkkEhgPXE83PzLpp993zMGH1qU49fF7XXyGj1Y CNFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1698314205; x=1698400605; bh=AXH4vkAgDBd5Z i4eITQJDs0SX1hr46jyNzVXAzoNK3Y=; b=jn/rG4w0ugns27pgxwEWxkzbMOvQ1 /FcFVtm4q5HkWK0xbY9Rhu5FHbWN7yqX7jF7fa23USAKXN17tcRrL+EOlmMlmggm 4VeF5DH8LuVsPL5R6mAGhd2H2RFP+nfRKy0ucQ5IQEWfpHfB4HJmoL2v+Eo26+kM 5n72XdZSlecTmtyPmS2k18ozl2OokvOFq3X3ML0liRa0YayyChDZG6Pm+l/HOEbz tUl8+2GJmEOrmMx0tg2XZhYmv1PttNQKMkq51uREPyJheMH+4qr7/iUHzQb3gab+ JJmEGxdg9Ep9txKpfijYLr5km9Yj4pnhn4xuQSQBR8/N0WWW3idO8y0Hw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrledvgddvvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleffteen ucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 26 Oct 2023 05:56:44 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 08adc2b2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 Oct 2023 09:56:35 +0000 (UTC) Date: Thu, 26 Oct 2023 11:56:42 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Eric Sunshine , Han-Wen Nienhuys Subject: [PATCH v2 06/12] builtin/show-ref: stop using global variable to count matches Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: When passing patterns to git-show-ref(1) we're checking whether any reference matches -- if none does, we indicate this condition via an unsuccessful exit code. We're using a global variable to count these matches, which is required because the counter is getting incremented in a callback function. But now that we have the `struct show_ref_data` in place, we can get rid of the global variable and put the counter in there instead. Signed-off-by: Patrick Steinhardt --- builtin/show-ref.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 90481c58492..c30c01785cc 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -18,7 +18,7 @@ static const char * const show_ref_usage[] = { NULL }; -static int deref_tags, show_head, tags_only, heads_only, found_match, verify, +static int deref_tags, show_head, tags_only, heads_only, verify, quiet, hash_only, abbrev; static void show_one(const char *refname, const struct object_id *oid) @@ -50,6 +50,7 @@ static void show_one(const char *refname, const struct object_id *oid) struct show_ref_data { const char **patterns; + int found_match; }; static int show_ref(const char *refname, const struct object_id *oid, @@ -78,7 +79,7 @@ static int show_ref(const char *refname, const struct object_id *oid, } match: - found_match++; + data->found_match++; show_one(refname, oid); @@ -187,7 +188,7 @@ static int cmd_show_ref__patterns(const char **patterns) } else { for_each_ref(show_ref, &show_ref_data); } - if (!found_match) + if (!show_ref_data.found_match) return 1; return 0;