From patchwork Fri Nov 10 10:01:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13452282 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 3A5F713FF1 for ; Fri, 10 Nov 2023 10:01:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="FVh00FSu"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="vGK/IDr1" Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4C5926303 for ; Fri, 10 Nov 2023 02:01:28 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 0B18B32009A4; Fri, 10 Nov 2023 05:01:26 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 10 Nov 2023 05:01:27 -0500 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=1699610486; x=1699696886; bh=bB vCWDmr7Ynf0mpKg0vZjKVBHEDpefSPoVzZxbkfxJw=; b=FVh00FSupWWnRxn8U9 pNsX+OTryGd/s3sdwBbs+4lPJl4wng/LBa2iNQBToL1AO+BCaPGHxDCtvRJqeMqF HXyBbGFQGGRqYg1XNTQWS2cnyk5Z0yc1Avmuv1UKQI+Eg48IE/y3oTMfh6p8hTeE X1OcKJoC0ZRtBYB40YibcbtSYw1DYqn6fCwWdlvVQdAtVuzlU8Ne/6tukAPwiQwy hhZytB3vxTY/ui9/8LVsiywMLapZVTtF+5UGaHmfsRngiv8T2ZS6QRYlbIflivRS jegyw8/yvRZDD3Hg7q0Tpuy9tSaWXfa22RJ+YtCW+7sqSXpH2UcwX9AY/cibd+f7 IhVg== 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=1699610486; x=1699696886; bh=bBvCWDmr7Ynf0 mpKg0vZjKVBHEDpefSPoVzZxbkfxJw=; b=vGK/IDr17YEtfCOSpxrEtebSTbSm+ gWNcXhYtLMaGJotCKtpg+Eyerbs8wahE7+XsIP8p289YDrOI1QTAR0xVDo7bd+sS /4deveO0MWPubaDQp2IUT0+197gOI0RVYmiz2IrW1tjOVlGYEPAEiyp5K64sMCpz MXGaVfO56JYtFevlEbgk095gNlEAy6U63871LS9WFUOI7ta8HesoTuWPAXGGkM/E ha7l0qkC/ydn3B08iFHmh+Ge/7Cl9/8It6usHjL8UrwyVkWaW0/hOD11ZVe6OT/j dHrDb14jloXLgACXX5brY+uMzzlyryGbbWxKLTlSMPD7sHeNUwBylAHqg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedruddvfedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 Nov 2023 05:01:25 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 279f5469 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 Nov 2023 10:00:56 +0000 (UTC) Date: Fri, 10 Nov 2023 11:01:24 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v2 3/4] contrib/subtree: convert subtree type check to use case statement Message-ID: <761cde1b341e22b20063ce3baa6b70d80aa05168.1699609940.git.ps@pks.im> 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: The `subtree_for_commit ()` helper function asserts that the subtree identified by its parameters are either a commit or tree. This is done via the `-o` parameter of test, which is discouraged. Refactor the code to instead use a switch statement over the type. Despite being aligned with our coding guidelines, the resulting code is arguably also easier to read. Signed-off-by: Patrick Steinhardt --- contrib/subtree/git-subtree.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 8af0a81ba3f..3028029ac2d 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -641,10 +641,16 @@ subtree_for_commit () { while read mode type tree name do assert test "$name" = "$dir" - assert test "$type" = "tree" -o "$type" = "commit" - test "$type" = "commit" && continue # ignore submodules - echo $tree - break + + case "$type" in + commit) + continue;; # ignore submodules + tree) + echo $tree + break;; + *) + die "fatal: tree entry is of type ${type}, expected tree or commit";; + esac done || exit $? }