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

Re: [PATCH 3/3] submodule: implement `module_clone` as a builtin helper

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Sep 1, 2015, 18:35 UTC
Message-ID
<CAPig+cSZ9et=7DNF15MJo-Ef5o1bjbLxAoTgxJV6q1BEUiBGcA@mail.gmail.com>
In-Reply-To
<CAGZ79kYDYO-q6QEmRQ4YW4ED2HAmMjZNyRaY52ix6YU1=WVNHw@mail.gmail.com>
On Tue, Sep 1, 2015 at 1:49 PM, Stefan Beller <sbeller@google.com> wrote:
Show 24 quoted lines
> took all suggestions except the one below.
>
>>
>>     if (strbuf_getcwd(&sb))
>>         die_errno(...);
>>     strbuf_addf(&sb, "/%s, sm_gitdir);
>>     free(sm_gitdir);
>>     sm_gitdir = strbuf_detach(&sb, NULL);
>>
>>> +       }
>>> +
>>> +       if (strbuf_getcwd(&sb))
>>> +               die_errno("unable to get current working directory");
>>
>> The conditional block just above here also gets 'cwd'. If you move
>> this code above the !is_absolute_path(sm_gitdir) conditional block,
>> then you can avoid the duplication.
>
> I don't get it. We need to have strbuf_getcwd twice no matter how we
> arrange the code
> as we strbuf_detach will empty the strbuf.
>
> Do you mean to call strbuf_getcwd just once and then xstrdup the value,
> then reset the strbuf to just contain the cwd and append the other string ?
Sorry, I have no idea what you are asking.

All I am saying is that you're unnecessarily invoking getcwd() twice. It's value doesn't change between invocations, so the second call is entirely redundant and wasteful. You can instead call it just once and use the result in both places.

Previous: Stefan BellerNext: Junio C Hamano
Message 11 of 21 in “[PATCHv2 0/3] submodule--helper: Have some refactoring only patches first”
  1. Stefan BellerAug 31, 2015
  2. 1/3 submodule: implement `module_list` as a builtin helperStefan Beller, Aug 31, 2015
  3. Eric SunshineAug 31, 2015
  4. 2/3 submodule: implement `module_name` as a builtin helperStefan Beller, Aug 31, 2015
  5. Junio C HamanoAug 31, 2015
  6. Stefan BellerAug 31, 2015
  7. Eric SunshineAug 31, 2015
  8. 3/3 submodule: implement `module_clone` as a builtin helperStefan Beller, Aug 31, 2015
  9. Eric SunshineAug 31, 2015
  10. Stefan BellerSep 1, 2015
  11. Eric SunshineSep 1, 2015
  12. Junio C HamanoAug 31, 2015
  13. 0/3 submodule--helper: Have some refactoring only patches firstStefan Beller, Sep 1, 2015
  14. 1/3 submodule: implement `module-list` as a builtin helperStefan Beller, Sep 1, 2015
  15. Eric SunshineSep 1, 2015
  16. 2/3 submodule: implement `module-name` as a builtin helperStefan Beller, Sep 1, 2015
  17. Eric SunshineSep 1, 2015
  18. Stefan BellerSep 1, 2015
  19. 3/3 submodule: implement `module-clone` as a builtin helperStefan Beller, Sep 1, 2015
  20. Eric SunshineSep 1, 2015
  21. Eric SunshineSep 1, 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.