From: Shourya Shukla <shouryashukla.oo@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, christian.couder@gmail.com,
liu.denton@gmail.com, peff@peff.net, heba.waly@gmail.com,
Shourya Shukla <shouryashukla.oo@gmail.com>
Subject: [PATCH v3] submodule: port subcommand 'set-url' from shell to C
Date: Mon, 4 May 2020 12:57:05 +0530 [thread overview]
Message-ID: <20200504072705.15261-1-shouryashukla.oo@gmail.com> (raw)
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 and Denton for the review :)
Eliminated the whitespace errors and removed the callback structures
as well. I have made the commit message more abstract for now as pointed
out by Denton that the message seems to go into too much detail.
Also, the variable name for `&entry` has been changed to `config_entry` so
as to avoid confusion with `cache_entry`. The shell file has also been
amended.
builtin/submodule--helper.c | 46 +++++++++++++++++++++++++++++++++++++
git-submodule.sh | 22 +-----------------
2 files changed, 47 insertions(+), 21 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 1a4b391c88..6fd459988e 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2246,6 +2246,51 @@ 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 = NULL;
+ const char *path = NULL;
+
+ struct strbuf config_entry = 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 (quiet)
+ quiet |= OPT_QUIET;
+
+ if (argc!=2){
+ usage_with_options(usage, set_url_options);
+ return 1;
+ }
+
+ path = argv[0];
+ newurl = argv[1];
+
+ strbuf_addstr(&config_entry, "submodule.");
+ strbuf_addstr(&config_entry, path);
+ strbuf_addstr(&config_entry, ".url");
+
+ config_set_in_gitmodules_file_gently(config_entry.buf, newurl);
+ sync_submodule(path, prefix, quiet);
+
+ strbuf_release(&config_entry);
+
+ return 0;
+}
+
#define SUPPORT_SUPER_PREFIX (1<<0)
struct cmd_struct {
@@ -2276,6 +2321,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
next reply other threads:[~2020-05-04 7:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-04 7:27 Shourya Shukla [this message]
2020-05-04 15:55 ` [PATCH v3] submodule: port subcommand 'set-url' from shell to C Junio C Hamano
2020-05-04 17:39 ` Shourya Shukla
2020-05-04 19:14 ` Junio C Hamano
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=20200504072705.15261-1-shouryashukla.oo@gmail.com \
--to=shouryashukla.oo@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=heba.waly@gmail.com \
--cc=liu.denton@gmail.com \
--cc=peff@peff.net \
/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).