Thread (71 messages) 71 messages, 6 authors, 2024-07-24

Re: [PATCH 8/8] check-whitespace: detect if no base_commit is provided

From: Chris Torek <hidden>
Date: 2024-07-08 10:18:50

On Mon, Jul 8, 2024 at 2:24 AM Karthik Nayak [off-list ref] wrote:
quoted hunk ↗ jump to hunk
diff --git a/ci/check-whitespace.sh b/ci/check-whitespace.sh
index db399097a5..ab023f9519 100755
--- a/ci/check-whitespace.sh
+++ b/ci/check-whitespace.sh
@@ -9,12 +9,19 @@ baseCommit=$1
 outputFile=$2
 url=$3

-if test "$#" -ne 1 && test "$#" -ne 3
+if { test "$#" -ne 1 && test "$#" -ne 3; } || test -z "$1"
 then
The braces `{ ... }` here are unnecessary as `&&`will bind first
(sh and bash give both operators the same precedence but
then use left associativity). Dropping them drops the need for
the semicolon. Of course some might prefer this to be explicit.

The `test` command has AND and OR operators of its own,
which give `-a` (AND) higher precedence than `-o` (OR).  In
addition, `$#` can only expand to an integer value, so quotes
are not required, and the whole thing can be written as:

    if test $# -ne 1 -a $# -ne 3 -o -z "$1"

(which is what I would do myself, unless I wanted a separate
error message for an empty "$1").  It's fine as is though.

Chris
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help