Skip to content

Commit

Permalink
*.sh: purge use of test '-a' and '-o' ops
Browse files Browse the repository at this point in the history
Although the test utility's '-a' and '-o' operators are
documented by POSIX, they are marked obsolete and may
not be supported by some implementations.

Furthermore, the semantics (i.e. precedence and order of
evaluation) are not well defined when they are in use.

Therefore expunge use of them in favor of multiple tests
combined with '||' and/or '&&' etc.

Also sneak in a tiny optimization into the tg-export.sh
argument parsing code since it's affected by the change.

Signed-off-by: Kyle J. McKay <[email protected]>
  • Loading branch information
mackyle committed Nov 9, 2017
1 parent 260679a commit 84d8101
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 75 deletions.
6 changes: 3 additions & 3 deletions hooks/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ v_check_topfile()
}

# check for positive size
[ -n "$_zerook" -o "$_size" -gt 0 ] || {
[ -n "$_zerook" ] || [ "$_size" -gt 0 ] || {
eval "$_var="'"$_file has empty (i.e. 0) size"'
return 3
}
Expand Down Expand Up @@ -125,7 +125,7 @@ while read -r status fn; do case "$fn" in
esac; done <<-EOT
$(git diff-index --cached --name-status "$headtree" | grep -e "^$prefix\\.topdeps\$" -e "^$prefix\\.topmsg\$")
EOT
[ -n "$changedeps" -o -n "$changemsg" ] || exit 0
[ -n "$changedeps" ] || [ -n "$changemsg" ] || exit 0

check_cycle_name()
{
Expand Down Expand Up @@ -197,7 +197,7 @@ prefix="100[0-9][0-9][0-9] $octet20 0$tab"
newtree="$(GIT_INDEX_FILE="$tg_index" git write-tree)"
rm -f "$tg_index"
files=
if [ -n "$changedeps" -a -n "$changemsg" ]; then
if [ -n "$changedeps" ] && [ -n "$changemsg" ]; then
files=".topdeps and .topmsg"
elif [ -n "$changedeps" ]; then
files=".topdeps"
Expand Down
6 changes: 3 additions & 3 deletions t/test-lib-main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ getcmd() {
# without "-P" or "-L" a relative dirname may be returned
whats_the_dir() {
# determine "$1"'s directory and store it into the var name passed as "$2"
if [ "z$1" = "z-P" -o "z$1" = "z-L" ]; then
if [ "z$1" = "z-P" ] || [ "z$1" = "z-L" ]; then
if [ "z$2" = "z--" ]; then
set -- "$3" "$4" "$1"
else
Expand All @@ -92,7 +92,7 @@ whats_the_dir() {
if [ "z$3" != "z" ] && [ -d "$1" ] &&
! case "$1" in [!/]*|*"/./"*|*"/."|*"/../"*|*"/..") ! :; esac; then
[ "z$3" = "z-P" ] || set -- "$1" "$2"
if [ "z$3" = "z" -a \( "z$1" = "z." -o "z$1" = "z$PWD" \) ]; then
if [ "z$3" = "z" ] && { [ "z$1" = "z." ] || [ "z$1" = "z$PWD" ]; }; then
set -- "$PWD" "$2"
else
set -- "$(cd "$1" && pwd $3)" "$2"
Expand All @@ -116,7 +116,7 @@ vcmp() {
while
vcmp_a_="${1%%.*}"
vcmp_b_="${3%%.*}"
[ "z$vcmp_a_" != "z" -o "z$vcmp_b_" != "z" ]
[ "z$vcmp_a_" != "z" ] || [ "z$vcmp_b_" != "z" ]
do
if [ "${vcmp_a_:-0}" -lt "${vcmp_b_:-0}" ]; then
unset_ vcmp_a_ vcmp_b_
Expand Down
4 changes: 2 additions & 2 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fi
# without "-P" or "-L" a relative dirname may be returned
whats_the_dir() {
# determine "$1"'s directory and store it into the var name passed as "$2"
if [ "z$1" = "z-P" -o "z$1" = "z-L" ]; then
if [ "z$1" = "z-P" ] || [ "z$1" = "z-L" ]; then
if [ "z$2" = "z--" ]; then
set -- "$3" "$4" "$1"
else
Expand All @@ -199,7 +199,7 @@ whats_the_dir() {
if [ "z$3" != "z" ] && [ -d "$1" ] &&
! case "$1" in [!/]*|*"/./"*|*"/."|*"/../"*|*"/..") ! :; esac; then
[ "z$3" = "z-P" ] || set -- "$1" "$2"
if [ "z$3" = "z" -a \( "z$1" = "z." -o "z$1" = "z$PWD" \) ]; then
if [ "z$3" = "z" ] && { [ "z$1" = "z." ] || [ "z$1" = "z$PWD" ]; }; then
set -- "$PWD" "$2"
else
set -- "$(cd "$1" && pwd $3)" "$2"
Expand Down
16 changes: 8 additions & 8 deletions tg-create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,25 +147,25 @@ while [ $# -gt 0 ]; do case "$1" in
;;
esac; shift; done
ensure_work_tree
[ $# -gt 0 -o -z "$rname" ] || set -- "$rname"
[ $# -gt 0 ] || [ -z "$rname" ] || set -- "$rname"
if [ $# -gt 0 ]; then
name="$1"
shift
if [ -z "$remote" -a "$1" = "-r" ]; then
if [ -z "$remote" ] && [ "$1" = "-r" ]; then
remote=1
shift;
rname="$1"
[ $# -eq 0 ] || shift
fi
fi
[ -n "$name" ] || { err "no branch name given"; usage 1; }
[ -z "$remote" -o -n "$rname" ] || rname="$name"
[ -z "$remote" -o -z "$msg$msgfile$topmsg$topmsgfile$nocommit$noupdate$nodeps" ] || { err "-r may not be combined with other options"; usage 1; }
[ $# -eq 0 -o -z "$remote" ] || { err "deps not allowed with -r"; usage 1; }
[ $# -le 1 -o -z "$nodeps" ] || { err "--base (aka --no-deps) allows at most one <dep>"; usage 1; }
[ -z "$remote" ] || [ -n "$rname" ] || rname="$name"
[ -z "$remote" ] || [ -z "$msg$msgfile$topmsg$topmsgfile$nocommit$noupdate$nodeps" ] || { err "-r may not be combined with other options"; usage 1; }
[ $# -eq 0 ] || [ -z "$remote" ] || { err "deps not allowed with -r"; usage 1; }
[ $# -le 1 ] || [ -z "$nodeps" ] || { err "--base (aka --no-deps) allows at most one <dep>"; usage 1; }
[ "$nocommit$noupdate" != "11" ] || die "--no-commit and --no-update are mutually exclusive options"
[ -z "$msg" -o -z "$msgfile" ] || die "only one -F or -m option is allowed"
[ "$msgfile" != "-" -o "$topmsgfile" != "-" ] || { err "--message-file and --topmsg-file may not both be '-'"; usage 1; }
[ -z "$msg" ] || [ -z "$msgfile" ] || die "only one -F or -m option is allowed"
[ "$msgfile" != "-" ] || [ "$topmsgfile" != "-" ] || { err "--message-file and --topmsg-file may not both be '-'"; usage 1; }

## Fast-track creating branches based on remote ones

Expand Down
2 changes: 1 addition & 1 deletion tg-export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ while [ -n "$1" ]; do
if [ "$val" = "--strip" ]; then
strip=true
stripval=9999
elif [ -n "$val" -a "x$(echol "$val" | sed -e 's/[0-9]//g')" = "x" ]; then
elif [ -n "$val" ] && [ "${val#*[!0-9]}" = "$val" ]; then
strip=true
stripval=$val
else
Expand Down
2 changes: 1 addition & 1 deletion tg-log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ if [ -z "$hasdd" ]; then
git $logcmd --first-parent $nomerges "$@" "refs/$topbases/$name".."$name"
else
cmd='git $logcmd --first-parent $nomerges'
while [ $# -gt 0 -a "$1" != "--" ]; do
while [ $# -gt 0 ] && [ "$1" != "--" ]; do
cmd="$cmd $(quotearg "$1")"
shift
done
Expand Down
2 changes: 1 addition & 1 deletion tg-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ else
git diff-tree -p --stat --summary ${binary:+--binary} "$@" $b_tree $t_tree
else
cmd="git diff-tree -p --stat --summary ${binary:+--binary}"
while [ $# -gt 0 -a "$1" != "--" ]; do
while [ $# -gt 0 ] && [ "$1" != "--" ]; do
cmd="$cmd $(quotearg "$1")"
shift
done
Expand Down
2 changes: 1 addition & 1 deletion tg-rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if [ -n "$optcontinue" ]; then
exit 1
fi
fi
if [ -z "$optmerge" -a -z "$optcontinue" ]; then
if [ -z "$optmerge" ] && [ -z "$optcontinue" ]; then
cat <<EOT >&2
${tgname:-tg} rebase is intended as a drop-in replacement for git rebase -m.
Either add the -m (or --merge) option to the command line or use git rebase
Expand Down
36 changes: 18 additions & 18 deletions tg-revert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ while [ $# -gt 0 ]; do case "$1" in
esac; shift; done
[ -z "$exclude" ] || exclude="$exclude "

[ -z "$list$short$hashonly" -o -z "$force$interact$dryrun$nodeps$nostash" ] || usage 1
[ -z "$force$interact$dryrun" -o -z "$list$short$hashonly$deps$rdeps" ] || usage 1
[ -z "$deps" -o -z "$rdeps" ] || usage 1
[ -z "$list$short$hashonly" ] || [ -z "$force$interact$dryrun$nodeps$nostash" ] || usage 1
[ -z "$force$interact$dryrun" ] || [ -z "$list$short$hashonly$deps$rdeps" ] || usage 1
[ -z "$deps" ] || [ -z "$rdeps" ] || usage 1
[ -n "$list$force$interact$dryrun" ] || list=1
[ -z "$list" -o -n "$short" ] || if [ -n "$hashonly" ]; then short="--no-short"; else short="--short"; fi
[ -z "$list" ] || [ -n "$short" ] || if [ -n "$hashonly" ]; then short="--no-short"; else short="--short"; fi
[ -n "$1" ] || { echo "Tag name required" >&2; usage 1; }
tagname="$1"
shift
Expand All @@ -114,7 +114,7 @@ if [ "$1" = "--topgit-heads" ]; then
headstopgit=1
set -- "--heads" "$@"
fi
[ -n "$list" -o "$1" != "--heads" ] || usage 1
[ -n "$list" ] || [ "$1" != "--heads" ] || usage 1
[ "$tagname" != "--stash" ] || tagname=refs/tgstash
case "$tagname" in --stash"@{"*"}")
strip="${tagname#--stash??}"
Expand Down Expand Up @@ -212,9 +212,9 @@ show_heads()
fi
}

[ $# -ne 0 -o -z "$rdeps$deps" ] || { set -- --heads; headstopgit=1; }
[ $# -ne 1 -o -z "$deps" -o "$1" != "--heads" ] || { deps=; set --; }
if [ $# -eq 1 -a "$1" = "--heads" ]; then
[ $# -ne 0 ] || [ -z "$rdeps$deps" ] || { set -- --heads; headstopgit=1; }
[ $# -ne 1 ] || [ -z "$deps" ] || [ "$1" != "--heads" ] || { deps=; set --; }
if [ $# -eq 1 ] && [ "$1" = "--heads" ]; then
set -- $(show_heads)
fi

Expand All @@ -239,7 +239,7 @@ for b; do
ref_exists "$rn" || die "not present in tag data (try --list): $rn"
case " $refs " in *" $rn "*);;*)
refs="${refs:+$refs }$rn"
if [ -z "$list" ] && [ -z "$nodeps" -o -z "$exp" ] && is_tgish "$rn"; then
if [ -z "$list" ] && { [ -z "$nodeps" ] || [ -z "$exp" ]; } && is_tgish "$rn"; then
case "$rn" in
refs/"$topbases"/*)
refs="$refs refs/heads/${rn#refs/$topbases/}"
Expand All @@ -256,7 +256,7 @@ show_dep() {
case "$exclude" in *" refs/heads/$_dep "*) return; esac
case " $seen_deps " in *" $_dep "*) return 0; esac
seen_deps="${seen_deps:+$seen_deps }$_dep"
[ -z "$tgish" -o -n "$_dep_is_tgish" ] || return 0
[ -z "$tgish" ] || [ -n "$_dep_is_tgish" ] || return 0
printf 'refs/heads/%s\n' "$_dep"
[ -z "$_dep_is_tgish" ] ||
printf 'refs/%s/%s\n' "$topbases" "$_dep"
Expand Down Expand Up @@ -286,7 +286,7 @@ show_deps()
show_rdep()
{
case "$exclude" in *" refs/heads/$_dep "*) return; esac
[ -z "$tgish" -o -n "$_dep_is_tgish" ] || return 0
[ -z "$tgish" ] || [ -n "$_dep_is_tgish" ] || return 0
if [ -n "$hashonly" ]; then
printf '%s %s\n' "$_depchain" "$(ref_exists_rev_short "refs/heads/$_dep" $short)"
else
Expand Down Expand Up @@ -377,7 +377,7 @@ get_short() {
git rev-parse --verify --quiet --short "$1" --
}

if [ -n "$nodeps" -o -z "$refs" ]; then
if [ -n "$nodeps" ] || [ -z "$refs" ]; then
while read -r name rev; do
case "$exclude" in *" $name "*) continue; esac
[ -z "$refs" ] || case " $refs " in *" $name "*);;*) continue; esac
Expand Down Expand Up @@ -412,7 +412,7 @@ EOT
mv -f "$insn"+ "$insn"
[ -s "$insn" ] || die "nothing to do"
while read -r op hash ref; do
[ "$op" = "r" -o "$op" = "revert" ] ||
[ "$op" = "r" ] || [ "$op" = "revert" ] ||
die "invalid op in instruction: $op $hash $ref"
case "$ref" in refs/?*);;*)
die "invalid ref in instruction: $op $hash $ref"
Expand All @@ -422,10 +422,10 @@ EOT
done <"$insn"
fi
msg="tgrevert: $reftype $tagname ($(( $(wc -l <"$insn") )) command(s))"
[ -n "$dryrun" -o -n "$nostash" ] || tg tag -q -q --none-ok -m "$msg" --stash || die "requested --stash failed"
[ -n "$dryrun" ] || [ -n "$nostash" ] || tg tag -q -q --none-ok -m "$msg" --stash || die "requested --stash failed"
refwidth="$(git config --get --int core.abbrev 2>/dev/null)" || :
[ -n "$refwidth" ] || refwidth=7
[ $refwidth -ge 4 -a $refwidth -le 40 ] || refwidth=7
[ $refwidth -ge 4 ] && [ $refwidth -le 40 ] || refwidth=7
nullref="$(printf '%.*s' $refwidth "$nullsha")"
notewidth=$(( $refwidth + 4 + $refwidth ))
srh=
Expand All @@ -435,7 +435,7 @@ while read -r name rev; do
orig="$(git rev-parse --verify --quiet "$name" --)" || :
init_reflog "$name"
if [ "$rev" != "$orig" ]; then
[ -z "$dryrun" -a -n "$quiet" ] ||
[ -z "$dryrun" ] && [ -n "$quiet" ] ||
origsh="$(git rev-parse --verify --short --quiet "$name" --)" || :
if [ -z "$dryrun" ]; then
if [ -n "$srh" ] && [ "$srh" = "$name" ]; then
Expand All @@ -447,7 +447,7 @@ while read -r name rev; do
fi
git update-ref -m "$msg" "$name" "$rev"
fi
if [ -n "$dryrun" -o -z "$quiet" ]; then
if [ -n "$dryrun" ] || [ -z "$quiet" ]; then
revsh="$(git rev-parse --verify --short --quiet "$rev" --)" || :
if [ -n "$origsh" ]; then
hdr=' '
Expand All @@ -460,7 +460,7 @@ while read -r name rev; do
fi
fi
else
: #[ -z "$dryrun" -a -n "$quiet" ] || printf "* %-*s %s\n" $notewidth "[no change]" "$name"
: #[ -z "$dryrun" ] && [ -n "$quiet" ] || printf "* %-*s %s\n" $notewidth "[no change]" "$name"
fi
done

Expand Down
14 changes: 7 additions & 7 deletions tg-summary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ while [ -n "$1" ]; do
exclude="$exclude ${1#--exclude=}";;
--exclude)
shift
[ -n "$1" -a "$1" != "--all" ] || die "--exclude requires a branch name"
[ -n "$1" ] && [ "$1" != "--all" ] || die "--exclude requires a branch name"
exclude="$exclude $1";;
-*)
usage;;
Expand All @@ -113,14 +113,14 @@ if [ "$1" = "--all" ]; then
doingall=1
fi
[ "$heads$rdeps" != "11" ] || head=
[ $# -ne 0 -o -z "$head" ] || set -- "$head"
[ -z "$defwithdeps" ] || [ $# -ne 1 ] || [ z"$1" != z"HEAD" -a z"$1" != z"@" ] || defwithdeps=2
[ $# -ne 0 ] || [ -z "$head" ] || set -- "$head"
[ -z "$defwithdeps" ] || [ $# -ne 1 ] || { [ z"$1" != z"HEAD" ] && [ z"$1" != z"@" ]; } || defwithdeps=2

[ "$terse$heads$headsonly$graphviz$sort$deps$depsonly" = "" ] ||
[ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "1" ] ||
[ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "11" -a "$heads$rdeps" = "11" ] ||
{ [ "$terse$heads$headsonly$graphviz$sort$deps$depsonly$rdeps" = "11" ] && [ "$heads$rdeps" = "11" ]; } ||
die "mutually exclusive options given"
[ -z "$withdeps" -o -z "$rdeps$depsonly$heads$headsonly" ] ||
[ -z "$withdeps" ] || [ -z "$rdeps$depsonly$heads$headsonly" ] ||
die "mutually exclusive options given"

for b; do
Expand Down Expand Up @@ -177,7 +177,7 @@ show_heads()
fi
}

if [ -n "$heads" -a -z "$rdeps" ]; then
if [ -n "$heads" ] && [ -z "$rdeps" ]; then
show_heads
exit 0
fi
Expand Down Expand Up @@ -337,7 +337,7 @@ process_branch()
branch_contains "refs/$topbases/$name" "refs/remotes/$base_remote/${topbases#heads/}/$name" &&
branch_contains "refs/heads/$name" "refs/remotes/$base_remote/$name"
} || rem_update='R'
[ "$remote" != 'r' -o "$rem_update" = 'R' ] || {
[ "$remote" != 'r' ] || [ "$rem_update" = 'R' ] || {
branch_contains "refs/remotes/$base_remote/$name" "refs/heads/$name" 2>/dev/null
} || rem_update='L'
needs_update_check "$name"
Expand Down
Loading

0 comments on commit 84d8101

Please sign in to comment.