From e7ffa38c6e726e8014b76297b06f78e008deb2d0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 24 Aug 2015 09:39:48 -0700 Subject: write_file_v(): do not leave incomplete line at the end All existing callers to this function use it to produce a text file or an empty file, and a new callsite that mimick them must end their payload with a LF. If they forget to do so, the resulting file will end with an incomplete line. Teach write_file_v() to complete the incomplete line, if exists, so that the callers do not have to. With this, the caller-side fix in builtin/am.c becomes unnecessary. Signed-off-by: Junio C Hamano --- builtin/am.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'builtin') diff --git a/builtin/am.c b/builtin/am.c index 9c576779c3..486ff594d7 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -199,19 +199,13 @@ 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) { - const char *fmt; - - if (*string && string[strlen(string) - 1] != '\n') - fmt = "%s\n"; - else - fmt = "%s"; - return write_file(am_path(state, name), fmt, string); + return write_file(am_path(state, name), "%s", string); } static int write_state_count(const struct am_state *state, const char *name, int value) { - return write_file(am_path(state, name), "%d\n", value); + return write_file(am_path(state, name), "%d", value); } static int write_state_bool(const struct am_state *state, -- cgit v1.2.3