From patchwork Thu Nov 9 10:53:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13450924 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 7C4CA107BB for ; Thu, 9 Nov 2023 10:53:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="lBfTPNUq"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ovKbNuNZ" Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB5B22699 for ; Thu, 9 Nov 2023 02:53:34 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 560145C0366; Thu, 9 Nov 2023 05:53:34 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 09 Nov 2023 05:53:34 -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=1699527214; x=1699613614; bh=cm rm92hyAPDltxCycxbyaumo8wApdbG86eiiCvkWNOU=; b=lBfTPNUqzV2haY87bI Zw2Nefu1F5Mk8Ovh/wOHge/976BfhK6SAwYmMdvoulRU60XCcaENC6UA/65l7GQZ 6IpZjSRAwLWSwwAWiInbXGvyWVQh/n7ms1ZP1Iz2AKtBTwfl0eiuNI7XMY7OI1kb Cx3Mxb0SQJ30eiRizXUXKkzON1Ev5C6mi+TbL6bvlB6KQuYdaCsi31svC4J761Ud ZBSexJVICxA2OcfKNinAsqE9vrSuIxb3qfnnDt/Co+J5hesFUxvpb0weA3Pt8Ire fjzaqtW1BwUKBhyYDdddvSg744sm5XOHoOqHWtTxmcXUTX4vWwqlOqt/496B4byA KOUg== 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=1699527214; x=1699613614; bh=cmrm92hyAPDlt xCycxbyaumo8wApdbG86eiiCvkWNOU=; b=ovKbNuNZuiXvJpmQ2NHu9rMKxzLVs D1QYfqsn57kbEmrWYzAG7JW2XU34VAAQUg45+rANnsE3cT8n/3rFw6uo2Zh5PvDr q4SR1ScDuCiQTWs6kTaFCkQI3/AfjgK6OKToqi+8kq94pXpLdB8zGjYDhzm+HbaX X42TcgTtYe1eTBEYZTwtzVCnt2bLmFtBhESHsR6TtOCS4MMy8J3Nx+DLtpV0C9zg byn3KGuH0bpPBr0QHWLnqTcJBxrNlijbB7UJigC+d53ZtkUUxJejGeQnA6ykFKZH Cg+xgUFNZ88fnwixQiyjX5LhWJZvBTGGFQ1liSG9h+n4Sspboy8b7ANRw== 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:33 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0a8f35e7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 9 Nov 2023 10:53:05 +0000 (UTC) Date: Thu, 9 Nov 2023 11:53:31 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 1/4] global: convert trivial usages of `test -a/-o ` 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: 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. 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..e4d31cbbd6a 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 Thu Nov 9 10:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13450925 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 7F6551945C for ; Thu, 9 Nov 2023 10:53:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="RsNRw75l"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XY61Az20" Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07840D41 for ; Thu, 9 Nov 2023 02:53:39 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 7A3DF5C033E; Thu, 9 Nov 2023 05:53:38 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 09 Nov 2023 05:53:38 -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=1699527218; x=1699613618; bh=Y/ h83g2cVK1cUfW3x3k+6tWSuUa/mZxQS58zZInx4WM=; b=RsNRw75lBrMiK6+19n zheswOFKhu/SDeZ+dPThCsT1Olzgl2xvQnLmuN8W72ajwZfAewM4eyqAkf5US5v0 JHZm2Uoq8HLlFlJiUReAJn4WVlSVx6ofdBBf2CEJ00SiMfsND7tfBu+S6caZigYL D9k5rdnSZMYBf1bSHUEc9knr7nYTRVLXvF/a3XyRXoJrJbplbFNVFUuUclVGwIsh mpuC387IoBP+hZJBlKnrfH8wrtouB+OVnsjUWgaK7tt9OB8xFN/D+zD2zKV1jYHC +JXRkvP1X0kmbce5P3z76yj8wHhu5hhr8IoUimnyAWwEP95ZeaOScmaAU6mj42xh nRjA== 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=1699527218; x=1699613618; bh=Y/h83g2cVK1cU fW3x3k+6tWSuUa/mZxQS58zZInx4WM=; b=XY61Az20jmbJrSHRZ9yeI9GYS30Bu g3y149zoW8yenvHydOP0HGbzA5lVAbmBpTTLLp/xxKaemLe1sNmpopYTWy55fLDY Ny1n2cT9XE+RpxYm9khNUe/iI14t6p41FSQMKJQStq1awF/PwSNN8tYZ34iHPkkh VsvtLDpVeH1bm3cB3MFsrIiig630aUuQBb7wSMdVgQ9xxI0pyv3O9DQOnPfYGcrq qKpwRyVQfPiSZnuDBgE+g49t1PBa4RIyGxtP5yaPY2DmgzdDVQ5owmNXO9utpupG qaPftk7DGn49GT9vNXWire7uJWNTBjKzoZbkmXaoCb8WzxUlEzE7wI/ZA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedruddvuddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 9 Nov 2023 05:53:37 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 92ec5bee (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 9 Nov 2023 10:53:09 +0000 (UTC) Date: Thu, 9 Nov 2023 11:53:35 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 2/4] contrib/subtree: stop using `-o` to test for number of args 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: 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. 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 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 $? } From patchwork Thu Nov 9 10:53:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13450927 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 00C64199AF for ; Thu, 9 Nov 2023 10:53:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="jOLji6r3"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Wixc9MOk" Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 782C92590 for ; Thu, 9 Nov 2023 02:53:49 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id E33775C02EA; Thu, 9 Nov 2023 05:53:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 09 Nov 2023 05:53:48 -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=1699527228; x=1699613628; bh=jz AcxQy2WYq+p5Je+BJ7NS7xX7ylyMJIJvRiIR7HjCw=; b=jOLji6r3MO9RMe9eaA g7NqsJZwvbfOaGJi7rhL1U0AwhMhaVXIsXo7FowHeOzni4ZZGEXBp3cyDTdq0oMD XM+VtnV4naBl/l7o92wgkPJBbFflZp9GDPi7LMxoG6w99lhGswipJr2i29jxxBup oHOT9nnhkYY8SRmkSFwselw9tdvtFyKk4LwOsE0Als9r3a9xEeUKzcwmqFk/Kswj Y+go/Rwdk5n7wJLG+GQwsopeDm0t4vWvfWzZ7bRDONwSujqG7fhb6FaOnJfCcU45 fnzXAgZMkeTzosVp4fzZGXzBbXXdNXHm69m5VlpSuR+3KWavhZlw9eorddXllY0q jaew== 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=1699527228; x=1699613628; bh=jzAcxQy2WYq+p 5Je+BJ7NS7xX7ylyMJIJvRiIR7HjCw=; b=Wixc9MOky9NEkXFINXwId2jbWO3fU kd5aPyl5bMORZvYP5KkX23zAGuhnDRuIPu+6RRcnWc91v8TDgVCerJ23ckykDJkr DifajUrsheLhElsA8OVtc0iWaPiOhDWbbewXf7zusK+bDUUp7KBb2AJ1fIjHs3Bq SyMyYZ+iRncbzm9LsCtpCrcKJg45U0OMMwrdSx+O6FlNhgXd6CZYARQlJVRdmZMq oM/5Okz2BQwMjqQdtXk9I+7n0QUTbNLLrnlt0yh4yRmqRlo5lM2SfeH9S6sIe12o uuFAYh/EQCI+1d7Heaj6Ck0H+PfItmcsGA9DK+TdqDlG3V1T6xDQBmgfg== 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:47 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 738dddd7 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 9 Nov 2023 10:53:20 +0000 (UTC) Date: Thu, 9 Nov 2023 11:53:45 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Jeff King , Junio C Hamano Subject: [PATCH 4/4] Makefile: stop using `test -o` when unlinking duplicate executables 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 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::