Skip to content

Commit e020e55

Browse files
committed
Merge branch 'ps/ban-a-or-o-operator-with-test'
Test and shell scripts clean-up. * ps/ban-a-or-o-operator-with-test: Makefile: stop using `test -o` when unlinking duplicate executables contrib/subtree: convert subtree type check to use case statement contrib/subtree: stop using `-o` to test for number of args global: convert trivial usages of `test <expr> -a/-o <expr>`
2 parents 4297485 + 615993d commit e020e55

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
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) ;;

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,7 @@ profile-fast: profile-clean
23512351

23522352
all:: $(ALL_COMMANDS_TO_INSTALL) $(SCRIPT_LIB) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS
23532353
ifneq (,$X)
2354-
$(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';)
2354+
$(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;)
23552355
endif
23562356

23572357
all::

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: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ try_remove_previous () {
373373

374374
# Usage: process_subtree_split_trailer SPLIT_HASH MAIN_HASH [REPOSITORY]
375375
process_subtree_split_trailer () {
376-
assert test $# = 2 -o $# = 3
376+
assert test $# -ge 2
377+
assert test $# -le 3
377378
b="$1"
378379
sq="$2"
379380
repository=""
@@ -402,7 +403,8 @@ process_subtree_split_trailer () {
402403

403404
# Usage: find_latest_squash DIR [REPOSITORY]
404405
find_latest_squash () {
405-
assert test $# = 1 -o $# = 2
406+
assert test $# -ge 1
407+
assert test $# -le 2
406408
dir="$1"
407409
repository=""
408410
if test "$#" = 2
@@ -455,7 +457,8 @@ find_latest_squash () {
455457

456458
# Usage: find_existing_splits DIR REV [REPOSITORY]
457459
find_existing_splits () {
458-
assert test $# = 2 -o $# = 3
460+
assert test $# -ge 2
461+
assert test $# -le 3
459462
debug "Looking for prior splits..."
460463
local indent=$(($indent + 1))
461464

@@ -489,13 +492,13 @@ find_existing_splits () {
489492
;;
490493
END)
491494
debug "Main is: '$main'"
492-
if test -z "$main" -a -n "$sub"
495+
if test -z "$main" && test -n "$sub"
493496
then
494497
# squash commits refer to a subtree
495498
debug " Squash: $sq from $sub"
496499
cache_set "$sq" "$sub"
497500
fi
498-
if test -n "$main" -a -n "$sub"
501+
if test -n "$main" && test -n "$sub"
499502
then
500503
debug " Prior: $main -> $sub"
501504
cache_set $main $sub
@@ -638,10 +641,16 @@ subtree_for_commit () {
638641
while read mode type tree name
639642
do
640643
assert test "$name" = "$dir"
641-
assert test "$type" = "tree" -o "$type" = "commit"
642-
test "$type" = "commit" && continue # ignore submodules
643-
echo $tree
644-
break
644+
645+
case "$type" in
646+
commit)
647+
continue;; # ignore submodules
648+
tree)
649+
echo $tree
650+
break;;
651+
*)
652+
die "fatal: tree entry is of type ${type}, expected tree or commit";;
653+
esac
645654
done || exit $?
646655
}
647656

@@ -916,7 +925,7 @@ cmd_split () {
916925
if test $# -eq 0
917926
then
918927
rev=$(git rev-parse HEAD)
919-
elif test $# -eq 1 -o $# -eq 2
928+
elif test $# -eq 1 || test $# -eq 2
920929
then
921930
rev=$(git rev-parse -q --verify "$1^{commit}") ||
922931
die "fatal: '$1' does not refer to a commit"
@@ -1006,8 +1015,11 @@ cmd_split () {
10061015

10071016
# Usage: cmd_merge REV [REPOSITORY]
10081017
cmd_merge () {
1009-
test $# -eq 1 -o $# -eq 2 ||
1018+
if test $# -lt 1 || test $# -gt 2
1019+
then
10101020
die "fatal: you must provide exactly one revision, and optionally a repository. Got: '$*'"
1021+
fi
1022+
10111023
rev=$(git rev-parse -q --verify "$1^{commit}") ||
10121024
die "fatal: '$1' does not refer to a commit"
10131025
repository=""

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)