diff mbox series

[RFC,18/20] git-submodule.sh: simplify parsing loop

Message ID RFC-patch-18.20-c5796878f0b-20220610T011725Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series submodule: remove git-submodule.sh, create bare builtin/submodule.c | expand

Commit Message

Ævar Arnfjörð Bjarmason June 10, 2022, 2:01 a.m. UTC
Simplify the parsing loop so that we don't try to find out the
"$command" when looping over arguments initially, we'll only look for
the --quiet and --cached options.

Then if we have no more arguments we default to "status", otherwise we
emit our usage info. Most importantly we don't need to give --cache to
only "status" and "summary", instead we trust that "submodule--helper"
is checking those arguments, if some subcommands don't them they can
emit their own errors.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-submodule.sh | 44 +++++++++++++++++---------------------------
 1 file changed, 17 insertions(+), 27 deletions(-)
diff mbox series

Patch

diff --git a/git-submodule.sh b/git-submodule.sh
index cad9948c047..0274b253297 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -29,50 +29,40 @@  cd_to_toplevel
 GIT_PROTOCOL_FROM_USER=0
 export GIT_PROTOCOL_FROM_USER
 
-command=
 quiet=
 cached=
 
-while test $# != 0 && test -z "$command"
+while test $# != 0
 do
 	case "$1" in
-	add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs)
-		command=$1
-		;;
 	-q|--quiet)
-		quiet=1
+		quiet=1 &&
+		shift
 		;;
 	--cached)
-		cached=1
-		;;
-	--)
-		break
-		;;
-	-*)
-		usage
+		cached=1 &&
+		shift
 		;;
 	*)
 		break
 		;;
 	esac
-	shift
 done
 
 # No command word defaults to "status"
-if test -z "$command"
+command=
+if test $# = 0
 then
-    if test $# = 0
-    then
 	command=status
-    else
-	usage
-    fi
-fi
-
-# "--cached" is accepted only by "status" and "summary"
-if test -n "$cached" && test "$command" != status && test "$command" != summary
-then
-	usage
+else
+	case "$1" in
+	add | foreach | init | deinit | update | set-branch | set-url | status | summary | sync | absorbgitdirs)
+		command=$1 &&
+		shift
+		;;
+	*)
+		usage
+	esac
 fi
 
 case "$command" in
@@ -83,7 +73,7 @@  update)
 	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \
 		${quiet:+--quiet} ${wt_prefix:+--prefix "$wt_prefix"} "$@"
 	;;
-add | foreach | init | deinit | set-branch | set-url | status | summary | sync)
+*)
 	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \
 		${quiet:+--quiet} ${cached:+--cached} "$@"
 	;;