git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Glen Choo via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Atharva Raykar" <raykar.ath@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Johannes Schindelin" <johannes.schindelin@gmx.de>,
	"Glen Choo" <chooglen@google.com>,
	"Glen Choo" <chooglen@google.com>
Subject: [PATCH v2 10/18] submodule--helper: eliminate internal "--update" option
Date: Thu, 30 Jun 2022 21:19:30 +0000	[thread overview]
Message-ID: <b788fc671bf1862a72f9fe7256affd7d152b8a6f.1656623978.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1282.v2.git.git.1656623978.gitgitgadget@gmail.com>

From: Glen Choo <chooglen@google.com>

Follow-up on the preceding commit which taught "git submodule--helper
update" to understand "--merge", "--checkout" and "--rebase" and use
those options instead of "--update=(rebase|merge|checkout|none)" when
the command invokes itself.

Unlike the preceding change this isn't strictly necessary to
eventually change "git-submodule.sh" so that it invokes "git
submodule--helper update" directly, but let's remove this
inconsistency in the command-line interface. We shouldn't need to
carry special synonyms for existing options in "git submodule--helper"
when that command can use the primary documented names instead.

But, as seen in the post-image this makes the control flow within
"builtin/submodule--helper.c" simpler, we can now write directly to
the "update_default" member of "struct update_data" when parsing the
options in "module_update()".

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/submodule--helper.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 53179472d85..389b900602f 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,7 @@ struct update_data {
 	const char *prefix;
 	const char *recursive_prefix;
 	const char *displaypath;
-	const char *update_default;
+	enum submodule_update_type update_default;
 	struct object_id suboid;
 	struct string_list references;
 	struct submodule_update_strategy update_strategy;
@@ -2423,6 +2421,8 @@ static const char *submodule_update_type_to_label(enum submodule_update_type typ
 
 static void update_data_to_args(struct update_data *update_data, struct strvec *args)
 {
+	enum submodule_update_type update_type = update_data->update_default;
+
 	strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
 	strvec_pushf(args, "--jobs=%d", update_data->max_jobs);
 	if (update_data->recursive_prefix)
@@ -2446,8 +2446,10 @@ 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);
+	if (update_type != SM_UPDATE_UNSPECIFIED)
+		strvec_pushf(args, "--%s",
+			     submodule_update_type_to_label(update_type));
+
 	if (update_data->references.nr) {
 		struct string_list_item *item;
 		for_each_string_list_item(item, &update_data->references)
@@ -2599,7 +2601,6 @@ static int module_update(int argc, const char **argv, const char *prefix)
 	struct update_data opt = UPDATE_DATA_INIT;
 	struct list_objects_filter_options filter_options;
 	int ret;
-	enum submodule_update_type update_type = SM_UPDATE_UNSPECIFIED;
 
 	struct option module_update_options[] = {
 		OPT__FORCE(&opt.force, N_("force checkout updates"), 0),
@@ -2618,16 +2619,13 @@ 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", &update_type,
+		OPT_SET_INT(0, "checkout", &opt.update_default,
 			N_("use the 'checkout' update strategy (default)"),
 			SM_UPDATE_CHECKOUT),
-		OPT_SET_INT('m', "merge", &update_type,
+		OPT_SET_INT('m', "merge", &opt.update_default,
 			N_("use the 'merge' update strategy"),
 			SM_UPDATE_MERGE),
-		OPT_SET_INT('r', "rebase", &update_type,
+		OPT_SET_INT('r', "rebase", &opt.update_default,
 			N_("use the 'rebase' update strategy"),
 			SM_UPDATE_REBASE),
 		OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
@@ -2679,13 +2677,8 @@ static int module_update(int argc, const char **argv, const char *prefix)
 
 	opt.filter_options = &filter_options;
 
-	if (update_type != SM_UPDATE_UNSPECIFIED)
-		opt.update_default = submodule_update_type_to_label(update_type);
-
 	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);
-- 
gitgitgadget


  parent reply	other threads:[~2022-06-30 21:20 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-27 23:20 [PATCH 0/5] submodule: remove "--recursive-prefix" Glen Choo via GitGitGadget
2022-06-27 23:20 ` [PATCH 1/5] submodule--helper update: use display path helper Glen Choo via GitGitGadget
2022-06-28  8:23   ` Ævar Arnfjörð Bjarmason
2022-06-28 17:34     ` Glen Choo
2022-06-27 23:20 ` [PATCH 2/5] submodule--helper: don't recreate recursive prefix Glen Choo via GitGitGadget
2022-06-27 23:20 ` [PATCH 3/5] submodule--helper: use correct display path helper Glen Choo via GitGitGadget
2022-06-27 23:20 ` [PATCH 4/5] submodule--helper update: use --super-prefix Glen Choo via GitGitGadget
2022-06-28  8:47   ` Ævar Arnfjörð Bjarmason
2022-06-28 18:15     ` Glen Choo
2022-06-27 23:20 ` [PATCH 5/5] submodule--helper: remove display path helper Glen Choo via GitGitGadget
2022-06-28 16:34 ` [PATCH 0/5] submodule: remove "--recursive-prefix" Glen Choo
2022-06-30 21:19 ` [PATCH v2 00/18] " Glen Choo via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 01/18] git-submodule.sh: remove unused sanitize_submodule_env() Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 02/18] git-submodule.sh: remove unused $prefix variable Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 03/18] git-submodule.sh: make the "$cached" variable a boolean Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 04/18] git-submodule.sh: remove unused top-level "--branch" argument Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 05/18] submodule--helper: have --require-init imply --init Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 06/18] submodule update: remove "-v" option Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 07/18] submodule--helper: rename "absorb-git-dirs" to "absorbgitdirs" Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 08/18] submodule--helper: report "submodule" as our name in some "-h" output Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 09/18] submodule--helper: understand --checkout, --merge and --rebase synonyms Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` Glen Choo via GitGitGadget [this message]
2022-06-30 21:19   ` [PATCH v2 11/18] git-submodule.sh: use "$quiet", not "$GIT_QUIET" Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 12/18] git-sh-setup.sh: remove "say" function, change last users Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 13/18] submodule--helper update: use display path helper Glen Choo via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 14/18] submodule--helper: don't recreate recursive prefix Glen Choo via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 15/18] submodule--helper: use correct display path helper Glen Choo via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 16/18] submodule--helper: remove unused SUPPORT_SUPER_PREFIX flags Ævar Arnfjörð Bjarmason via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 17/18] submodule--helper update: use --super-prefix Glen Choo via GitGitGadget
2022-06-30 21:19   ` [PATCH v2 18/18] submodule--helper: remove display path helper Glen Choo via GitGitGadget
2022-06-30 21:57   ` [PATCH v2 00/18] submodule: remove "--recursive-prefix" Glen Choo
2022-06-30 22:11   ` [PATCH v3 0/6] " Glen Choo
2022-06-30 22:11     ` [PATCH v3 1/6] submodule--helper update: use display path helper Glen Choo
2022-06-30 22:11     ` [PATCH v3 2/6] submodule--helper: don't recreate recursive prefix Glen Choo
2022-06-30 22:11     ` [PATCH v3 3/6] submodule--helper: use correct display path helper Glen Choo
2022-06-30 22:11     ` [PATCH v3 4/6] submodule--helper: remove unused SUPPORT_SUPER_PREFIX flags Glen Choo
2022-06-30 22:11     ` [PATCH v3 5/6] submodule--helper update: use --super-prefix Glen Choo
2022-06-30 22:11     ` [PATCH v3 6/6] submodule--helper: remove display path helper Glen Choo
2022-07-01  2:11     ` [PATCH v4 0/7] submodule: remove "--recursive-prefix" Glen Choo
2022-07-01  2:11       ` [PATCH v4 1/7] submodule--helper tests: add missing "display path" coverage Glen Choo
2022-07-01  2:11       ` [PATCH v4 2/7] submodule--helper update: use display path helper Glen Choo
2022-07-01  2:11       ` [PATCH v4 3/7] submodule--helper: don't recreate recursive prefix Glen Choo
2022-07-01  2:11       ` [PATCH v4 4/7] submodule--helper: use correct display path helper Glen Choo
2022-07-01  2:11       ` [PATCH v4 5/7] submodule--helper: remove unused SUPPORT_SUPER_PREFIX flags Glen Choo
2022-07-01  2:11       ` [PATCH v4 6/7] submodule--helper update: use --super-prefix Glen Choo
2022-07-01  2:11       ` [PATCH v4 7/7] submodule--helper: remove display path helper Glen Choo
2022-06-30 22:16   ` [PATCH v2 00/18] submodule: remove "--recursive-prefix" Ævar Arnfjörð Bjarmason
2022-06-30 23:45     ` 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

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

  git send-email \
    --in-reply-to=b788fc671bf1862a72f9fe7256affd7d152b8a6f.1656623978.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=avarab@gmail.com \
    --cc=chooglen@google.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    --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.
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 NNTP newsgroup(s).