From patchwork Fri Nov 10 10:01:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13452280 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 94B00134A0 for ; Fri, 10 Nov 2023 10:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="pOXbJICv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JR6X0RR5" Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14A0226304 for ; Fri, 10 Nov 2023 02:01:20 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id BA6E43200A23; Fri, 10 Nov 2023 05:01:18 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 10 Nov 2023 05:01:19 -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=1699610478; x=1699696878; bh=Es kPxpgrVZXQQtQ//2KPu4zLi4hcig++T5tD+AE4FQA=; b=pOXbJICvUx0KyLtF/O DEqv6TyF4TMhXbdGOZNa6j24oGMNZamFJ5m7hrAc9dYT66NAFxDsWaPiE1wKYGDW RjGQAOmR+WVgkT2Tgi5yBAY+LUJcmavrOwzBMMQQw7BReYId/01scFpk0kAMvrJV bs0Zu51CS+Kh/Ut/qiJMdnMtmf/R680T/wedBvky4ZiNssPhESEbJpe9z5RP+uos 59BTh5jHCTFiTpJuDkmvmS0xF1qjF15GTSaqHaPQjvr8eRNxDow+FvmljvK/rKdA ObmUGsPjDZRfWorgB7FNRtyy58jpt+Eq+fPXyZJfyt6RDYGLh0TBxE2HzTxS3MKL JAoQ== 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=1699610478; x=1699696878; bh=EskPxpgrVZXQQ tQ//2KPu4zLi4hcig++T5tD+AE4FQA=; b=JR6X0RR5XFd81Egmp6L0GuG84ji6R 7vEUSClnmCSsKn8vE6888sW6tZZwTPTU1gKwBJvRcRlkv+Q9YuLJHv914h+d1KL9 Hf4PjIQZfT9TEBJdDhbamkTeTnG0OaC/9Xm1A+/dcmZIHBE2hAfiTyuwq/eov+ML 0Joua+SUzIJEPtYmUOI7oNbAfutGTnufkI/tErn4JAcZYuFDZRktn15uhwatj/7h CCFTn7UhTRVZwhRJeP0Sjd5fzrbN7CVFI9CVAdkcYKc5qd3IabKkPeibia85uQ0V cc3PSpIsffbPeSFIRIN3nwB+yQJ6eCLTR7+Vkncb9udpBpD1nzj3ajcjQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedruddvfedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 Nov 2023 05:01:17 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 9d803de4 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 Nov 2023 10:00:47 +0000 (UTC) Date: Fri, 10 Nov 2023 11:01:15 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v2 1/4] global: convert trivial usages of `test -a/-o ` Message-ID: <2967c8ebb460934eb4aaaaebe5941bff643d4a94.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: Our coding guidelines say to not use `test` with `-a` and `-o` because it can easily lead to bugs. Convert trivial cases where we still use these to instead instead concatenate multiple invocations of `test` via `&&` and `||`, respectively. While not all of the converted instances can cause ambiguity, it is worth getting rid of all of them regardless: - It becomes easier to reason about the code as we do not have to argue why one use of `-a`/`-o` is okay while another one isn't. - We don't encourage people to use these expressions. Signed-off-by: Patrick Steinhardt --- GIT-VERSION-GEN | 2 +- configure.ac | 2 +- contrib/subtree/git-subtree.sh | 4 ++-- t/perf/perf-lib.sh | 2 +- t/perf/run | 9 +++++---- t/valgrind/valgrind.sh | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index e54492f8271..7246ab7c78c 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -11,7 +11,7 @@ LF=' if test -f version then VN=$(cat version) || VN="$DEF_VER" -elif test -d ${GIT_DIR:-.git} -o -f .git && +elif { test -d "${GIT_DIR:-.git}" || test -f .git; } && VN=$(git describe --match "v[0-9]*" HEAD 2>/dev/null) && case "$VN" in *$LF*) (exit 1) ;; diff --git a/configure.ac b/configure.ac index 276593cd9dd..d1a96da14eb 100644 --- a/configure.ac +++ b/configure.ac @@ -94,7 +94,7 @@ AC_DEFUN([GIT_PARSE_WITH_SET_MAKE_VAR], [AC_ARG_WITH([$1], [AS_HELP_STRING([--with-$1=VALUE], $3)], if test -n "$withval"; then - if test "$withval" = "yes" -o "$withval" = "no"; then + if test "$withval" = "yes" || test "$withval" = "no"; then AC_MSG_WARN([You likely do not want either 'yes' or 'no' as] [a value for $1 ($2). Maybe you do...?]) fi diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index e0c5d3b0de6..43b5fec7320 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -489,13 +489,13 @@ find_existing_splits () { ;; END) debug "Main is: '$main'" - if test -z "$main" -a -n "$sub" + if test -z "$main" && test -n "$sub" then # squash commits refer to a subtree debug " Squash: $sq from $sub" cache_set "$sq" "$sub" fi - if test -n "$main" -a -n "$sub" + if test -n "$main" && test -n "$sub" then debug " Prior: $main -> $sub" cache_set $main $sub diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh index e7786775a90..b952e5024b4 100644 --- a/t/perf/perf-lib.sh +++ b/t/perf/perf-lib.sh @@ -31,7 +31,7 @@ unset GIT_CONFIG_NOSYSTEM GIT_CONFIG_SYSTEM="$TEST_DIRECTORY/perf/config" export GIT_CONFIG_SYSTEM -if test -n "$GIT_TEST_INSTALLED" -a -z "$PERF_SET_GIT_TEST_INSTALLED" +if test -n "$GIT_TEST_INSTALLED" && test -z "$PERF_SET_GIT_TEST_INSTALLED" then error "Do not use GIT_TEST_INSTALLED with the perf tests. diff --git a/t/perf/run b/t/perf/run index 34115edec35..486ead21980 100755 --- a/t/perf/run +++ b/t/perf/run @@ -91,10 +91,10 @@ set_git_test_installed () { run_dirs_helper () { mydir=${1%/} shift - while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do + while test $# -gt 0 && test "$1" != -- && test ! -f "$1"; do shift done - if test $# -gt 0 -a "$1" = --; then + if test $# -gt 0 && test "$1" = --; then shift fi @@ -124,7 +124,7 @@ run_dirs_helper () { } run_dirs () { - while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do + while test $# -gt 0 && test "$1" != -- && test ! -f "$1"; do run_dirs_helper "$@" shift done @@ -180,7 +180,8 @@ run_subsection () { GIT_PERF_AGGREGATING_LATER=t export GIT_PERF_AGGREGATING_LATER - if test $# = 0 -o "$1" = -- -o -f "$1"; then + if test $# = 0 || test "$1" = -- || test -f "$1" + then set -- . "$@" fi diff --git a/t/valgrind/valgrind.sh b/t/valgrind/valgrind.sh index 669ebaf68be..9fbf90cee7c 100755 --- a/t/valgrind/valgrind.sh +++ b/t/valgrind/valgrind.sh @@ -23,7 +23,7 @@ memcheck) VALGRIND_MAJOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*\([0-9]*\)') VALGRIND_MINOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*[0-9]*\.\([0-9]*\)') test 3 -gt "$VALGRIND_MAJOR" || - test 3 -eq "$VALGRIND_MAJOR" -a 4 -gt "$VALGRIND_MINOR" || + ( test 3 -eq "$VALGRIND_MAJOR" && test 4 -gt "$VALGRIND_MINOR" ) || TOOL_OPTIONS="$TOOL_OPTIONS --track-origins=yes" ;; *) From patchwork Fri Nov 10 10:01:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13452281 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 93E4E134D5 for ; Fri, 10 Nov 2023 10:01:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="MJ7I5jME"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="JMKNhIfM" Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EA6326306 for ; Fri, 10 Nov 2023 02:01:25 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id D666632009A4; Fri, 10 Nov 2023 05:01:22 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Fri, 10 Nov 2023 05:01:23 -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=1699610482; x=1699696882; bh=tU Gb48h9yIi0W+VG60IKRomj8PiRbCKVhwKoWk7G+OM=; b=MJ7I5jMEIG85FsgtO7 yFSmsOFf11fTpc009tLDKUCESYPe4IaXgR+ce1gmEzBEaa+JxJo6OGG+z5Y8beBo JE/t5cvi0jyz9lMIr58orYwrtD6YP9t1cxw7KUOq/LA20nZbbbGYcuiOjuI3i++e CrjTPfwLyPyps4hnkJXDfEKwAo/s5N3XBg0Bs8IWL04PZpr0bo+qL2LSwMYSbzYd bbO1p32NtE3IfBwn9REGaNMK5L9+mtWEBEtHaNlVS6FiqZrTnC3JxfNsiqNc28al ESZe3BZSZb2iDaLg/Smyo4CHvYgyMmzb88ZHBB/pWMQ8asRsNev6S+SU/aPvkeNY sF5A== 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=1699610482; x=1699696882; bh=tUGb48h9yIi0W +VG60IKRomj8PiRbCKVhwKoWk7G+OM=; b=JMKNhIfMxrC6PHMGqxt4mlhbr6D// YW989q/wdnO/ckwa715a3K4uE3UKrSy/ZIXXrJf+1aF0N+x8IK/tgdagZPT39wg7 cE+FLTbf936PYDp89oLdf1kRdIqjGwIfjox/I+llTOMkjd5vKgZnQcTu4KoFZV8g kyzc3bJYlcziYZF1XS280s9aB8A+BE1J1XTMUIc2Re4PahYwGTBSFKDjygYMMvF7 B4UWMmOw8cO1JtE9yEhIJIHC9FQnCNiUGTRzBL22f5ZTtYkXHDuirho48KOeN0zW uioetEVJ5U8dEAtbverRaJ//2fg7TvOUysNhA7s6Rhs6Gm1EryNSTy/PA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedruddvfedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 10 Nov 2023 05:01:21 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id db5b6e71 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 Nov 2023 10:00:52 +0000 (UTC) Date: Fri, 10 Nov 2023 11:01:19 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v2 2/4] contrib/subtree: stop using `-o` to test for number of args Message-ID: <977132d22366423fc0bc32af38ed027be3b1ba2c.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: Functions in git-subtree.sh all assert that they are being passed the correct number of arguments. In cases where we accept a variable number of arguments we assert this via a single call to `test` with `-o`, which is discouraged by our coding guidelines. Convert these cases to stop doing so. This requires us to decompose assertions of the style `assert test $# = 2 -o $# = 3` into two calls because we have no easy way to logically chain statements passed to the assert function. Signed-off-by: Patrick Steinhardt --- contrib/subtree/git-subtree.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 43b5fec7320..8af0a81ba3f 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -373,7 +373,8 @@ try_remove_previous () { # Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH [REPOSITORY] process_subtree_split_trailer () { - assert test $# = 2 -o $# = 3 + assert test $# -ge 2 + assert test $# -le 3 b="$1" sq="$2" repository="" @@ -402,7 +403,8 @@ process_subtree_split_trailer () { # Usage: find_latest_squash DIR [REPOSITORY] find_latest_squash () { - assert test $# = 1 -o $# = 2 + assert test $# -ge 1 + assert test $# -le 2 dir="$1" repository="" if test "$#" = 2 @@ -455,7 +457,8 @@ find_latest_squash () { # Usage: find_existing_splits DIR REV [REPOSITORY] find_existing_splits () { - assert test $# = 2 -o $# = 3 + assert test $# -ge 2 + assert test $# -le 3 debug "Looking for prior splits..." local indent=$(($indent + 1)) @@ -916,7 +919,7 @@ cmd_split () { if test $# -eq 0 then rev=$(git rev-parse HEAD) - elif test $# -eq 1 -o $# -eq 2 + elif test $# -eq 1 || test $# -eq 2 then rev=$(git rev-parse -q --verify "$1^{commit}") || die "fatal: '$1' does not refer to a commit" @@ -1006,8 +1009,11 @@ cmd_split () { # Usage: cmd_merge REV [REPOSITORY] cmd_merge () { - test $# -eq 1 -o $# -eq 2 || + if test $# -lt 1 || test $# -gt 2 + then die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'" + fi + rev=$(git rev-parse -q --verify "$1^{commit}") || die "fatal: '$1' does not refer to a commit" repository="" 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 $? } From patchwork Fri Nov 10 10:01:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13452283 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 A59F214008 for ; Fri, 10 Nov 2023 10:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="dwjrY7Rl"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pqrnqxBp" Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64A1826303 for ; Fri, 10 Nov 2023 02:01:32 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 337EB3200A27; Fri, 10 Nov 2023 05:01:31 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 10 Nov 2023 05:01:31 -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=1699610490; x=1699696890; bh=up 6Da/zabzE2e/EuSTJSqZzLWQ/YQ+NinMw/cUt9XYY=; b=dwjrY7RlhUa05F3FKg bDOaLCDUv+CQqzJ99AC1hAuULmv8cFoscdSmuI+7snNJxJ7V7aYzvR0VC1X/j/4n Nlv5i9swPHM+4yt+3RzxawehEIws1T/BFcXSz+814YLBfSS5kdH7eSE8w46AmRoT rvaNGSdjIobYtVil/je+I1Q6YPSQDdaKSRveGMqWEqZ8I+MCCEZHaRDm7PoVQkUf Dv+yc/Os/J+atjT3p/1YLPidliF52KhFMWjjgVR/7XmWBnhEoedcX7LisRIrXzB5 jk7L4/0oaRfwDM1s1QULOjIZ66HnnjvBQZ8z+EqjpBJfQSJBHQM4mDjUZHqEA2QU ZnLg== 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=1699610490; x=1699696890; bh=up6Da/zabzE2e /EuSTJSqZzLWQ/YQ+NinMw/cUt9XYY=; b=pqrnqxBpqSXZ/mOII9OPFW2a+cN52 DMNRpeSIQyEYbRENbd0YlxnY3pllnFZe4XeJdU7cmfX2yy9LeUSBUDIleKTKeFas OYSL8gwsmrxFTfRiPIo8pnCiljF0IU8+stlbmCt8dWnaRD0/9PbR7yQQ3jznlXkH 33xbR+pHrPvD46kKZyQcg/J4DZXQbfRKVcxEGs4tytj+VOilCMfZwEVoNYf0GsDf 4vZET+7xY2P/fP5FgPImNY4ZJM5EwUaMmzIPmQYRh3YZd7DLvdWzC7N1qSw3JhRY I+xBAnTl4eHqEIcYFWNvIbFljryTLMm0ZwWcZYRExdBnerJ6HLekLGh8w== 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:29 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 111fff1b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 10 Nov 2023 10:01:00 +0000 (UTC) Date: Fri, 10 Nov 2023 11:01:28 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH v2 4/4] Makefile: stop using `test -o` when unlinking duplicate executables Message-ID: <5326d86888a46931e8893657bda9a2063a5cee3a.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: When building executables we may end up with both `foo` and `foo.exe` in the project's root directory. This can cause issues on Cygwin, which is why we unlink the `foo` binary (see 6fc301bbf68 (Makefile: remove $foo when $foo.exe is built/installed., 2007-01-10)). This step is skipped if either: - `foo` is a directory, which can happen when building Git on Windows via MSVC (see ade2ca0ca9f (Do not try to remove directories when removing old links, 2009-10-27)). - `foo` is a hardlink to `foo.exe`, which can happen on Cygwin (see 0d768f7c8f1 (Makefile: building git in cygwin 1.7.0, 2008-08-15)). These two conditions are currently chained together via `test -o`, which is discouraged by our code style guide. Convert the recipe to instead use an `if` statement with `&&`'d conditions, which both matches our style guide and is easier to ready. Signed-off-by: Patrick Steinhardt --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 03adcb5a480..1094a557711 100644 --- a/Makefile +++ b/Makefile @@ -2342,7 +2342,7 @@ profile-fast: profile-clean all:: $(ALL_COMMANDS_TO_INSTALL) $(SCRIPT_LIB) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS ifneq (,$X) - $(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) $(OTHER_PROGRAMS))), test -d '$p' -o '$p' -ef '$p$X' || $(RM) '$p';) + $(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) $(OTHER_PROGRAMS))), if test ! -d '$p' && test ! '$p' -ef '$p$X'; then $(RM) '$p'; fi;) endif all::