From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: git@vger.kernel.org, jrnieder@gmail.com, Jens.Lehmann@web.de
Subject: Re: [PATCH 2/2] submodule: port init from shell to C
Date: Thu, 18 Feb 2016 12:46:37 -0800 [thread overview]
Message-ID: <xmqqmvqxg30y.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1455320356-15778-3-git-send-email-sbeller@google.com> (Stefan Beller's message of "Fri, 12 Feb 2016 15:39:16 -0800")
Stefan Beller <sbeller@google.com> writes:
> By having the `init` functionality in C, we can reference it easier
> from other parts in the code.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> builtin/submodule--helper.c | 107 ++++++++++++++++++++++++++++++++++++++++++++
> git-submodule.sh | 39 +---------------
> submodule.c | 21 +++++++++
> submodule.h | 1 +
> 4 files changed, 130 insertions(+), 38 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index d1e9118..30e623a 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -214,6 +214,112 @@ static int resolve_relative_url_test(int argc, const char **argv, const char *pr
> return 0;
> }
>
> +static void init_submodule(const char *path, const char *prefix, int quiet)
> +{
> + const struct submodule *sub;
> + struct strbuf sb = STRBUF_INIT;
> + char *url = NULL;
> + const char *upd = NULL;
> + char *cwd = xgetcwd();
> + const char *displaypath = relative_path(cwd, prefix, &sb);
> +
> + /* Only loads from .gitmodules, no overlay with .git/config */
> + gitmodules_config();
This feeds submodule_config() function with the contents of
".gitmodules".
> + sub = submodule_from_path(null_sha1, path);
> +
> + /*
> + * Copy url setting when it is not set yet.
> + * To look up the url in .git/config, we must not fall back to
> + * .gitmodules, so look it up directly.
> + */
> + strbuf_reset(&sb);
> + strbuf_addf(&sb, "submodule.%s.url", sub->name);
> + if (git_config_get_string(sb.buf, &url)) {
> + url = xstrdup(sub->url);
> + if (!url)
> + die(_("No url found for submodule path '%s' in .gitmodules"),
> + displaypath);
I am assuming that this corresponds to these lines in the original
scripted version:
url=$(git config -f .gitmodules submodule."$name".url)
test -z "$url" &&
die "$(eval_gettext "No url found for submodule path...
but what makes git_config_get_string() to read from ".gitmodules"
file? Doesn't it read from $GIT_DIR/config & ~/.gitconfig instead?
> + /* Possibly a url relative to parent */
> + if (starts_with_dot_dot_slash(url) ||
> + starts_with_dot_slash(url)) {
> + char *remoteurl;
> + char *remote = get_default_remote();
> + struct strbuf remotesb = STRBUF_INIT;
> + strbuf_addf(&remotesb, "remote.%s.url", remote);
> + free(remote);
> +
> + if (git_config_get_string(remotesb.buf, &remoteurl))
> + /*
> + * The repository is its own
> + * authoritative upstream
> + */
> + remoteurl = xgetcwd();
> + url = relative_url(remoteurl, url, NULL);
> + strbuf_release(&remotesb);
> + free(remoteurl);
Does the code inside this block correspond to this single line in
the original?
url=$(git submodule--helper resolve-relative-url "$url") || exit
It seems to be doing quite a different thing, though.
> + }
> +
> + if (git_config_set(sb.buf, url))
> + die(_("Failed to register url for submodule path '%s'"),
> + displaypath);
> + if (!quiet)
> + printf(_("Submodule '%s' (%s) registered for path '%s'\n"),
> + sub->name, url, displaypath);
> + }
> +
> + /* Copy "update" setting when it is not set yet */
> + strbuf_reset(&sb);
> + strbuf_addf(&sb, "submodule.%s.update", sub->name);
> + if (git_config_get_string_const(sb.buf, &upd) &&
This part of the code is supposed to read from in-tree ".gitmodules"
and copy to $GIT_DIR/config (i.e. git_config_set() below), but
again, I am not sure what makes this read from ".gitmodules".
Puzzled.
> + sub->update_strategy.type != SM_UPDATE_UNSPECIFIED) {
> + if (sub->update_strategy.type == SM_UPDATE_COMMAND) {
> + fprintf(stderr, _("warning: command update mode suggested for submodule '%s'\n"),
> + sub->name);
> + upd = "none";
> + } else
> + upd = submodule_strategy_to_string(&sub->update_strategy);
> +
> + if (git_config_set(sb.buf, upd))
> + die(_("Failed to register update mode for submodule path '%s'"), displaypath);
> + }
> + strbuf_release(&sb);
> + free(cwd);
> + free(url);
> +}
next prev parent reply other threads:[~2016-02-18 20:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-12 23:39 [PATCH 0/2] Port `git submodule init` from shell to C Stefan Beller
2016-02-12 23:39 ` [PATCH 1/2] submodule: port resolve_relative_url " Stefan Beller
2016-02-18 20:23 ` Junio C Hamano
2016-02-27 8:28 ` Duy Nguyen
2016-03-02 17:21 ` Johannes Sixt
2016-03-02 17:34 ` Stefan Beller
2016-02-12 23:39 ` [PATCH 2/2] submodule: port init " Stefan Beller
2016-02-18 20:46 ` Junio C Hamano [this message]
2016-02-18 23:15 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2016-04-16 0:50 [PATCH 0/2] Another reroll of sb/submodule-init Stefan Beller
2016-04-16 0:50 ` [PATCH 2/2] submodule: port init from shell to C Stefan Beller
2016-04-14 18:18 [PATCH 0/2] Port `submodule init` " Stefan Beller
2016-04-14 18:18 ` [PATCH 2/2] submodule: port init from shell " Stefan Beller
2016-04-13 0:18 [PATCH 0/2] Port `git submodule init` " Stefan Beller
2016-04-13 0:18 ` [PATCH 2/2] submodule: port init " Stefan Beller
2016-03-15 0:15 [PATCH 0/2] Port `git submodule init` " Stefan Beller
2016-03-15 0:15 ` [PATCH 2/2] submodule: port init " Stefan Beller
2016-01-15 23:37 [PATCH 0/2] Port `git submodule init` " Stefan Beller
2016-01-15 23:37 ` [PATCH 2/2] submodule: Port init " Stefan Beller
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=xmqqmvqxg30y.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=sbeller@google.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).