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

Re: [PATCH 1/2] read_and_strip_branch: fix typo'd address-of operator

From
Jeff King <peff@peff.net>
Date
Jan 28, 2015, 22:57 UTC
Message-ID
<20150128225755.GA15719@peff.net>
In-Reply-To
<xmqq1tmehc25.fsf@gitster.dls.corp.google.com>
On Wed, Jan 28, 2015 at 12:42:26PM -0800, Junio C Hamano wrote:
> > This is the most minimal fix, but I kind of wonder if it should just be
> > using strbuf_rtrim (or even strbuf_trim) in the first place.
> 
> Yeah.  Or strbuf_chomp(), which does not exist ;-)

This is not the first time I've seen this chomp/trim distinction come up. However, the thing that has prevented me from writing strbuf_chomp is that the trim is almost always a more reasonable choice.

Take this instance. We are opening and reading a whole file. Surely we need to drop the final newline, which is not interesting. But we are not just doing that; we are dropping _all_ trailing newlines. So "foo\n\n" becomes "foo". But "foo\n \n" does not. That doesn't make much sense.

IOW, I would venture to say that chomping like this falls into one of two categories:

  1. You want to clean up any extraneous cruft. Multiple lines, extra
     whitespace, etc.
  2. You want to read one line, but don't want the trailing newline.
And strbuf_getline already handles case (2).
End mini-rant. :)
Show 7 quoted lines
> It is tempting to apply this directly to maint and merge up
> immediately, as there is no way this 1-byte change will break things
> (of course that is not necessarily true for random 1-byte changes,
> though).
> 
> It sometimes gets really hard to resist that temptation during the
> pre-release freeze period.

That's part of why I did the simplest fix instead of strbuf_rtrim. To tempt you. :)

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 6 in “silence clang-3.6 warnings”
  1. 0/2 silence clang-3.6 warningsJeff King, Jan 28, 2015
  2. 1/2 read_and_strip_branch: fix typo'd address-of operatorJeff King, Jan 28, 2015
  3. Junio C HamanoJan 28, 2015
  4. Jeff KingJan 28, 2015
  5. Junio C HamanoJan 29, 2015
  6. 2/2 do not check truth value of flex arraysJeff King, Jan 28, 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.