On Sun, Aug 23, 2015 at 12:05:32PM -0700, Junio C Hamano wrote:

> > -   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()).

> @@ -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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to