Re: [PATCH 3/3] notes remove: --stdin reads from the standard input
- From
Jeff King <peff@peff.net>
- Date
- May 19, 2011, 10:50 UTC
- Message-ID
- <20110519105009.GA11107@sigill.intra.peff.net>
- In-Reply-To
- <1305764061-21303-4-git-send-email-gitster@pobox.com>
On Wed, May 18, 2011 at 05:14:21PM -0700, Junio C Hamano wrote:
Show 9 quoted lines
> + if (from_stdin) {
> + struct strbuf sb = STRBUF_INIT;
> + while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
> + int len = sb.len;
> + if (len && sb.buf[len - 1] == '\n')
> + sb.buf[--len] = '\0';
> + retval |= remove_one_note(t, sb.buf, flag);
> + }
> + }Wouldn't strbuf_rtrim (or even strbuf_trim) be useful here?
Manipulating only a copy of the len parameter while changing the strbuf itself raised warning flags, though it is correct as-is because you never actually use sb.len.
Using strbuf_trim is shorter, easier to read, and will helpfully eat any extraneous whitespace, too.
-Peff