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

Re: [PATCHv15 2/5] run_processes_parallel: add LF when caller is sloppy

From
Stefan Beller <sbeller@google.com>
Date
Feb 24, 2016, 21:19 UTC
Message-ID
<CAGZ79kYv-dKMnON=Hj2fUNEbUXz=8ti3x3tNG2WxWmdr5CA2tA@mail.gmail.com>
In-Reply-To
<xmqqa8mpub1y.fsf@gitster.mtv.corp.google.com>
On Wed, Feb 24, 2016 at 12:07 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 26 quoted lines
> Stefan Beller <sbeller@google.com> writes:
>
>> @@ -1095,9 +1098,11 @@ static void pp_buffer_stderr(struct parallel_processes *pp, int output_timeout)
>>  static void pp_output(struct parallel_processes *pp)
>>  {
>>       int i = pp->output_owner;
>> -     if (pp->children[i].state == GIT_CP_WORKING &&
>> -         pp->children[i].err.len) {
>> +     size_t len = pp->children[i].err.len;
>> +     if (pp->children[i].state == GIT_CP_WORKING && len) {
>>               fputs(pp->children[i].err.buf, stderr);
>> +             pp->ended_with_newline =
>> +                     (pp->children[i].err.buf[len - 1] == '\n');
>>               strbuf_reset(&pp->children[i].err);
>>       }
>>  }
>
> The child->err thing is treated as a counted byte array when the
> code determines where the end of the buffer is, but is treated as a
> nul-terminated string when it is output with fputs().
>
> The inconsistency may not hurt as long as (1) the producers of the
> message will never stuff a NUL in the middle, and (2) strbuf always
> has the guard NUL after its contents.  Even though we know that the
> latter will hold true for the foreseeable future, it also is easy to
> do the right thing here, too, so why not?

What is the right thing? I asked myself and obviously it is treating the child->err the same in both cases of checking for a trailing LF and when outputting.

But what is the right way to look at child->err? I would argue that we should allow for children to have a NUL in its output stream and replay their output as literal as possible.

i.e. my conclusion is to replace the fputs by fwrite as opposed to using strlen to determine the length of string output.

Thanks, Stefan

Previous: Junio C HamanoNext: Junio C Hamano
Message 5 of 13 in “[PATCHv15 0/5] Expose submodule parallelism to the user”
  1. Stefan BellerFeb 24, 2016
  2. 1/5 run-command: expose default_{start_failure, task_finished}Stefan Beller, Feb 24, 2016
  3. 2/5 run_processes_parallel: add LF when caller is sloppyStefan Beller, Feb 24, 2016
  4. Junio C HamanoFeb 24, 2016
  5. Stefan BellerFeb 24, 2016
  6. Junio C HamanoFeb 24, 2016
  7. Jonathan NiederFeb 24, 2016
  8. Stefan BellerFeb 24, 2016
  9. Jonathan NiederFeb 25, 2016
  10. Junio C HamanoFeb 25, 2016
  11. 3/5 git submodule update: have a dedicated helper for cloningStefan Beller, Feb 24, 2016
  12. 4/5 submodule update: expose parallelism to the userStefan Beller, Feb 24, 2016
  13. 5/5 clone: allow an explicit argument for parallel submodule clonesStefan Beller, Feb 24, 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.