git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH v4] submodule: port subcommand 'set-url' from shell to C
@ 2020-05-06  7:37 Shourya Shukla
  2020-05-06  8:09 ` Christian Couder
                   ` (2 more replies)
  0 siblings, 3 replies; 22+ messages in thread
From: Shourya Shukla @ 2020-05-06  7:37 UTC (permalink / raw)
  To: git; +Cc: gitster, christian.couder, kaartic.sivaraam, liu.denton,
	Shourya Shukla

Convert submodule subcommand 'set-url' to a builtin. Port 'set-url'to
'submodule--helper.c' and call the latter via 'git-submodule.sh'.

Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
---
Thank you Junio for the review! :)
BTW, how detailed should the commit message be about the
patch?

 builtin/submodule--helper.c | 39 +++++++++++++++++++++++++++++++++++++
 git-submodule.sh            | 22 +--------------------
 2 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 1a4b391c88..f50745a03f 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2246,6 +2246,44 @@ static int module_config(int argc, const char **argv, const char *prefix)
 	usage_with_options(git_submodule_helper_usage, module_config_options);
 }
 
+static int module_set_url(int argc, const char **argv, const char *prefix)
+{
+	int quiet = 0;
+	const char *newurl;
+	const char *path;
+	struct strbuf config_name = STRBUF_INIT;
+
+	struct option set_url_options[] = {
+		OPT__QUIET(&quiet, N_("Suppress output for setting url of a submodule")),
+		OPT_END()
+	};
+
+	const char *const usage[] = {
+		N_("git submodule--helper set-url [--quiet] <path> <newurl>"),
+		NULL
+	};
+
+	argc = parse_options(argc, argv, prefix, set_url_options,
+			     usage, 0);
+
+	if (argc!=2) {
+		usage_with_options(usage, set_url_options);
+		return 1;
+	}
+
+	path = argv[0];
+	newurl = argv[1];
+
+	strbuf_addf(&config_name, "submodule.%s.url", path);
+
+	config_set_in_gitmodules_file_gently(config_name.buf, newurl);
+	sync_submodule(path, prefix, quiet ? OPT_QUIET : 0);
+
+	strbuf_release(&config_name);
+
+	return 0;
+}
+
 #define SUPPORT_SUPER_PREFIX (1<<0)
 
 struct cmd_struct {
@@ -2276,6 +2314,7 @@ static struct cmd_struct commands[] = {
 	{"is-active", is_active, 0},
 	{"check-name", check_name, 0},
 	{"config", module_config, 0},
+	{"set-url", module_set_url, 0},
 };
 
 int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
diff --git a/git-submodule.sh b/git-submodule.sh
index 08e0439df0..39ebdf25b5 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -805,27 +805,7 @@ cmd_set_url() {
 		shift
 	done
 
-	if test $# -ne 2
-	then
-		usage
-	fi
-
-	# we can't use `git submodule--helper name` here because internally, it
-	# hashes the path so a trailing slash could lead to an unintentional no match
-	name="$(git submodule--helper list "$1" | cut -f2)"
-	if test -z "$name"
-	then
-		exit 1
-	fi
-
-	url="$2"
-	if test -z "$url"
-	then
-		exit 1
-	fi
-
-	git submodule--helper config submodule."$name".url "$url"
-	git submodule--helper sync ${GIT_QUIET:+--quiet} "$name"
+	git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper set-url ${GIT_QUIET:+--quiet} -- "$@"
 }
 
 #
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2020-05-08 17:51 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-06  7:37 [PATCH v4] submodule: port subcommand 'set-url' from shell to C Shourya Shukla
2020-05-06  8:09 ` Christian Couder
2020-05-06 16:31   ` Shourya Shukla
2020-05-06 17:16     ` Junio C Hamano
2020-05-06 17:12 ` Junio C Hamano
2020-05-06 18:12   ` Shourya Shukla
2020-05-06 18:22     ` Junio C Hamano
2020-05-07  4:40       ` Shourya Shukla
2020-05-07  5:08         ` Junio C Hamano
2020-05-08  5:47           ` Shourya Shukla
2020-05-08  6:18             ` Christian Couder
2020-05-08 15:18               ` Re* " Junio C Hamano
2020-05-08 15:38                 ` Eric Sunshine
2020-05-08 15:57                   ` Junio C Hamano
2020-05-08 16:13                     ` Eric Sunshine
2020-05-08 16:38                       ` Junio C Hamano
2020-05-08 17:51                         ` Eric Sunshine
2020-05-08  6:21 ` [PATCH v5] " Shourya Shukla
2020-05-08  6:30   ` Denton Liu
2020-05-08 16:13     ` Junio C Hamano
2020-05-08 16:17     ` Junio C Hamano
2020-05-08 16:18   ` [PATCH v6] " Junio C Hamano

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).