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

Re: What's cooking in git.git (Jan 2017, #02; Sun, 15)

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 16, 2017, 17:06 UTC
Message-ID
<alpine.DEB.2.20.1701161746200.3469@virtualbox>
In-Reply-To
<20170116160456.ltbb7ofe47xos7xo@sigill.intra.peff.net>
Hi Peff,
On Mon, 16 Jan 2017, Jeff King wrote:
Show 24 quoted lines
> On Mon, Jan 16, 2017 at 01:52:39PM +0100, Johannes Schindelin wrote:
> 
> > > >  An error message with an ASCII control character like '\r' in it
> > > >  can alter the message to hide its early part, which is problematic
> > > >  when a remote side gives such an error message that the local side
> > > >  will relay with a "remote: " prefix.
> > > >
> > > >  Will merge to 'next'.
> > > 
> > > Please be not too hasty with advancing this topic to master. I could imagine
> > > that there is some unwanted fallout on systems where the end-of-line marker
> > > CRLF is common. Though, I haven't tested the topic myself, yet, nor do I
> > > expect regressions in *my* typical workflow.
> > 
> > Thank you for being so attentive.
> > 
> > This topic branch would indeed have caused problems. Worse: it would have
> > caused problems that are not covered by our test suite, as Git for
> > Windows' own utilities do not generate CR/LF line endings. So this
> > regression would have bit our users. Nasty.
> 
> Hmm.  I am not sure to what degree CRLFs are actually a problem here.
> Keep in mind these are error messages generated via error(), and so not
> processing arbitrary data. I can imagine that CRs might come from:

Please note the regression test I added. It uses rev-parse's --abbrev-ref option which quotes the argument when erroring out. This argument then gets munged.

So error() (or in this case, die()) *very much* processes arbitrary data.

I *know* that rev-parse --abbrev-ref is an artificial example, it is highly unlikely that anybody will use

	git rev-parse --abbrev-ref "$(<call an external program here that
		generates CR/LF line endings>)"

However, there are plenty other cases in regular Git usage where arguments are generated by external programs to which we have no business dictating a specific line ending style.

If you absolutely insist, I will spend time to find a plausible example and use that in the regression test. However, that would not really improve anything, as the purpose of the regression test is simply to demonstrate that a user-provided argument's CR/LF does not get munged incorrectly. And the test I provided serves that purpose perfectly.

Show 10 quoted lines
>   1. A parameter like a filename or revision name. If I ask for a
>      rev-parse of "foo\r\n", then it's probably useful to mention the
>      "\r" in the error message, rather than ignoring it (or converting
>      it to a line-feed).
> 
>      And I think that would apply to any input parameter we show via
>      error(), etc, if it is connected to a newline (ideally we would
>      show newlines as "?", too, but we cannot tell the difference
>      between ones from parameters, and ones that are part of the error
>      message).

I think it is doing users a really great disservice to munge up CR or LF into question marks. I *guarantee* you that it confuses users. And not because they are dumb, but because the code violates the Law of Least Surprise.

> I am certainly open to loosening the sanitizing for CR to make things
> work seamlessly on Windows. But I am having trouble imagining a case
> that is actually negatively impacted.

Git accepts all kinds of arguments, not just file names. It is totally legitimate, and you probably can show use cases of that yourself, to generate those arguments by other programs.

These programs can generate CR/LF line endings.

While well-intentioned, your changes could make things even unreadable. Certainly confusing.

> > -- snipsnap --
> > Subject: [PATCH] fixup! vreport: sanitize ASCII control chars
> 
> Given the subtlety here, I'd much rather have a patch on top.
Fine.
Show 22 quoted lines
> > The original patch is incorrect, as it turns carriage returns into
> > question marks.
> > 
> > However, carriage returns should be left alone when preceding a line feed,
> > and simply turned into line feeds otherwise.
> 
> The question of whether to leave CRLFs alone is addressed above. But I
> do not understand why you'd want a lone CR to be converted to a line
> feed. Running:
> 
>   git rev-parse --abbrev-ref "$(printf "foo\r")"
> 
> with my patch gets you:
> 
>   fatal: ambiguous argument 'foo?': unknown revision or path not in the working tree.
> 
> But with yours:
> 
>   fatal: ambiguous argument 'foo
>   ': unknown revision or path not in the working tree.
> 
> Obviously the "?" thing is a lossy transformation,
s/lossy/confusing/

Probably not to you, because you came up with the transformation, but to literally everybody else.

> but I do not see how a newline is any less confusing (but see below for
> some thoughts).

The more common bug report to be expected would show that multi-line arguments are converted to ending in question marks. That is not the user experience for which I am aiming.

Show 19 quoted lines
> > To make the end result more readable, the logic is inverted so that the
> > common case (no substitution) is handled first.
> > 
> > While at it, let's lose the unnecessary curly braces.
> 
> Please don't. Obviously C treats the "if/else" as a single unit, but
> IMHO it's less error-prone to include the braces any time there are
> multiple visual lines. E.g., something like:
> 
>   while (foo)
> 	if (bar)
> 		one();
> 	else
> 		two();
> 	three();
> 
> is much easier to spot as wrong when you would require braces either
> way (and not relevant here, but I'd say that even an inner block with a
> comment deserves braces for the same reason).
There is no documentation about the preferred coding style.

For years, I saw patches, and provided patches myself, that *avoided* curly braces when not necessary (in addition to aiming for shorter arms to come before longer arms in conditionals).

Now all of a sudden Junio *and* you suggest unnecessary curly braces to be added.

That is inconsistent at best, and confusing. Maybe you two gentle people can make up your mind and document the final verdict, and for extra brownie points automate the formatting so that patch reviews are not dominated by coding style comments that would be better addressed by machines than by humans.

Show 17 quoted lines
> > We also add a regression test that verifies that carriage returns are
> > handled properly. And as we expect CR/LF to be handled properly also on
> > platforms other than Windows, this test case is not guarded by the MINGW
> > prerequisite.
> 
> I am not sure what "properly" means here. In your test:
> 
> > +# This test verifies that the error reporting functions handle CR correctly.
> > +# --abbrev-ref is simply used out of convenience, as it reports an error including
> > +# a user-specified argument.
> > +test_expect_success 'error messages treat CR/LF correctly' '
> > +	test_must_fail git rev-parse --abbrev-ref "$(printf "CR/LF\\r\\n")" 2>err &&
> > +	grep "^fatal: .*CR/LF$" err
> > +'
> 
> The "\n" is eaten by the shell, and git sees only "CR/LF\r". So we are
> not testing the CRLF case in vreportf() at all.
True. Should be easy to fix, starting from my patch.
Show 6 quoted lines
> We do end up with "CR/LF\n" in vreportf(), which is presumably converted
> by fprintf() to "CR/LF\r\n" on Windows. And so perhaps that is why you
> are doing the "convert \r to \n" thing above.
> 
> But I still think it's not doing the right thing. Git _didn't_ see CRLF,
> it saw CR.

You know, I don't care. As long as carriage returns are either left alone (which conflicts specifically with your stated goal) or at least are handled gracefully when coming before line feeds.

Converting stray carriage returns to question marks is confusing, and of course I would take the brunt of the bug reports, so I do not look favorably on that change.

My patch was just a starter, to help with fixing the patch series before it hits `next`.

Ciao, Johannes

Previous: Jeff KingNext: Johannes Sixt
Message 6 of 28 in “What's cooking in git.git (Jan 2017, #02; Sun, 15)”
  1. Junio C HamanoJan 16, 2017
  2. Johannes SixtJan 16, 2017
  3. Junio C HamanoJan 16, 2017
  4. Johannes SchindelinJan 16, 2017
  5. Jeff KingJan 16, 2017
  6. Johannes SchindelinJan 16, 2017
  7. Johannes SixtJan 16, 2017
  8. Jeff KingJan 16, 2017
  9. Junio C HamanoJan 17, 2017
  10. Johannes SixtJan 18, 2017
  11. Junio C HamanoJan 18, 2017
  12. Johannes SchindelinJan 19, 2017
  13. Jeff KingJan 16, 2017
  14. CodingGuidelines: clarify multi-line brace styleJeff King, Jan 16, 2017
  15. Junio C HamanoJan 17, 2017
  16. Jeff KingJan 17, 2017
  17. Junio C HamanoJan 17, 2017
  18. Jacob KellerJan 17, 2017
  19. Jeff KingJan 17, 2017
  20. Junio C HamanoJan 17, 2017
  21. Jeff KingJan 17, 2017
  22. Junio C HamanoJan 17, 2017
  23. Jeff KingJan 17, 2017
  24. Johannes SchindelinJan 16, 2017
  25. Junio C HamanoJan 17, 2017
  26. Johannes SchindelinJan 18, 2017
  27. Johannes SchindelinJan 16, 2017
  28. 4/4 unpack-trees: support super-prefix optionStefan Beller, Jan 18, 2017

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.