git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason 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>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 09/18] submodule--helper: understand --checkout, --merge and --rebase synonyms
Date: Thu, 30 Jun 2022 21:19:29 +0000	[thread overview]
Message-ID: <8f12108c2951cdfa181d6be66b6def28cd007bdd.1656623978.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1282.v2.git.git.1656623978.gitgitgadget@gmail.com>

From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?=
 <avarab@gmail.com>

Understand --checkout, --merge and --rebase synonyms for
--update={checkout,merge,rebase}, as well as the short options that
'git submodule' itself understands.

This removes a difference between the CLI API of "git submodule" and
"git submodule--helper", making it easier to make the latter an alias
for the former. See 48308681b07 (git submodule update: have a
dedicated helper for cloning, 2016-02-29) for the initial addition of
--update.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/submodule--helper.c | 30 ++++++++++++++++++++++++++++++
 git-submodule.sh            | 14 +++++++++-----
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 04d2620fce8..53179472d85 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2404,6 +2404,23 @@ static void ensure_core_worktree(const char *path)
 	}
 }
 
+static const char *submodule_update_type_to_label(enum submodule_update_type type)
+{
+	switch (type) {
+	case SM_UPDATE_CHECKOUT:
+		return "checkout";
+	case SM_UPDATE_MERGE:
+		return "merge";
+	case SM_UPDATE_REBASE:
+		return "rebase";
+	case SM_UPDATE_UNSPECIFIED:
+	case SM_UPDATE_NONE:
+	case SM_UPDATE_COMMAND:
+		break;
+	}
+	BUG("unreachable with type %d", type);
+}
+
 static void update_data_to_args(struct update_data *update_data, struct strvec *args)
 {
 	strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
@@ -2582,6 +2599,7 @@ 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),
@@ -2603,6 +2621,15 @@ static int module_update(int argc, const char **argv, const char *prefix)
 		OPT_STRING(0, "update", &opt.update_default,
 			   N_("string"),
 			   N_("rebase, merge, checkout or none")),
+		OPT_SET_INT(0, "checkout", &update_type,
+			N_("use the 'checkout' update strategy (default)"),
+			SM_UPDATE_CHECKOUT),
+		OPT_SET_INT('m', "merge", &update_type,
+			N_("use the 'merge' update strategy"),
+			SM_UPDATE_MERGE),
+		OPT_SET_INT('r', "rebase", &update_type,
+			N_("use the 'rebase' update strategy"),
+			SM_UPDATE_REBASE),
 		OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
 			   N_("reference repository")),
 		OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2652,6 +2679,9 @@ 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)
diff --git a/git-submodule.sh b/git-submodule.sh
index 1c1dc320922..7fc7119fb21 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -40,7 +40,9 @@ require_init=
 files=
 remote=
 nofetch=
-update=
+rebase=
+merge=
+checkout=
 custom_name=
 depth=
 progress=
@@ -260,7 +262,7 @@ cmd_update()
 			force=$1
 			;;
 		-r|--rebase)
-			update="rebase"
+			rebase=1
 			;;
 		--reference)
 			case "$2" in '') usage ;; esac
@@ -274,13 +276,13 @@ cmd_update()
 			dissociate=1
 			;;
 		-m|--merge)
-			update="merge"
+			merge=1
 			;;
 		--recursive)
 			recursive=1
 			;;
 		--checkout)
-			update="checkout"
+			checkout=1
 			;;
 		--recommend-shallow)
 			recommend_shallow="--recommend-shallow"
@@ -341,7 +343,9 @@ cmd_update()
 		${init:+--init} \
 		${nofetch:+--no-fetch} \
 		${wt_prefix:+--prefix "$wt_prefix"} \
-		${update:+--update "$update"} \
+		${rebase:+--rebase} \
+		${merge:+--merge} \
+		${checkout:+--checkout} \
 		${reference:+"$reference"} \
 		${dissociate:+"--dissociate"} \
 		${depth:+"$depth"} \
-- 
gitgitgadget


  parent reply	other threads:[~2022-06-30 21:23 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   ` Ævar Arnfjörð Bjarmason via GitGitGadget [this message]
2022-06-30 21:19   ` [PATCH v2 10/18] submodule--helper: eliminate internal "--update" option Glen Choo via GitGitGadget
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

  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=8f12108c2951cdfa181d6be66b6def28cd007bdd.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.
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).