git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Glen Choo via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Atharva Raykar" <raykar.ath@gmail.com>,
	"Glen Choo" <chooglen@google.com>,
	"Glen Choo" <chooglen@google.com>
Subject: [PATCH 5/8] submodule--helper update: use one param per type
Date: Fri, 10 Jun 2022 00:26:18 +0000	[thread overview]
Message-ID: <1bed100c12e851bf5697af6cb96275510ae52b2f.1654820781.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1275.git.git.1654820781.gitgitgadget@gmail.com>

From: Glen Choo <chooglen@google.com>

git-submodule.sh accepts literal 'update types' as options, but parses
them into a "--update" option for "git submodule--helper update", e.g.
"--checkout" becomes "--update=checkout".

Teach the 'update type' options to "git submodule--helper update" so
that we no longer have to do this parsing in git-submodule.sh, and
append them to `opts`.

Signed-off-by: Glen Choo <chooglen@google.com>
---
 builtin/submodule--helper.c | 37 ++++++++++++++++++++++++-------------
 git-submodule.sh            |  8 +++-----
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index a40f9f143e8..09510ebc026 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
 static void determine_submodule_update_strategy(struct repository *r,
 						int just_cloned,
 						const char *path,
-						const char *update,
+						enum submodule_update_type update,
 						struct submodule_update_strategy *out)
 {
 	const struct submodule *sub = submodule_from_path(r, null_oid(), path);
@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r,
 	key = xstrfmt("submodule.%s.update", sub->name);
 
 	if (update) {
-		if (parse_submodule_update_strategy(update, out) < 0)
-			die(_("Invalid update mode '%s' for submodule path '%s'"),
-				update, path);
+		out->type = update;
 	} else if (!repo_config_get_string_tmp(r, key, &val)) {
 		if (parse_submodule_update_strategy(val, out) < 0)
 			die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@@ -1882,7 +1880,6 @@ struct update_data {
 	const char *prefix;
 	const char *recursive_prefix;
 	const char *displaypath;
-	const char *update_default;
 	struct object_id suboid;
 	struct string_list references;
 	struct submodule_update_strategy update_strategy;
@@ -1892,6 +1889,7 @@ struct update_data {
 	int max_jobs;
 	int single_branch;
 	int recommend_shallow;
+	enum submodule_update_type update_default;
 	unsigned int require_init;
 	unsigned int force;
 	unsigned int quiet;
@@ -2429,8 +2427,20 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
 		strvec_push(args, "--require-init");
 	if (update_data->depth)
 		strvec_pushf(args, "--depth=%d", update_data->depth);
-	if (update_data->update_default)
-		strvec_pushl(args, "--update", update_data->update_default, NULL);
+	switch (update_data->update_default) {
+	case SM_UPDATE_MERGE:
+		strvec_push(args, "--merge");
+		break;
+	case SM_UPDATE_CHECKOUT:
+		strvec_push(args, "--checkout");
+		break;
+	case SM_UPDATE_REBASE:
+		strvec_push(args, "--rebase");
+		break;
+	default:
+		break;
+	}
+
 	if (update_data->references.nr) {
 		struct string_list_item *item;
 		for_each_string_list_item(item, &update_data->references)
@@ -2600,9 +2610,12 @@ static int module_update(int argc, const char **argv, const char *prefix)
 			   N_("path"),
 			   N_("path into the working tree, across nested "
 			      "submodule boundaries")),
-		OPT_STRING(0, "update", &opt.update_default,
-			   N_("string"),
-			   N_("rebase, merge, checkout or none")),
+		OPT_SET_INT(0, "checkout", &opt.update_default,
+			    N_("update using checkout"), SM_UPDATE_CHECKOUT),
+		OPT_SET_INT('r', "rebase", &opt.update_default,
+			    N_("update using rebase"), SM_UPDATE_REBASE),
+		OPT_SET_INT('m', "merge", &opt.update_default,
+			    N_("update using merge"), SM_UPDATE_MERGE),
 		OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
 			   N_("reference repository")),
 		OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2654,9 +2667,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
 	opt.filter_options = &filter_options;
 
 	if (opt.update_default)
-		if (parse_submodule_update_strategy(opt.update_default,
-						    &opt.update_strategy) < 0)
-			die(_("bad value for update parameter"));
+		opt.update_strategy.type = opt.update_default;
 
 	if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) {
 		list_objects_filter_release(&filter_options);
diff --git a/git-submodule.sh b/git-submodule.sh
index f61d12ccd21..d93b6dfbbd7 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -35,7 +35,6 @@ force=
 cached=
 recursive=
 files=
-update=
 prefix=
 custom_name=
 depth=
@@ -267,7 +266,7 @@ cmd_update()
 			opts="$opts $1"
 			;;
 		-r|--rebase)
-			update="rebase"
+			opts="$opts $1"
 			;;
 		--reference)
 			case "$2" in '') usage ;; esac
@@ -281,13 +280,13 @@ cmd_update()
 			opts="$opts $1"
 			;;
 		-m|--merge)
-			update="merge"
+			opts="$opts $1"
 			;;
 		--recursive)
 			opts="$opts $1"
 			;;
 		--checkout)
-			update="checkout"
+			opts="$opts $1"
 			;;
 		--recommend-shallow)
 			opts="$opts $1"
@@ -343,7 +342,6 @@ cmd_update()
 		${GIT_QUIET:+--quiet} \
 		${wt_prefix:+--prefix "$wt_prefix"} \
 		${prefix:+--recursive-prefix "$prefix"} \
-		${update:+--update "$update"} \
 		$opts \
 		-- \
 		"$@"
-- 
gitgitgadget


  parent reply	other threads:[~2022-06-10  0:26 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 ` Glen Choo via GitGitGadget [this message]
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   ` [RFC PATCH 10/20] git-submodule.sh: dispatch directly " Ævar Arnfjörð Bjarmason
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=1bed100c12e851bf5697af6cb96275510ae52b2f.1654820781.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=avarab@gmail.com \
    --cc=chooglen@google.com \
    --cc=git@vger.kernel.org \
    --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).