From: Simon Ruderich <simon@ruderich.org>
To: Paul Campbell <pcampbell@kemitix.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/3] contrib/subtree: remove use of -a/-o in [ commands
Date: Sun, 24 Mar 2013 22:17:13 +0100 [thread overview]
Message-ID: <20130324211713.GA6155@ruderich.org> (raw)
In-Reply-To: <1364153863-27437-3-git-send-email-pcampbell@kemitix.net>
From: Paul Campbell <pcampbell@kemitix.net>
Use of -a and -o in the [ command can have confusing semantics.
Use a separate test invocation for each single test, combining them with
&& and ||.
Signed-off-by: Paul Campbell <pcampbell@kemitix.net>
Signed-off-by: Simon Ruderich <simon@ruderich.org>
---
On Sun, Mar 24, 2013 at 07:37:42PM +0000, Paul Campbell wrote:
> Use a separate test invocation for each single test, combining them with
> && and ||, and use ordinary parentheses for grouping.
Hello Paul,
Parentheses are only necessary if both && and || are used to
enforce precedence; the shell can split the commands without
needing the parentheses. In these cases they can all be removed.
Regards
Simon
contrib/subtree/git-subtree.sh | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 5701376..d02e6c5 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -119,7 +119,7 @@ esac
dir="$(dirname "$prefix/.")"
-if [ "$command" != "pull" -a "$command" != "add" -a "$command" != "push" ]; then
+if test "$command" != "pull" && test "$command" != "add" && test "$command" != "push"; then
revs=$(git rev-parse $default --revs-only "$@") || exit $?
dirs="$(git rev-parse --no-revs --no-flags "$@")" || exit $?
if [ -n "$dirs" ]; then
@@ -181,9 +181,9 @@ cache_set()
{
oldrev="$1"
newrev="$2"
- if [ "$oldrev" != "latest_old" \
- -a "$oldrev" != "latest_new" \
- -a -e "$cachedir/$oldrev" ]; then
+ if test "$oldrev" != "latest_old" \
+ && test "$oldrev" != "latest_new" \
+ && test -e "$cachedir/$oldrev"; then
die "cache for $oldrev already exists!"
fi
echo "$newrev" >"$cachedir/$oldrev"
@@ -273,12 +273,12 @@ find_existing_splits()
git-subtree-split:) sub="$b" ;;
END)
debug " Main is: '$main'"
- if [ -z "$main" -a -n "$sub" ]; then
+ 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 [ -n "$main" -a -n "$sub" ]; then
+ if test -n "$main" && test -n "$sub"; then
debug " Prior: $main -> $sub"
cache_set $main $sub
cache_set $sub $sub
@@ -541,7 +541,7 @@ cmd_add_commit()
tree=$(git write-tree) || exit $?
headrev=$(git rev-parse HEAD) || exit $?
- if [ -n "$headrev" -a "$headrev" != "$rev" ]; then
+ if test -n "$headrev" && test "$headrev" != "$rev"; then
headp="-p $headrev"
else
headp=
--
1.8.2
--
+ privacy is necessary
+ using gnupg http://gnupg.org
+ public key id: 0x92FEFDB7E44C32F9
next prev parent reply other threads:[~2013-03-24 21:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-24 19:37 [PATCH 0/3] Improve POSIX compatibility and general portablity Paul Campbell
2013-03-24 19:37 ` [PATCH 1/3] contrib/subtree: stop explicitly using a bash shell Paul Campbell
2013-03-25 17:57 ` Junio C Hamano
2013-03-24 19:37 ` [PATCH 2/3] contrib/subtree: remove use of -a/-o in [ commands Paul Campbell
2013-03-24 21:17 ` Simon Ruderich [this message]
2013-03-24 19:37 ` [PATCH 3/3] contrib/subtree: replace echo options with printf Paul Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130324211713.GA6155@ruderich.org \
--to=simon@ruderich.org \
--cc=git@vger.kernel.org \
--cc=pcampbell@kemitix.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).