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

Re: Anyone know why git ls-remote output might be corrupted?

From
Paul Smith <paul@mad-scientist.net>
Date
Jun 12, 2023, 19:59 UTC
Message-ID
<21193d97d43094a01b4ac9442448135867e22c70.camel@mad-scientist.net>
In-Reply-To
<xmqqo7loo42s.fsf@gitster.g>
On Sat, 2023-06-10 at 03:58 +0900, Junio C Hamano wrote:
Show 19 quoted lines
> Paul Smith <paul@mad-scientist.net> writes:
> 
> > I also checked and indeed, the git ls-remote command does print to
> > both stdout and stderr as part of its "standard" behavior:
> > 
> >    $ git ls-remote --heads >/dev/null
> >    From git@git:myrepo
> > 
> > This is unexpected to me, although of course there's nothing
> > inherently wrong with it but usually you don't expect "regular"
> > output to go to stderr.  I suppose the idea is that people can run:
> > 
> >    $ git ls-remote --heads 2>/dev/null
> > 
> > if they want just the output without the header.
> 
> The above sounds like a reasonable expectation; then the issue is
> there are some fflush missing when the command writes to one stream
> and switches to write to another stream?

It's not immediately clear to me which "above" you refer to as a reasonable expectation (the reason for the stdout vs. stderr different I suppose?)

But I agree that forcing flush would be a good idea (or perhaps forcing line buffering? Changing buffering can be annoying to do portably), for situations in which the output is being sent to a non-TTY, because the default in that situation is fully buffered output.

Maybe it would be sufficient to have any output to stderr run fflush(stdout) before the output, and fflush(stderr) after the output. Presumably output to stderr is relatively rare, and so this wouldn't be very noticeable.

Previous: Junio C Hamano
Message 14 of 14 in “Anyone know why git ls-remote output might be corrupted?”
  1. Paul SmithJun 2, 2023
  2. Paul SmithJun 2, 2023
  3. rsbecker@nexbridge.comJun 2, 2023
  4. Paul SmithJun 2, 2023
  5. rsbecker@nexbridge.comJun 2, 2023
  6. Paul SmithJun 2, 2023
  7. Elijah NewrenJun 3, 2023
  8. Elijah NewrenJun 3, 2023
  9. Jeff KingJun 4, 2023
  10. Jeff KingJun 4, 2023
  11. Jeff KingJun 4, 2023
  12. Paul SmithJun 9, 2023
  13. Junio C HamanoJun 9, 2023
  14. Paul SmithJun 12, 2023

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.