Skip to content

Commit 1342002

Browse files
pks-tgitster
authored andcommitted
global: convert trivial usages of test <expr> -a/-o <expr>
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dadef80 commit 1342002

File tree

6 files changed

+11
-10
lines changed

6 files changed

+11
-10
lines changed

GIT-VERSION-GEN

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LF='
1111
if test -f version
1212
then
1313
VN=$(cat version) || VN="$DEF_VER"
14-
elif test -d ${GIT_DIR:-.git} -o -f .git &&
14+
elif { test -d "${GIT_DIR:-.git}" || test -f .git; } &&
1515
VN=$(git describe --match "v[0-9]*" HEAD 2>/dev/null) &&
1616
case "$VN" in
1717
*$LF*) (exit 1) ;;

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ AC_DEFUN([GIT_PARSE_WITH_SET_MAKE_VAR],
9494
[AC_ARG_WITH([$1],
9595
[AS_HELP_STRING([--with-$1=VALUE], $3)],
9696
if test -n "$withval"; then
97-
if test "$withval" = "yes" -o "$withval" = "no"; then
97+
if test "$withval" = "yes" || test "$withval" = "no"; then
9898
AC_MSG_WARN([You likely do not want either 'yes' or 'no' as]
9999
[a value for $1 ($2). Maybe you do...?])
100100
fi

contrib/subtree/git-subtree.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,13 @@ find_existing_splits () {
489489
;;
490490
END)
491491
debug "Main is: '$main'"
492-
if test -z "$main" -a -n "$sub"
492+
if test -z "$main" && test -n "$sub"
493493
then
494494
# squash commits refer to a subtree
495495
debug " Squash: $sq from $sub"
496496
cache_set "$sq" "$sub"
497497
fi
498-
if test -n "$main" -a -n "$sub"
498+
if test -n "$main" && test -n "$sub"
499499
then
500500
debug " Prior: $main -> $sub"
501501
cache_set $main $sub

t/perf/perf-lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ unset GIT_CONFIG_NOSYSTEM
3131
GIT_CONFIG_SYSTEM="$TEST_DIRECTORY/perf/config"
3232
export GIT_CONFIG_SYSTEM
3333

34-
if test -n "$GIT_TEST_INSTALLED" -a -z "$PERF_SET_GIT_TEST_INSTALLED"
34+
if test -n "$GIT_TEST_INSTALLED" && test -z "$PERF_SET_GIT_TEST_INSTALLED"
3535
then
3636
error "Do not use GIT_TEST_INSTALLED with the perf tests.
3737

t/perf/run

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ set_git_test_installed () {
9191
run_dirs_helper () {
9292
mydir=${1%/}
9393
shift
94-
while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
94+
while test $# -gt 0 && test "$1" != -- && test ! -f "$1"; do
9595
shift
9696
done
97-
if test $# -gt 0 -a "$1" = --; then
97+
if test $# -gt 0 && test "$1" = --; then
9898
shift
9999
fi
100100

@@ -124,7 +124,7 @@ run_dirs_helper () {
124124
}
125125

126126
run_dirs () {
127-
while test $# -gt 0 -a "$1" != -- -a ! -f "$1"; do
127+
while test $# -gt 0 && test "$1" != -- && test ! -f "$1"; do
128128
run_dirs_helper "$@"
129129
shift
130130
done
@@ -180,7 +180,8 @@ run_subsection () {
180180
GIT_PERF_AGGREGATING_LATER=t
181181
export GIT_PERF_AGGREGATING_LATER
182182

183-
if test $# = 0 -o "$1" = -- -o -f "$1"; then
183+
if test $# = 0 || test "$1" = -- || test -f "$1"
184+
then
184185
set -- . "$@"
185186
fi
186187

t/valgrind/valgrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ memcheck)
2323
VALGRIND_MAJOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*\([0-9]*\)')
2424
VALGRIND_MINOR=$(expr "$VALGRIND_VERSION" : '[^0-9]*[0-9]*\.\([0-9]*\)')
2525
test 3 -gt "$VALGRIND_MAJOR" ||
26-
test 3 -eq "$VALGRIND_MAJOR" -a 4 -gt "$VALGRIND_MINOR" ||
26+
{ test 3 -eq "$VALGRIND_MAJOR" && test 4 -gt "$VALGRIND_MINOR"; } ||
2727
TOOL_OPTIONS="$TOOL_OPTIONS --track-origins=yes"
2828
;;
2929
*)

0 commit comments

Comments
 (0)