From: Eric Sunshine <sunshine@sunshineco.com>
To: Stefan Beller <sbeller@google.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Git List <git@vger.kernel.org>,
Jens Lehmann <jens.lehmann@web.de>,
Heiko Voigt <hvoigt@hvoigt.net>
Subject: Re: [PATCH 2/4] submodule: implement `module_name` as a builtin helper
Date: Tue, 4 Aug 2015 20:58:41 -0400 [thread overview]
Message-ID: <CAPig+cQtoWF_9Km4H7MXDf7ySQNUP9gncxkrV3NFTrULA8fbbA@mail.gmail.com> (raw)
In-Reply-To: <1438733070-15805-2-git-send-email-sbeller@google.com>
On Tue, Aug 4, 2015 at 8:04 PM, Stefan Beller <sbeller@google.com> wrote:
> The goal of this series being rewriting `git submodule update`,
> we don't want to call out to the shell script for config lookups.
>
> So reimplement the lookup of the submodule name in C.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index cb18ddf..dd5635f 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -98,6 +100,48 @@ static int module_list(int argc, const char **argv, const char *prefix)
> +static int collect_module_names(const char *key, const char *value, void *cb)
> +{
> + size_t len;
> + struct string_list *sl = cb;
> +
> + if (starts_with(key, "submodule.")
> + && strip_suffix(key, ".path", &len)) {
> + struct strbuf sb = STRBUF_INIT;
> + strbuf_add(&sb, key + strlen("submodule."),
> + len - strlen("submodule."));
> + string_list_insert(sl, value)->util = strbuf_detach(&sb, NULL);
> + strbuf_release(&sb);
Why the complexity and overhead of a strbuf when the same could be
accomplished more easily and straightforwardly with xstrndup()?
> + }
> +
> + return 0;
> +}
> +
> +static int module_name(int argc, const char **argv, const char *prefix)
> +{
> + struct string_list_item *item;
> + struct git_config_source config_source;
> + struct string_list values = STRING_LIST_INIT_DUP;
> +
> + if (!argc)
Do you mean?
if (argc != 1)
> + usage("git submodule--helper module_name <path>\n");
> +
> + memset(&config_source, 0, sizeof(config_source));
> + config_source.file = ".gitmodules";
> +
> + if (git_config_with_options(collect_module_names, &values,
> + &config_source, 1) < 0)
> + die(_("unknown error occured while reading the git modules file"));
> +
> + item = string_list_lookup(&values, argv[0]);
> + if (item)
> + printf("%s\n", (char*)item->util);
> + else
> + die("No submodule mapping found in .gitmodules for path '%s'", argv[0]);
> + return 0;
> +}
> +
> int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
> {
> if (argc < 2)
> @@ -106,6 +150,9 @@ int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
> if (!strcmp(argv[1], "module_list"))
> return module_list(argc - 1, argv + 1, prefix);
>
> + if (!strcmp(argv[1], "module_name"))
> + return module_name(argc - 2, argv + 2, prefix);
> +
> usage:
> usage("git submodule--helper module_list\n");
> }
next prev parent reply other threads:[~2015-08-05 0:58 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-05 0:04 [PATCH 1/4] submodule: implement `module_list` as a builtin helper Stefan Beller
2015-08-05 0:04 ` [PATCH 2/4] submodule: implement `module_name` " Stefan Beller
2015-08-05 0:05 ` Stefan Beller
2015-08-05 0:58 ` Eric Sunshine [this message]
2015-08-05 16:29 ` Stefan Beller
2015-08-05 19:06 ` Jens Lehmann
2015-08-05 19:55 ` Stefan Beller
2015-08-05 21:08 ` [PATCH] " Stefan Beller
2015-08-06 19:49 ` Jens Lehmann
2015-08-06 21:38 ` Stefan Beller
2015-08-07 20:03 ` Junio C Hamano
2015-08-07 20:54 ` Stefan Beller
2015-08-07 20:17 ` Junio C Hamano
2015-08-07 20:49 ` Stefan Beller
2015-08-07 21:14 ` Junio C Hamano
2015-08-07 21:21 ` Stefan Beller
2015-08-07 21:32 ` Junio C Hamano
2015-08-07 22:04 ` Stefan Beller
2015-08-07 22:18 ` Junio C Hamano
2015-08-07 23:12 ` Stefan Beller
2015-08-07 22:42 ` Junio C Hamano
2015-08-07 23:19 ` Stefan Beller
2015-08-08 0:21 ` Junio C Hamano
2015-08-08 6:20 ` Junio C Hamano
2015-08-10 17:03 ` Stefan Beller
2015-08-05 18:31 ` [PATCH 1/4] submodule: implement `module_list` " Jens Lehmann
2015-08-07 19:53 ` 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
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=CAPig+cQtoWF_9Km4H7MXDf7ySQNUP9gncxkrV3NFTrULA8fbbA@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hvoigt@hvoigt.net \
--cc=jens.lehmann@web.de \
--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).