From: Junio C Hamano Date: Mon, 24 Aug 2015 20:58:06 GMT Subject: [PATCH v2 2/6] builtin/am: make sure state files are text Message-ID: <1440449890-29490-3-git-send-email-gitster@pobox.com> In-Reply-To: <1440449890-29490-1-git-send-email-gitster@pobox.com> 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 --- builtin/am.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 4d34dc5..f0a046b 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -199,13 +199,19 @@ static inline const char *am_path(const struct am_state *state, const char *path static int write_state_text(const struct am_state *state, const char *name, const char *string) { - return write_file(am_path(state, name), 1, "%s", string); + const char *fmt; + + if (*string && string[strlen(string) - 1] != '\n') + fmt = "%s\n"; + else + fmt = "%s"; + return write_file(am_path(state, name), 1, fmt, string); } static int write_state_count(const struct am_state *state, const char *name, int value) { - return write_file(am_path(state, name), 1, "%d", value); + return write_file(am_path(state, name), 1, "%d\n", value); } static int write_state_bool(const struct am_state *state, -- 2.5.0-568-g53a3e28