Supplant the "while case ... break ;; esac" idiom
A lot of shell scripts contained stuff starting with while case "$#" in 0) break ;; esac and similar. I consider breaking out of the condition instead of the body od the loop ugly, and the implied "true" value of the non-matching case is not really obvious to humans at first glance. It happens not to be obvious to some BSD shells, either, but that's because they are not POSIX-compliant. In most cases, this has been replaced by a straight condition using "test". "case" has the advantage of being faster than "test" on vintage shells where "test" is not a builtin. Since none of them is likely to run the git scripts, anyway, the added readability should be worth the change. A few loops have had their termination condition expressed differently. Signed-off-by: David Kastrup <dak@gnu.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
b9fc6ea9ef
commit
822f7c7349
@ -9,7 +9,7 @@ SUBDIRECTORY_OK=Yes
|
|||||||
. git-sh-setup
|
. git-sh-setup
|
||||||
|
|
||||||
no_prune=:
|
no_prune=:
|
||||||
while case $# in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--prune)
|
--prune)
|
||||||
|
@ -14,7 +14,7 @@ username=
|
|||||||
list=
|
list=
|
||||||
verify=
|
verify=
|
||||||
LINES=0
|
LINES=0
|
||||||
while case "$#" in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-a)
|
-a)
|
||||||
|
@ -5,7 +5,7 @@ SUBDIRECTORY_OK='Yes'
|
|||||||
. git-sh-setup
|
. git-sh-setup
|
||||||
|
|
||||||
verbose=
|
verbose=
|
||||||
while case $# in 0) break;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
|
-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
|
||||||
|
@ -109,7 +109,7 @@ dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
|
|||||||
resolvemsg= resume=
|
resolvemsg= resume=
|
||||||
git_apply_opt=
|
git_apply_opt=
|
||||||
|
|
||||||
while case "$#" in 0) break;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-d=*|--d=*|--do=*|--dot=*|--dote=*|--dotes=*|--dotest=*)
|
-d=*|--d=*|--do=*|--dot=*|--dote=*|--dotes=*|--dotest=*)
|
||||||
|
@ -26,7 +26,7 @@ rmrf="rm -rf --"
|
|||||||
rm_refuse="echo Not removing"
|
rm_refuse="echo Not removing"
|
||||||
echo1="echo"
|
echo1="echo"
|
||||||
|
|
||||||
while case "$#" in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-d)
|
-d)
|
||||||
|
@ -89,7 +89,7 @@ force_author=
|
|||||||
only_include_assumed=
|
only_include_assumed=
|
||||||
untracked_files=
|
untracked_files=
|
||||||
templatefile="`git config commit.template`"
|
templatefile="`git config commit.template`"
|
||||||
while case "$#" in 0) break;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-F|--F|-f|--f|--fi|--fil|--file)
|
-F|--F|-f|--f|--fi|--fil|--file)
|
||||||
|
@ -27,7 +27,7 @@ shallow_depth=
|
|||||||
no_progress=
|
no_progress=
|
||||||
test -t 1 || no_progress=--no-progress
|
test -t 1 || no_progress=--no-progress
|
||||||
quiet=
|
quiet=
|
||||||
while case "$#" in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-a|--a|--ap|--app|--appe|--appen|--append)
|
-a|--a|--ap|--app|--appe|--appen|--append)
|
||||||
|
@ -105,8 +105,9 @@ filter_tag_name=
|
|||||||
filter_subdir=
|
filter_subdir=
|
||||||
orig_namespace=refs/original/
|
orig_namespace=refs/original/
|
||||||
force=
|
force=
|
||||||
while case "$#" in 0) usage;; esac
|
while :
|
||||||
do
|
do
|
||||||
|
test $# = 0 && usage
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
|
@ -61,7 +61,7 @@ stop_httpd () {
|
|||||||
test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
|
test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
while case "$#" in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--stop|stop)
|
--stop|stop)
|
||||||
|
@ -13,7 +13,7 @@ die () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exec=
|
exec=
|
||||||
while case "$#" in 0) break;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--h|--he|--hea|--head|--heads)
|
-h|--h|--he|--hea|--head|--heads)
|
||||||
|
@ -122,7 +122,7 @@ merge_name () {
|
|||||||
case "$#" in 0) usage ;; esac
|
case "$#" in 0) usage ;; esac
|
||||||
|
|
||||||
have_message=
|
have_message=
|
||||||
while case "$#" in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
|
-n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
|
||||||
|
@ -268,7 +268,7 @@ merge_file () {
|
|||||||
cleanup_temp_files
|
cleanup_temp_files
|
||||||
}
|
}
|
||||||
|
|
||||||
while case $# in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-t|--tool*)
|
-t|--tool*)
|
||||||
|
@ -16,7 +16,7 @@ test -z "$(git ls-files -u)" ||
|
|||||||
die "You are in the middle of a conflicted merge."
|
die "You are in the middle of a conflicted merge."
|
||||||
|
|
||||||
strategy_args= no_summary= no_commit= squash=
|
strategy_args= no_summary= no_commit= squash=
|
||||||
while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
|
while :
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
|
-n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
|
||||||
@ -46,8 +46,8 @@ do
|
|||||||
-h|--h|--he|--hel|--help)
|
-h|--h|--he|--hel|--help)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-*)
|
*)
|
||||||
# Pass thru anything that is meant for fetch.
|
# Pass thru anything that may be meant for fetch.
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -5,7 +5,7 @@ SUBDIRECTORY_ON=Yes
|
|||||||
|
|
||||||
dry_run=""
|
dry_run=""
|
||||||
quilt_author=""
|
quilt_author=""
|
||||||
while case "$#" in 0) break;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--au=*|--aut=*|--auth=*|--autho=*|--author=*)
|
--au=*|--aut=*|--auth=*|--autho=*|--author=*)
|
||||||
|
@ -317,7 +317,7 @@ do_rest () {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
while case $# in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--continue)
|
--continue)
|
||||||
|
@ -122,15 +122,14 @@ finish_rb_merge () {
|
|||||||
|
|
||||||
is_interactive () {
|
is_interactive () {
|
||||||
test -f "$dotest"/interactive ||
|
test -f "$dotest"/interactive ||
|
||||||
while case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
|
while :; do case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
|
||||||
do
|
|
||||||
shift
|
shift
|
||||||
done && test -n "$1"
|
done && test -n "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
is_interactive "$@" && exec git-rebase--interactive "$@"
|
is_interactive "$@" && exec git-rebase--interactive "$@"
|
||||||
|
|
||||||
while case "$#" in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--continue)
|
--continue)
|
||||||
|
@ -9,7 +9,7 @@ SUBDIRECTORY_OK='Yes'
|
|||||||
|
|
||||||
no_update_info= all_into_one= remove_redundant=
|
no_update_info= all_into_one= remove_redundant=
|
||||||
local= quiet= no_reuse= extra=
|
local= quiet= no_reuse= extra=
|
||||||
while case "$#" in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-n) no_update_info=t ;;
|
-n) no_update_info=t ;;
|
||||||
|
@ -11,7 +11,7 @@ require_work_tree
|
|||||||
update= reset_type=--mixed
|
update= reset_type=--mixed
|
||||||
unset rev
|
unset rev
|
||||||
|
|
||||||
while case $# in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--mixed | --soft | --hard)
|
--mixed | --soft | --hard)
|
||||||
|
@ -251,7 +251,7 @@ modules_list()
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
while case "$#" in 0) break ;; esac
|
while test $# != 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
add)
|
add)
|
||||||
|
Loading…
Reference in New Issue
Block a user