diff mbox series

[1/8] submodule update: remove intermediate parsing

Message ID 0eec4debd0498b22a2279e53f3b9548ae3d673da.1654820781.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series submodule update: parse all options in C | expand

Commit Message

Glen Choo June 10, 2022, 12:26 a.m. UTC
From: Glen Choo <chooglen@google.com>

When the cmd_*() functions in git-submodule.sh parse options, they
sometimes set an intermediate variable to "1", check if the variable is
set, and if so, pass a string option to "git submodule--helper".

In many cases, this parsing and unparsing is unnecessary because the
"git submodule--helper" command already understands the literal options
passed to "git submodule", e.g. when we see "--init", we don't need to
set "init=1" only to pass "${init:+--init}" again.

In cmd_update(), remove unnecessary "${variable+option}" expressions by
passing the literal option to "git submodule--helper update". Do this by
appending the string option into a catch-all "opts", so that the
intermediate variable becomes unused and can be removed.

This slightly changes the options we pass to "git submodule--helper
update" because we now pass every instance of the option instead of only
passing it once. This is probably a good thing though, because it's more
consistent to handle this in C instead of custom shell code.

Signed-off-by: Glen Choo <chooglen@google.com>
---
 git-submodule.sh | 25 ++++++++-----------------
 1 file changed, 8 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/git-submodule.sh b/git-submodule.sh
index fd0b4a2c947..f4679e0db80 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -38,17 +38,13 @@  recursive=
 init=
 require_init=
 files=
-remote=
-nofetch=
 update=
 prefix=
 custom_name=
 depth=
 progress=
 dissociate=
-single_branch=
 jobs=
-recommend_shallow=
 filter=
 
 isnumber()
@@ -246,6 +242,7 @@  cmd_deinit()
 #
 cmd_update()
 {
+	opts=
 	# parse $args after "submodule ... update".
 	while test $# -ne 0
 	do
@@ -257,7 +254,7 @@  cmd_update()
 			unset GIT_QUIET
 			;;
 		--progress)
-			progress=1
+			opts="$opts $1"
 			;;
 		-i|--init)
 			init=1
@@ -267,13 +264,13 @@  cmd_update()
 			require_init=1
 			;;
 		--remote)
-			remote=1
+			opts="$opts $1"
 			;;
 		-N|--no-fetch)
-			nofetch=1
+			opts="$opts $1"
 			;;
 		-f|--force)
-			force=$1
+			opts="$opts $1"
 			;;
 		-r|--rebase)
 			update="rebase"
@@ -287,13 +284,13 @@  cmd_update()
 			reference="$1"
 			;;
 		--dissociate)
-			dissociate=1
+			opts="$opts $1"
 			;;
 		-m|--merge)
 			update="merge"
 			;;
 		--recursive)
-			recursive=1
+			opts="$opts $1"
 			;;
 		--checkout)
 			update="checkout"
@@ -350,24 +347,18 @@  cmd_update()
 
 	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
 		${GIT_QUIET:+--quiet} \
-		${force:+--force} \
-		${progress:+"--progress"} \
-		${remote:+--remote} \
-		${recursive:+--recursive} \
 		${init:+--init} \
-		${nofetch:+--no-fetch} \
 		${wt_prefix:+--prefix "$wt_prefix"} \
 		${prefix:+--recursive-prefix "$prefix"} \
 		${update:+--update "$update"} \
 		${reference:+"$reference"} \
-		${dissociate:+"--dissociate"} \
 		${depth:+"$depth"} \
 		${require_init:+--require-init} \
-		${dissociate:+"--dissociate"} \
 		$single_branch \
 		$recommend_shallow \
 		$jobs \
 		$filter \
+		$opts \
 		-- \
 		"$@"
 }