git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Glen Choo" <chooglen@google.com>,
	"Atharva Raykar" <raykar.ath@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [RFC PATCH 10/20] git-submodule.sh: dispatch directly to helper
Date: Fri, 10 Jun 2022 04:01:22 +0200	[thread overview]
Message-ID: <RFC-patch-10.20-498a1fd275b-20220610T011725Z-avarab@gmail.com> (raw)
In-Reply-To: <RFC-cover-00.20-00000000000-20220610T011725Z-avarab@gmail.com>

Change the dispatching logic in "git-submodule.sh" for the "add",
"init", "deinit", "set-branch", "set-url", "summary" and "status"
sub-commands to do away with the argument parsing in git-submodule.sh,
and instead dispatch directly to "git submodule--helper".

As in a preceding commit the only functional change here should be
that on invalid options we'll now emit more targeted "-h" output.

The isnumber() helper function was only used in the now-removed
cmd_summary(), the same goes for the $files variable. The $custom_name
and $branch variables were only used in cmd_add().

Since there are no dashed commands anymore in git-submodule.sh we can
get rid of the "$(echo | sed ...)" one-liner to change e.g. "set-url"
to "set_url".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 git-submodule.sh | 321 +----------------------------------------------
 1 file changed, 5 insertions(+), 316 deletions(-)

diff --git a/git-submodule.sh b/git-submodule.sh
index ddc2e4e4032..61e4f17b805 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -30,18 +30,15 @@ GIT_PROTOCOL_FROM_USER=0
 export GIT_PROTOCOL_FROM_USER
 
 command=
-branch=
 force=
 reference=
 cached=
 recursive=
 init=
 require_init=
-files=
 remote=
 nofetch=
 update=
-custom_name=
 depth=
 progress=
 dissociate=
@@ -50,86 +47,7 @@ jobs=
 recommend_shallow=
 filter=
 
-isnumber()
-{
-	n=$(($1 + 0)) 2>/dev/null && test "$n" = "$1"
-}
-
-#
-# Add a new submodule to the working tree, .gitmodules and the index
-#
-# $@ = repo path
-#
-# optional branch is stored in global branch variable
-#
-cmd_add()
-{
-	# parse $args after "submodule ... add".
-	reference_path=
-	while test $# -ne 0
-	do
-		case "$1" in
-		-b | --branch)
-			case "$2" in '') usage ;; esac
-			branch=$2
-			shift
-			;;
-		-f | --force)
-			force=$1
-			;;
-		-q|--quiet)
-			GIT_QUIET=1
-			;;
-		--progress)
-			progress=1
-			;;
-		--reference)
-			case "$2" in '') usage ;; esac
-			reference_path=$2
-			shift
-			;;
-		--reference=*)
-			reference_path="${1#--reference=}"
-			;;
-		--dissociate)
-			dissociate=1
-			;;
-		--name)
-			case "$2" in '') usage ;; esac
-			custom_name=$2
-			shift
-			;;
-		--depth)
-			case "$2" in '') usage ;; esac
-			depth="--depth=$2"
-			shift
-			;;
-		--depth=*)
-			depth=$1
-			;;
-		--)
-			shift
-			break
-			;;
-		-*)
-			usage
-			;;
-		*)
-			break
-			;;
-		esac
-		shift
-	done
-
-	if test -z "$1"
-	then
-		usage
-	fi
-
-	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper add ${GIT_QUIET:+--quiet} ${force:+--force} ${progress:+"--progress"} ${branch:+--branch "$branch"} ${reference_path:+--reference "$reference_path"} ${dissociate:+--dissociate} ${custom_name:+--name "$custom_name"} ${depth:+"$depth"} -- "$@"
-}
 
-#
 # Execute an arbitrary command sequence in each checked out
 # submodule
 #
@@ -160,73 +78,6 @@ cmd_foreach()
 	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper foreach ${GIT_QUIET:+--quiet} ${recursive:+--recursive} -- "$@"
 }
 
-#
-# Register submodules in .git/config
-#
-# $@ = requested paths (default to all)
-#
-cmd_init()
-{
-	# parse $args after "submodule ... init".
-	while test $# -ne 0
-	do
-		case "$1" in
-		-q|--quiet)
-			GIT_QUIET=1
-			;;
-		--)
-			shift
-			break
-			;;
-		-*)
-			usage
-			;;
-		*)
-			break
-			;;
-		esac
-		shift
-	done
-
-	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} -- "$@"
-}
-
-#
-# Unregister submodules from .git/config and remove their work tree
-#
-cmd_deinit()
-{
-	# parse $args after "submodule ... deinit".
-	deinit_all=
-	while test $# -ne 0
-	do
-		case "$1" in
-		-f|--force)
-			force=$1
-			;;
-		-q|--quiet)
-			GIT_QUIET=1
-			;;
-		--all)
-			deinit_all=t
-			;;
-		--)
-			shift
-			break
-			;;
-		-*)
-			usage
-			;;
-		*)
-			break
-			;;
-		esac
-		shift
-	done
-
-	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper deinit ${GIT_QUIET:+--quiet} ${force:+--force} ${deinit_all:+--all} -- "$@"
-}
-
 #
 # Update each submodule path to correct revision, using clone and checkout as needed
 #
@@ -359,168 +210,6 @@ cmd_update()
 		"$@"
 }
 
-#
-# Configures a submodule's default branch
-#
-# $@ = requested path
-#
-cmd_set_branch() {
-	default=
-	branch=
-
-	while test $# -ne 0
-	do
-		case "$1" in
-		-q|--quiet)
-			# we don't do anything with this but we need to accept it
-			;;
-		-d|--default)
-			default=1
-			;;
-		-b|--branch)
-			case "$2" in '') usage ;; esac
-			branch=$2
-			shift
-			;;
-		--)
-			shift
-			break
-			;;
-		-*)
-			usage
-			;;
-		*)
-			break
-			;;
-		esac
-		shift
-	done
-
-	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-branch ${GIT_QUIET:+--quiet} ${branch:+--branch "$branch"} ${default:+--default} -- "$@"
-}
-
-#
-# Configures a submodule's remote url
-#
-# $@ = requested path, requested url
-#
-cmd_set_url() {
-	while test $# -ne 0
-	do
-		case "$1" in
-		-q|--quiet)
-			GIT_QUIET=1
-			;;
-		--)
-			shift
-			break
-			;;
-		-*)
-			usage
-			;;
-		*)
-			break
-			;;
-		esac
-		shift
-	done
-
-	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@"
-}
-
-#
-# Show commit summary for submodules in index or working tree
-#
-# If '--cached' is given, show summary between index and given commit,
-# or between working tree and given commit
-#
-# $@ = [commit (default 'HEAD'),] requested paths (default all)
-#
-cmd_summary() {
-	summary_limit=-1
-	for_status=
-	diff_cmd=diff-index
-
-	# parse $args after "submodule ... summary".
-	while test $# -ne 0
-	do
-		case "$1" in
-		--cached)
-			cached=1
-			;;
-		--files)
-			files="$1"
-			;;
-		--for-status)
-			for_status="$1"
-			;;
-		-n|--summary-limit)
-			summary_limit="$2"
-			isnumber "$summary_limit" || usage
-			shift
-			;;
-		--summary-limit=*)
-			summary_limit="${1#--summary-limit=}"
-			isnumber "$summary_limit" || usage
-			;;
-		--)
-			shift
-			break
-			;;
-		-*)
-			usage
-			;;
-		*)
-			break
-			;;
-		esac
-		shift
-	done
-
-	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper summary ${files:+--files} ${cached:+--cached} ${for_status:+--for-status} ${summary_limit:+-n $summary_limit} -- "$@"
-}
-#
-# List all submodules, prefixed with:
-#  - submodule not initialized
-#  + different revision checked out
-#
-# If --cached was specified the revision in the index will be printed
-# instead of the currently checked out revision.
-#
-# $@ = requested paths (default to all)
-#
-cmd_status()
-{
-	# parse $args after "submodule ... status".
-	while test $# -ne 0
-	do
-		case "$1" in
-		-q|--quiet)
-			GIT_QUIET=1
-			;;
-		--cached)
-			cached=1
-			;;
-		--recursive)
-			recursive=1
-			;;
-		--)
-			shift
-			break
-			;;
-		-*)
-			usage
-			;;
-		*)
-			break
-			;;
-		esac
-		shift
-	done
-
-	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper status ${GIT_QUIET:+--quiet} ${cached:+--cached} ${recursive:+--recursive} -- "$@"
-}
-
 # This loop parses the command line arguments to find the
 # subcommand name to dispatch.  Parsing of the subcommand specific
 # options are primarily done by the subcommand implementations.
@@ -573,11 +262,11 @@ case "$command" in
 absorbgitdirs)
 	git submodule--helper "$command" --prefix "$wt_prefix" "$@"
 	;;
-sync)
-	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \
-		${GIT_QUIET:+--quiet} "$@"
+foreach | update)
+	"cmd_$command" "$@"
 	;;
-*)
-	"cmd_$(echo $command | sed -e s/-/_/g)" "$@"
+add | init | deinit | set-branch | set-url | status | summary | sync)
+	git ${wt_prefix:+-C "$wt_prefix"} submodule--helper "$command" \
+		${GIT_QUIET:+--quiet} ${cached:+--cached} "$@"
 	;;
 esac
-- 
2.36.1.1178.gb5b1747c546


  parent reply	other threads:[~2022-06-10  2:02 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10  0:26 [PATCH 0/8] [RFC] submodule update: parse all options in C Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 1/8] submodule update: remove intermediate parsing Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 2/8] submodule update: pass options containing "[no-]" Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 3/8] submodule update: pass options with stuck forms Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 4/8] submodule update: pass --require-init and --init Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 5/8] submodule--helper update: use one param per type Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 6/8] submodule update: remove -v, pass --quiet Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 7/8] submodule update: stop parsing options in .sh Glen Choo via GitGitGadget
2022-06-10  0:26 ` [PATCH 8/8] submodule update: remove never-used expansion Glen Choo via GitGitGadget
2022-06-10  2:01 ` [RFC PATCH 00/20] submodule: remove git-submodule.sh, create bare builtin/submodule.c Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 01/20] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 02/20] git-submodule.sh: remove unused $prefix variable Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 03/20] git-submodule.sh: remove unused --super-prefix logic Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 04/20] git-submodule.sh: normalize parsing of "--branch" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 05/20] git-submodule.sh: normalize parsing of --cached Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 06/20] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 07/20] git-submodule.sh: create a "case" dispatch statement Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 08/20] submodule--helper: pretend to be "git submodule" in "-h" output Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 09/20] git-submodule.sh: dispatch "sync" to helper Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` Ævar Arnfjörð Bjarmason [this message]
2022-06-10  2:01   ` [RFC PATCH 11/20] git-submodule.sh: dispatch "foreach" " Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 12/20] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 13/20] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 14/20] git-submodule doc: document the -v" option to "update" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 15/20] submodule--helper: understand -v option for "update" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 16/20] git-submodule.sh: dispatch "update" to helper Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 17/20] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 18/20] git-submodule.sh: simplify parsing loop Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 19/20] submodule: make it a built-in, remove git-submodule.sh Ævar Arnfjörð Bjarmason
2022-06-10  2:01   ` [RFC PATCH 20/20] submodule: add a subprocess-less submodule.useBuiltin setting Ævar Arnfjörð Bjarmason
2022-06-13 19:07   ` [RFC PATCH 00/20] submodule: remove git-submodule.sh, create bare builtin/submodule.c Glen Choo
2022-06-13 22:38     ` [PATCH v2 00/12] submodule: make "git submodule--helper" behave like "git submodule" Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 01/12] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 03/12] git-submodule.sh: make "$cached" variable a boolean Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 04/12] git-submodule.sh: remove unused top-level "--branch" argument Ævar Arnfjörð Bjarmason
2022-06-15  0:10         ` Glen Choo
2022-06-13 22:38       ` [PATCH v2 05/12] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason
2022-06-15  0:19         ` Glen Choo
2022-06-13 22:38       ` [PATCH v2 06/12] submodule update: remove "-v" option Ævar Arnfjörð Bjarmason
2022-06-15  0:29         ` Glen Choo
2022-06-13 22:38       ` [PATCH v2 07/12] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason
2022-06-13 22:38       ` [PATCH v2 08/12] submodule--helper: report "submodule" as our name in "-h" output Ævar Arnfjörð Bjarmason
2022-06-15  3:34         ` Glen Choo
2022-06-15  4:01         ` Glen Choo
2022-06-15  9:42           ` Ævar Arnfjörð Bjarmason
2022-06-13 22:39       ` [PATCH v2 09/12] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason
2022-06-13 22:39       ` [PATCH v2 10/12] submodule--helper: eliminate internal "--update" option Ævar Arnfjörð Bjarmason
2022-06-15 16:52         ` Glen Choo
2022-06-13 22:39       ` [PATCH v2 11/12] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason
2022-06-13 22:39       ` [PATCH v2 12/12] git-sh-setup.sh: remove "say" function, change last users Ævar Arnfjörð Bjarmason
2022-06-15 16:58         ` Glen Choo
2022-06-13 23:09       ` [PATCH v2 00/12] submodule: make "git submodule--helper" behave like "git submodule" Glen Choo
2022-06-13 23:31         ` Ævar Arnfjörð Bjarmason
2022-06-15  0:00           ` Glen Choo
2022-06-15 18:42       ` Glen Choo
2022-06-22 14:27       ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2022-06-22 14:27         ` [PATCH v3 01/12] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason
2022-06-22 14:27         ` [PATCH v3 02/12] git-submodule.sh: remove unused $prefix var and --super-prefix Ævar Arnfjörð Bjarmason
2022-06-22 23:43           ` Glen Choo
2022-06-24 15:07             ` Ævar Arnfjörð Bjarmason
2022-06-24 16:48               ` Glen Choo
2022-06-22 14:27         ` [PATCH v3 03/12] git-submodule.sh: make the "$cached" variable a boolean Ævar Arnfjörð Bjarmason
2022-06-22 14:27         ` [PATCH v3 04/12] git-submodule.sh: remove unused top-level "--branch" argument Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 05/12] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 06/12] submodule update: remove "-v" option Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 07/12] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 08/12] submodule--helper: report "submodule" as our name in some "-h" output Ævar Arnfjörð Bjarmason
2022-06-22 18:28           ` Glen Choo
2022-06-22 14:28         ` [PATCH v3 09/12] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason
2022-06-22 18:57           ` Glen Choo
2022-06-22 19:04             ` Glen Choo
2022-06-22 14:28         ` [PATCH v3 10/12] submodule--helper: eliminate internal "--update" option Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 11/12] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason
2022-06-22 14:28         ` [PATCH v3 12/12] git-sh-setup.sh: remove "say" function, change last users Ævar Arnfjörð Bjarmason
2022-06-24  3:39         ` [PATCH v3 00/12] submodule: make "git submodule--helper" behave like "git submodule" Glen Choo
2022-06-28 10:05         ` [PATCH v4 " Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 01/12] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 02/12] git-submodule.sh: remove unused $prefix variable Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 03/12] git-submodule.sh: make the "$cached" variable a boolean Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 04/12] git-submodule.sh: remove unused top-level "--branch" argument Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 05/12] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 06/12] submodule update: remove "-v" option Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 07/12] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 08/12] submodule--helper: report "submodule" as our name in some "-h" output Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 09/12] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 10/12] submodule--helper: eliminate internal "--update" option Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 11/12] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason
2022-06-28 10:05           ` [PATCH v4 12/12] git-sh-setup.sh: remove "say" function, change last users Ævar Arnfjörð Bjarmason
2022-06-28 16:52           ` [PATCH v4 00/12] submodule: make "git submodule--helper" behave like "git submodule" Glen Choo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=RFC-patch-10.20-498a1fd275b-20220610T011725Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=chooglen@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=raykar.ath@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).