]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Supplant the "while case ... break ;; esac" idiom
authorDavid Kastrup <dak@gnu.org>
Sun, 23 Sep 2007 20:42:08 +0000 (22:42 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 23 Sep 2007 23:12:00 +0000 (16:12 -0700)
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>
19 files changed:
contrib/examples/git-gc.sh
contrib/examples/git-tag.sh
contrib/examples/git-verify-tag.sh
git-am.sh
git-clean.sh
git-commit.sh
git-fetch.sh
git-filter-branch.sh
git-instaweb.sh
git-ls-remote.sh
git-merge.sh
git-mergetool.sh
git-pull.sh
git-quiltimport.sh
git-rebase--interactive.sh
git-rebase.sh
git-repack.sh
git-reset.sh
git-submodule.sh

index 2ae235b081ea9829a51758bba5a0d0d64111d32c..1597e9f33f5e001995085639a448f1214010b561 100755 (executable)
@@ -9,7 +9,7 @@ SUBDIRECTORY_OK=Yes
 . git-sh-setup
 
 no_prune=:
-while case $# in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        --prune)
index 5ee3f50a3c083aa0685ad696fd1bc39b3ffbe607..ae7c5316664ce3aa14c567ddd9866499a5714eb7 100755 (executable)
@@ -14,7 +14,7 @@ username=
 list=
 verify=
 LINES=0
-while case "$#" in 0) break ;; esac
+while test $# != 0
 do
     case "$1" in
     -a)
index 37b0023b270928cd80e0a6456c3d34d8173c975b..0902a5c21adc4123e36856f73acc1409e17eb0ac 100755 (executable)
@@ -5,7 +5,7 @@ SUBDIRECTORY_OK='Yes'
 . git-sh-setup
 
 verbose=
-while case $# in 0) break;; esac
+while test $# != 0
 do
        case "$1" in
        -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
index 6809aa07f60165855ebc0192750e85569f9685ff..b66173c0cd8e7908c1ac9ffc9c9a6a91160849a0 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -109,7 +109,7 @@ dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
 resolvemsg= resume=
 git_apply_opt=
 
-while case "$#" in 0) break;; esac
+while test $# != 0
 do
        case "$1" in
        -d=*|--d=*|--do=*|--dot=*|--dote=*|--dotes=*|--dotest=*)
index a5cfd9f07a48b97ceebfe54e88fdcc519c3e0015..44917381863e27de6bedc91fa742eb0f8211a492 100755 (executable)
@@ -26,7 +26,7 @@ rmrf="rm -rf --"
 rm_refuse="echo Not removing"
 echo1="echo"
 
-while case "$#" in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        -d)
index bb113e858b73945a1c637024277415cc5ad8f436..7a7a2cb4b47c62d4826aabd9d90a7af26427f980 100755 (executable)
@@ -89,7 +89,7 @@ force_author=
 only_include_assumed=
 untracked_files=
 templatefile="`git config commit.template`"
-while case "$#" in 0) break;; esac
+while test $# != 0
 do
        case "$1" in
        -F|--F|-f|--f|--fi|--fil|--file)
index c3a200120df636fe8db0f02902d92c351c6c5e2e..e44af2c86d8e7e44bc79aafcc8ccef3806804720 100755 (executable)
@@ -27,7 +27,7 @@ shallow_depth=
 no_progress=
 test -t 1 || no_progress=--no-progress
 quiet=
-while case "$#" in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        -a|--a|--ap|--app|--appe|--appen|--append)
index a4b6577bd496819232754c1275b7c1e798b0470c..a12f6c2d4c7ad3c4f69a783f7255b3010224d0c3 100755 (executable)
@@ -105,8 +105,9 @@ filter_tag_name=
 filter_subdir=
 orig_namespace=refs/original/
 force=
-while case "$#" in 0) usage;; esac
+while :
 do
+       test $# = 0 && usage
        case "$1" in
        --)
                shift
index b79c6b6a42069168daf4e4ff191d08835f96e40f..f5629e7439955666b1755177135ac7ac198bad54 100755 (executable)
@@ -61,7 +61,7 @@ stop_httpd () {
        test -f "$fqgitdir/pid" && kill `cat "$fqgitdir/pid"`
 }
 
-while case "$#" in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        --stop|stop)
index b7e5d0458470248e65da0893b8b9bb4ced9152da..d56cf92ebfa685fd724a47e1ca753f0735dbd5bd 100755 (executable)
@@ -13,7 +13,7 @@ die () {
 }
 
 exec=
-while case "$#" in 0) break;; esac
+while test $# != 0
 do
   case "$1" in
   -h|--h|--he|--hea|--head|--heads)
index 3a01db0d751e272541efd0f27177a9ca5cb63bbe..cde09d4d602811b610e0d744f4e8ede6f9fb0a39 100755 (executable)
@@ -122,7 +122,7 @@ merge_name () {
 case "$#" in 0) usage ;; esac
 
 have_message=
-while case "$#" in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
index 47a80553ad3283c49cae0fbffcf444b93c8e34b7..a0e44f71c4acd5d995bf823913ba63e119ed2e68 100755 (executable)
@@ -268,7 +268,7 @@ merge_file () {
     cleanup_temp_files
 }
 
-while case $# in 0) break ;; esac
+while test $# != 0
 do
     case "$1" in
        -t|--tool*)
index 5e96d1f228da506b11452abec70e7c50d8907733..c3f05f56de300ad48d940def184698fb37c40028 100755 (executable)
@@ -16,7 +16,7 @@ test -z "$(git ls-files -u)" ||
        die "You are in the middle of a conflicted merge."
 
 strategy_args= no_summary= no_commit= squash=
-while case "$#,$1" in 0) break ;; *,-*) ;; *) break ;; esac
+while :
 do
        case "$1" in
        -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
@@ -46,8 +46,8 @@ do
        -h|--h|--he|--hel|--help)
                usage
                ;;
-       -*)
-               # Pass thru anything that is meant for fetch.
+       *)
+               # Pass thru anything that may be meant for fetch.
                break
                ;;
        esac
index 9de54d19fbc96c18ad52b1fe6b1126432d40f17a..74a54d5d08f86ebbd6a4b3af1f6950dbfd91c743 100755 (executable)
@@ -5,7 +5,7 @@ SUBDIRECTORY_ON=Yes
 
 dry_run=""
 quilt_author=""
-while case "$#" in 0) break;; esac
+while test $# != 0
 do
        case "$1" in
        --au=*|--aut=*|--auth=*|--autho=*|--author=*)
index abc2b1c3e06bf1904ed92a691e917e8718e9e299..2fa53fdaeb3a24495f023e1f1f79da23e7e34f7c 100755 (executable)
@@ -317,7 +317,7 @@ do_rest () {
        done
 }
 
-while case $# in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        --continue)
index 3bd66b0a04bac05a3447d68112d4d933480eaf04..058fcacb7eea33128436fa04c0412370562e9ff0 100755 (executable)
@@ -122,15 +122,14 @@ finish_rb_merge () {
 
 is_interactive () {
        test -f "$dotest"/interactive ||
-       while case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
-       do
+       while :; do case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
                shift
        done && test -n "$1"
 }
 
 is_interactive "$@" && exec git-rebase--interactive "$@"
 
-while case "$#" in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        --continue)
index 156c5e8f4aa2f6c04e33af323ef43356fd336adb..0aae1a3ed5571a010f80438f8e8a0fc7eb0dc285 100755 (executable)
@@ -9,7 +9,7 @@ SUBDIRECTORY_OK='Yes'
 
 no_update_info= all_into_one= remove_redundant=
 local= quiet= no_reuse= extra=
-while case "$#" in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        -n)     no_update_info=t ;;
index 1dc606fbd3fd29f5f4c9928a2518df46109ef449..bafeb52cd113ad8a07ffd1912191f2bc17a7ef7a 100755 (executable)
@@ -11,7 +11,7 @@ require_work_tree
 update= reset_type=--mixed
 unset rev
 
-while case $# in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        --mixed | --soft | --hard)
index 3320998c76ba72094755ec60369a6266751889ff..673aa27a452b11af62d89986bf21c8a4f10e0c41 100755 (executable)
@@ -251,7 +251,7 @@ modules_list()
        done
 }
 
-while case "$#" in 0) break ;; esac
+while test $# != 0
 do
        case "$1" in
        add)