git-submodule.sh: avoid "test <cond> -a/-o <cond>"
The construct is error-prone; "test" being built-in in most modern shells, the reason to avoid "test <cond> && test <cond>" spawning one extra process by using a single "test <cond> -a <cond>" no longer exists. Signed-off-by: Elia Pinto <gitter.spiros@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elia Pinto committed
Jun 10, 2014 at 05:28 UTC
496eeeb19b9c4adf743bf9acdc25d814e9c58a4e
1 file changed
+20
-12
git-submodule.sh
+20
-12
@@ -393,7 +393,7 @@ cmd_add()
393
sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
394
fi
395
396
- if test -z "$repo" -o -z "$sm_path"; then
396
+ if test -z "$repo" || test -z "$sm_path"; then
397
usage
398
fi
399
@@ -450,7 +450,7 @@ Use -f if you really want to add it." >&2
450
# perhaps the path exists and is already a git repo, else clone it
451
if test -e "$sm_path"
452
then
453
- if test -d "$sm_path"/.git -o -f "$sm_path"/.git
453
+ if test -d "$sm_path"/.git || test -f "$sm_path"/.git
454
then
455
eval_gettextln "Adding existing repo at '\$sm_path' to the index"
456
else
@@ -832,7 +832,7 @@ Maybe you want to use 'update --init'?")"
832
continue
833
fi
834
835
- if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
835
+ if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git
836
then
837
module_clone "$sm_path" "$name" "$url" "$reference" "$depth" || exit
838
cloned_modules="$cloned_modules;$name"
@@ -857,11 +857,11 @@ Maybe you want to use 'update --init'?")"
857
die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
858
fi
859
860
- if test "$subsha1" != "$sha1" -o -n "$force"
860
+ if test "$subsha1" != "$sha1" || test -n "$force"
861
then
862
subforce=$force
863
# If we don't already have a -f flag and the submodule has never been checked out
864
- if test -z "$subsha1" -a -z "$force"
864
+ if test -z "$subsha1" && test -z "$force"
865
then
866
subforce="-f"
867
fi
@@ -1031,7 +1031,7 @@ cmd_summary() {
1031
then
1032
head=$rev
1033
test $# = 0 || shift
1034
- elif test -z "$1" -o "$1" = "HEAD"
1034
+ elif test -z "$1" || test "$1" = "HEAD"
1035
then
1036
# before the first commit: compare with an empty tree
1037
head=$(git hash-object -w -t tree --stdin </dev/null)
@@ -1056,13 +1056,17 @@ cmd_summary() {
1056
while read mod_src mod_dst sha1_src sha1_dst status sm_path
1057
do
1058
# Always show modules deleted or type-changed (blob<->module)
1059
- test $status = D -o $status = T && echo "$sm_path" && continue
1059
+ if test "$status" = D || test "$status" = T
1060
+ then
1061
+ echo "$sm_path"
1062
+ continue
1063
+ fi
1064
# Respect the ignore setting for --for-status.
1065
if test -n "$for_status"
1066
then
1067
name=$(module_name "$sm_path")
1068
ignore_config=$(get_submodule_config "$name" ignore none)
1065
- test $status != A -a $ignore_config = all && continue
1069
+ test $status != A && test $ignore_config = all && continue
1070
fi
1071
# Also show added or modified modules which are checked out
1072
GIT_DIR="$sm_path/.git" git-rev-parse --git-dir >/dev/null 2>&1 &&
@@ -1122,7 +1126,7 @@ cmd_summary() {
1126
*)
1127
errmsg=
1128
total_commits=$(
1125
- if test $mod_src = 160000 -a $mod_dst = 160000
1129
+ if test $mod_src = 160000 && test $mod_dst = 160000
1130
then
1131
range="$sha1_src...$sha1_dst"
1132
elif test $mod_src = 160000
@@ -1159,7 +1163,7 @@ cmd_summary() {
1163
# i.e. deleted or changed to blob
1164
test $mod_dst = 160000 && echo "$errmsg"
1165
else
1162
- if test $mod_src = 160000 -a $mod_dst = 160000
1166
+ if test $mod_src = 160000 && test $mod_dst = 160000
1167
then
1168
limit=
1169
test $summary_limit -gt 0 && limit="-$summary_limit"
@@ -1230,7 +1234,11 @@ cmd_status()
1234
say "U$sha1 $displaypath"
1235
continue
1236
fi
1233
- if test -z "$url" || ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
1237
+ if test -z "$url" ||
1238
+ {
1239
+ ! test -d "$sm_path"/.git &&
1240
+ ! test -f "$sm_path"/.git
1241
+ }
1242
then
1243
say "-$sha1 $displaypath"
1244
continue;
@@ -1399,7 +1407,7 @@ then
1407
fi
1408
1409
# "--cached" is accepted only by "status" and "summary"
1402
-if test -n "$cached" && test "$command" != status -a "$command" != summary
1410
+if test -n "$cached" && test "$command" != status && test "$command" != summary
1411
then
1412
usage
1413
fi