builtin/am: make sure state files are text

We forgot to terminate the payload given to write_file() with LF, resulting in files that end with an incomplete line. Teach the wrappers builtin/am uses to make sure it adds LF at the end as necessary. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 24, 2015 at 09:43 UTC 57c867efe4e005e40cfdee8a64550d7a95bbb9a0
1 file changed +8 -2
builtin/am.c
+8 -2
@@ -199,13 +199,19 @@ static inline const char *am_path(const struct am_state *state, const char *path
199 static int write_state_text(const struct am_state *state,
200 const char *name, const char *string)
201 {
202 - return write_file(am_path(state, name), 1, "%s", string);
202 + const char *fmt;
203 +
204 + if (*string && string[strlen(string) - 1] != '\n')
205 + fmt = "%s\n";
206 + else
207 + fmt = "%s";
208 + return write_file(am_path(state, name), 1, fmt, string);
209 }
210
211 static int write_state_count(const struct am_state *state,
212 const char *name, int value)
213 {
208 - return write_file(am_path(state, name), 1, "%d", value);
214 + return write_file(am_path(state, name), 1, "%d\n", value);
215 }
216
217 static int write_state_bool(const struct am_state *state,