@matheusbsbs / matheus-bagliano / commits / 822f7c7349
Fork 0

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>

David Kastrup committed Sep 23, 2007 at 22:42 UTC 822f7c7349d61f6075961ce42c1bd1a85cf999e5
19 files changed +23 -23
contrib/examples/git-gc.sh
+1 -1
@@ -9,7 +9,7 @@ SUBDIRECTORY_OK=Yes
9 . git-sh-setup
10
11 no_prune=:
12 -while case $# in 0) break ;; esac
12 +while test $# != 0
13 do
14 case "$1" in
15 --prune)
contrib/examples/git-tag.sh
+1 -1
@@ -14,7 +14,7 @@ username=
14 list=
15 verify=
16 LINES=0
17 -while case "$#" in 0) break ;; esac
17 +while test $# != 0
18 do
19 case "$1" in
20 -a)
contrib/examples/git-verify-tag.sh
+1 -1
@@ -5,7 +5,7 @@ SUBDIRECTORY_OK='Yes'
5 . git-sh-setup
6
7 verbose=
8 -while case $# in 0) break;; esac
8 +while test $# != 0
9 do
10 case "$1" in
11 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
git-am.sh
+1 -1
@@ -109,7 +109,7 @@ dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
109 resolvemsg= resume=
110 git_apply_opt=
111
112 -while case "$#" in 0) break;; esac
112 +while test $# != 0
113 do
114 case "$1" in
115 -d=*|--d=*|--do=*|--dot=*|--dote=*|--dotes=*|--dotest=*)
git-clean.sh
+1 -1
@@ -26,7 +26,7 @@ rmrf="rm -rf --"
26 rm_refuse="echo Not removing"
27 echo1="echo"
28
29 -while case "$#" in 0) break ;; esac
29 +while test $# != 0
30 do
31 case "$1" in
32 -d)
git-commit.sh
+1 -1
@@ -89,7 +89,7 @@ force_author=
89 only_include_assumed=
90 untracked_files=
91 templatefile="`git config commit.template`"
92 -while case "$#" in 0) break;; esac
92 +while test $# != 0
93 do
94 case "$1" in
95 -F|--F|-f|--f|--fi|--fil|--file)
git-fetch.sh
+1 -1
@@ -27,7 +27,7 @@ shallow_depth=
27 no_progress=
28 test -t 1 || no_progress=--no-progress
29 quiet=
30 -while case "$#" in 0) break ;; esac
30 +while test $# != 0
31 do
32 case "$1" in
33 -a|--a|--ap|--app|--appe|--appen|--append)
git-filter-branch.sh
+2 -1
@@ -105,8 +105,9 @@ filter_tag_name=
105 filter_subdir=
106 orig_namespace=refs/original/
107 force=
108 -while case "$#" in 0) usage;; esac
108 +while :
109 do
110 + test $# = 0 && usage
111 case "$1" in
112 --)
113 shift
git-instaweb.sh
+1 -1
@@ -61,7 +61,7 @@ stop_httpd () {
61 test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
62 }
63
64 -while case "$#" in 0) break ;; esac
64 +while test $# != 0
65 do
66 case "$1" in
67 --stop|stop)
git-ls-remote.sh
+1 -1
@@ -13,7 +13,7 @@ die () {
13 }
14
15 exec=
16 -while case "$#" in 0) break;; esac
16 +while test $# != 0
17 do
18 case "$1" in
19 -h|--h|--he|--hea|--head|--heads)
git-merge.sh
+1 -1
@@ -122,7 +122,7 @@ merge_name () {
122 case "$#" in 0) usage ;; esac
123
124 have_message=
125 -while case "$#" in 0) break ;; esac
125 +while test $# != 0
126 do
127 case "$1" in
128 -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
git-mergetool.sh
+1 -1
@@ -268,7 +268,7 @@ merge_file () {
268 cleanup_temp_files
269 }
270
271 -while case $# in 0) break ;; esac
271 +while test $# != 0
272 do
273 case "$1" in
274 -t|--tool*)
git-pull.sh
+3 -3
@@ -16,7 +16,7 @@ test -z "$(git ls-files -u)" ||
16 die "You are in the middle of a conflicted merge."
17
18 strategy_args= no_summary= no_commit= squash=
19 -while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
19 +while :
20 do
21 case "$1" in
22 -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
@@ -46,8 +46,8 @@ do
46 -h|--h|--he|--hel|--help)
47 usage
48 ;;
49 - -*)
50 - # Pass thru anything that is meant for fetch.
49 + *)
50 + # Pass thru anything that may be meant for fetch.
51 break
52 ;;
53 esac
git-quiltimport.sh
+1 -1
@@ -5,7 +5,7 @@ SUBDIRECTORY_ON=Yes
5
6 dry_run=""
7 quilt_author=""
8 -while case "$#" in 0) break;; esac
8 +while test $# != 0
9 do
10 case "$1" in
11 --au=*|--aut=*|--auth=*|--autho=*|--author=*)
git-rebase--interactive.sh
+1 -1
@@ -317,7 +317,7 @@ do_rest () {
317 done
318 }
319
320 -while case $# in 0) break ;; esac
320 +while test $# != 0
321 do
322 case "$1" in
323 --continue)
git-rebase.sh
+2 -3
@@ -122,15 +122,14 @@ finish_rb_merge () {
122
123 is_interactive () {
124 test -f "$dotest"/interactive ||
125 - while case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
126 - do
125 + while :; do case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
126 shift
127 done && test -n "$1"
128 }
129
130 is_interactive "$@" && exec git-rebase--interactive "$@"
131
133 -while case "$#" in 0) break ;; esac
132 +while test $# != 0
133 do
134 case "$1" in
135 --continue)
git-repack.sh
+1 -1
@@ -9,7 +9,7 @@ SUBDIRECTORY_OK='Yes'
9
10 no_update_info= all_into_one= remove_redundant=
11 local= quiet= no_reuse= extra=
12 -while case "$#" in 0) break ;; esac
12 +while test $# != 0
13 do
14 case "$1" in
15 -n) no_update_info=t ;;
git-reset.sh
+1 -1
@@ -11,7 +11,7 @@ require_work_tree
11 update= reset_type=--mixed
12 unset rev
13
14 -while case $# in 0) break ;; esac
14 +while test $# != 0
15 do
16 case "$1" in
17 --mixed | --soft | --hard)
git-submodule.sh
+1 -1
@@ -251,7 +251,7 @@ modules_list()
251 done
252 }
253
254 -while case "$#" in 0) break ;; esac
254 +while test $# != 0
255 do
256 case "$1" in
257 add)