git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: Re: [PATCH 1/2] read_and_strip_branch: fix typo'd address-of operator
Date: Wed, 28 Jan 2015 17:57:56 -0500	[thread overview]
Message-ID: <20150128225755.GA15719@peff.net> (raw)
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. :)

> 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

  reply	other threads:[~2015-01-29  3:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-28 17:53 [PATCH 0/2] silence clang-3.6 warnings Jeff King
2015-01-28 17:57 ` [PATCH 1/2] read_and_strip_branch: fix typo'd address-of operator Jeff King
2015-01-28 20:42   ` Junio C Hamano
2015-01-28 22:57     ` Jeff King [this message]
2015-01-29  6:22       ` Junio C Hamano
2015-01-28 17:58 ` [PATCH 2/2] do not check truth value of flex arrays Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150128225755.GA15719@peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).