Re: [PATCH] am: terminate state files with a newline
- From
Jeff King <peff@peff.net>
- Date
- Aug 24, 2015, 05:13 UTC
- Message-ID
- <20150824051344.GA12490@sigill.intra.peff.net>
- In-Reply-To
- <xmqqy4h16d1f.fsf@gitster.dls.corp.google.com>
On Sun, Aug 23, 2015 at 12:05:32PM -0700, Junio C Hamano wrote:
Show 8 quoted lines
> > - write_file(am_path(state, "threeway"), 1, state->threeway ? "t" : "f"); > > + write_file(am_path(state, "threeway"), 1, "%s\n", state->threeway ? "t" : "f"); > > Stepping back a bit, after realizing that "write_file()" is a > short-hand for "I have all information necessary to produce the full > contents of a file, now go ahead and create and write that and > close", I have to wonder what caller even wants to create a file > with an incomplete line at the end.
FWIW, I had a similar thought when reading the original thread. I also noted that all of the callers here pass "1" for the "fatal" parameter, and that they are either bools or single strings. I wonder if:
void write_state_bool(struct am_state *state, const char *name, int v)
{
write_file(am_path(state, name), 1, "%s\n", v ? "t" : "f");
}would make the call-sites even easier to read (and of course the "\n" would be dropped here if it does migrate up to write_file()).
Show 7 quoted lines
> @@ -634,6 +641,9 @@ int write_file(const char *path, int fatal, const char *fmt, ...) > va_start(params, fmt); > strbuf_vaddf(&sb, fmt, params); > va_end(params); > + if (sb.len) > + strbuf_complete_line(&sb); > +
I think the "if" here is redundant; strbuf_complete_line already handles it.
-Peff