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

Re: [PATCH 5/7] submodule: implement `module_list` as a builtin helper

From
Stefan Beller <sbeller@google.com>
Date
Aug 19, 2015, 18:23 UTC
Message-ID
<CAGZ79kbHVAqOFT5s-4RRtHjfBO=KgvMOmup0Q1OyNZ3kSFfvxw@mail.gmail.com>
In-Reply-To
<xmqqpp2j9m7g.fsf@gitster.dls.corp.google.com>
On Wed, Aug 19, 2015 at 11:17 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 25 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> +static int module_list_compute(int argc, const char **argv,
>> +                             const char *prefix,
>> +                             struct pathspec *pathspec)
>> +{
>> +     int i;
>> +     char *max_prefix, *ps_matched = NULL;
>> +     int max_prefix_len;
>> +     parse_pathspec(pathspec, 0,
>> +                    PATHSPEC_PREFER_FULL |
>> +                    PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
>> +                    prefix, argv);
>> +
>> +     /* Find common prefix for all pathspec's */
>> +     max_prefix = common_prefix(pathspec);
>> +     max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
>> +
>> +     if (pathspec->nr)
>> +             ps_matched = xcalloc(1, pathspec->nr);
>
> Micronit.  Even though multiplication is commutative, the order of
> arguments to xcalloc() looks odd.  It lets you say "I want an array
> with nmemb elements, and each of its is size-bytes long" by giving
> it nmemb and then size.

Thanks for pointing that out! I think this would be an alignment issue in theory, if the items were larger and the number of items not dividable by the size of items.

So because 1 char has no alignment problems, we can happily allocate just one block of the member size here.

>
> No need to resend; will fix it up while queuing.
>
> Thanks.
Previous: Stefan BellerNext: Stefan Beller
Message 11 of 19 in “Submodule improvements”
  1. 0/7 Submodule improvementsStefan Beller, Aug 18, 2015
  2. 1/7 submodule: implement a config API for lookup of .gitmodules valuesStefan Beller, Aug 18, 2015
  3. 2/7 submodule: extract functions for config set and lookupStefan Beller, Aug 18, 2015
  4. 3/7 submodule: use new config API for worktree configurationsStefan Beller, Aug 18, 2015
  5. 4/7 submodule: Allow errornous values for the fetchrecursesubmodules optionStefan Beller, Aug 18, 2015
  6. Junio C HamanoAug 19, 2015
  7. 5/7 submodule: implement `module_list` as a builtin helperStefan Beller, Aug 18, 2015
  8. Junio C HamanoAug 19, 2015
  9. Junio C HamanoAug 19, 2015
  10. Stefan BellerAug 19, 2015
  11. Stefan BellerAug 19, 2015
  12. 6/7 submodule: implement `module_name` as a builtin helperStefan Beller, Aug 18, 2015
  13. 7/7 submodule: implement `module_clone` as a builtin helperStefan Beller, Aug 18, 2015
  14. Stefan BellerAug 18, 2015
  15. 7/7 submodule: implement `module_clone` as a builtin helperStefan Beller, Aug 18, 2015
  16. Junio C HamanoAug 19, 2015
  17. Stefan BellerAug 19, 2015
  18. Jeff KingAug 21, 2015
  19. Stefan BellerAug 18, 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.