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

Re: [PATCHv5 3/4] submodule: rename and add flags to ok_to_remove_submodule

From
Stefan Beller <sbeller@google.com>
Date
Dec 27, 2016, 17:55 UTC
Message-ID
<CAGZ79kbpq3WPk-sSoVh8s0FUanctEjHH92LfpoBGYV2WhfEV-w@mail.gmail.com>
In-Reply-To
<xmqqr34uchuq.fsf@gitster.mtv.corp.google.com>
On Mon, Dec 26, 2016 at 4:53 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> As only 0 is understood as false, rename the function to invert the
>> meaning, i.e. the return code of 0 signals the removal of the submodule
>> is fine, and other values can be used to return a more precise answer
>> what went wrong.
>
> Makes sense to rename it as that will catch all the callers that
> depend on the old semantics and name.
>
>> -     if (start_command(&cp))
>> -             die(_("could not run 'git status --porcelain -u --ignore-submodules=none' in submodule %s"), path);
>> +     if (start_command(&cp)) {
>> +             if (flags & SUBMODULE_REMOVAL_DIE_ON_ERROR)
>> +                     die(_("could not start 'git status in submodule '%s'"),
>> +                             path);
>> +             ret = -1;
>> +             goto out;
>> +     }
>
> This new codepath that does not die will not leak anything, as
> a failed start_command() should release its argv[] and env[].
>
>>       len = strbuf_read(&buf, cp.out, 1024);
>>       if (len > 2)
>> -             ok_to_remove = 0;
>> +             ret = 1;
>
> Not a new problem but is it obvious why the comparison of "len" is
> against "2"?  This may deserve a one-liner comment.
>
> Otherwise looks good to me.

I took the check "len > 2" from the other occurrence in submodule.c. When thinking about it (and inspecting the man page for porcelain status), I think just checking != 0 is sufficient.

So in a reroll I'll change that to just
    if (len)
        ...

I'll look at the other occurrences and see if we can reuse code as well.

Thanks, Stefan

Previous: Junio C HamanoNext: Stefan Beller
Message 8 of 13 in “[PATCHv5 0/4] git-rm absorbs submodule git directory before deletion”
  1. Stefan BellerDec 20, 2016
  2. 1/4 submodule.h: add extern keyword to functionsStefan Beller, Dec 20, 2016
  3. Junio C HamanoDec 27, 2016
  4. Stefan BellerDec 27, 2016
  5. 2/4 submodule: modernize ok_to_remove_submodule to use argv_arrayStefan Beller, Dec 20, 2016
  6. 3/4 submodule: rename and add flags to ok_to_remove_submoduleStefan Beller, Dec 20, 2016
  7. Junio C HamanoDec 27, 2016
  8. Stefan BellerDec 27, 2016
  9. 4/4 rm: absorb a submodules git dir before deletionStefan Beller, Dec 20, 2016
  10. Junio C HamanoDec 27, 2016
  11. Stefan BellerDec 27, 2016
  12. Stefan BellerDec 27, 2016
  13. Junio C HamanoDec 27, 2016

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.