git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/4] submodule: implement `module_name` as a builtin helper

From
Stefan Beller <sbeller@google.com>
Date
Aug 5, 2015, 16:29 UTC
Message-ID
<CAGZ79kb8q_OzdMTxeNQo6t0T9Ay8TJkMPPqZU-G0CkOZ9rA_hA@mail.gmail.com>
In-Reply-To
<CAPig+cQtoWF_9Km4H7MXDf7ySQNUP9gncxkrV3NFTrULA8fbbA@mail.gmail.com>
On Tue, Aug 4, 2015 at 5:58 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 28 quoted lines
> 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()?
fixed.
Show 17 quoted lines
>
>> +       }
>> +
>> +       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)
doh! Yes I meant that.
Show 31 quoted lines
>
>> +               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");
>>  }
Previous: Eric SunshineNext: Jens Lehmann
Message 5 of 27 in “submodule: implement `module_list` as a builtin helper”
  1. 1/4 submodule: implement `module_list` as a builtin helperStefan Beller, Aug 5, 2015
  2. 2/4 submodule: implement `module_name` as a builtin helperStefan Beller, Aug 5, 2015
  3. Stefan BellerAug 5, 2015
  4. Eric SunshineAug 5, 2015
  5. Stefan BellerAug 5, 2015
  6. Jens LehmannAug 5, 2015
  7. Stefan BellerAug 5, 2015
  8. submodule: implement `module_name` as a builtin helperStefan Beller, Aug 5, 2015
  9. Jens LehmannAug 6, 2015
  10. submodule: implement `module_name` as a builtin helperStefan Beller, Aug 6, 2015
  11. Junio C HamanoAug 7, 2015
  12. Stefan BellerAug 7, 2015
  13. Junio C HamanoAug 7, 2015
  14. Stefan BellerAug 7, 2015
  15. Junio C HamanoAug 7, 2015
  16. Stefan BellerAug 7, 2015
  17. Junio C HamanoAug 7, 2015
  18. Stefan BellerAug 7, 2015
  19. Junio C HamanoAug 7, 2015
  20. Stefan BellerAug 7, 2015
  21. Junio C HamanoAug 7, 2015
  22. Stefan BellerAug 7, 2015
  23. Junio C HamanoAug 8, 2015
  24. Junio C HamanoAug 8, 2015
  25. Stefan BellerAug 10, 2015
  26. Jens LehmannAug 5, 2015
  27. Junio C HamanoAug 7, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.