From patchwork Thu Nov 9 10:53:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13450926 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 B6ABE199AF for ; Thu, 9 Nov 2023 10:53:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Na7iqCUn"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QTjR4kJG" Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F889D41 for ; Thu, 9 Nov 2023 02:53:43 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id ABF585C031F; Thu, 9 Nov 2023 05:53:42 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 09 Nov 2023 05:53:42 -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=1699527222; x=1699613622; bh=hb prfUsjMxqU4r81HY1SLgu3wF4R+Tm+SjF+3YioTEA=; b=Na7iqCUnmUcNFBsQ50 ocBKA5XU2rwXBRw0Lk1vc1Y7O6ooxoiX+mgLV3T9OnfFQk+ebSJlv65hpuEht/1f lCOmDQZpdJxn79j2+G17o8gq8cXRkQGzDgsiaFdT5BymiA/hk88KxEvyQ8q/cXX3 BfsstOqzwV7TXuPT/0PsRcNwIjmZ0fhAjSsvJ8kwSa6+P5rJq0zOmk9lSzcui2/x 6rnvcz5JYsJS/JbYMSe1Dy5gcYJmxo8Mya74QdonTdgywPyNDedrHtgTylARp7tH IpAZj3con0AbIJZ2cy0Y1VU3t2VKL6nWgfE7SW4dYwMJc1AwluYHQuRqsmScE+bR YuGw== 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=1699527222; x=1699613622; bh=hbprfUsjMxqU4 r81HY1SLgu3wF4R+Tm+SjF+3YioTEA=; b=QTjR4kJGUgoMiobAKIM/5K00yQ8lm 7vZiTi/NZdxvszSwA/Y60vU8GLpZm/eh04ywJ122Jt4GYd30RpP8gyzxNISW1L4j OzN07uRyzVBDfdZKQZ3BgEjC8ZyfZPzR+1lWWOW9TR0tgOuPSBgyzaGOCjgK6ADL Wy5UhXUjzU18KitVwjIa4maqrGm0NmZUuirs31wlJfmSjKrUyB8ATT+MmwtlhD46 m0eNO1DU2dJwTbyBlxE/NpGBZX38JGkJ3HUattVZPiFk7+4cXW9o3tFJEmNFUcnh Faef5xVZze6B4BoSk3zSJsr72wR4qnOOmuctXnxL4RmjFA+Y1PCHLB+SQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedruddvuddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 9 Nov 2023 05:53:41 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e9d1b987 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 9 Nov 2023 10:53:13 +0000 (UTC) Date: Thu, 9 Nov 2023 11:53:39 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 3/4] contrib/subtree: convert subtree type check to use case statement Message-ID: <7c54d9070fac15b8f0504251d920d0e1fc1fb1f4.1699526999.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 $? }