summaryrefslogtreecommitdiff
path: root/builtin/am.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-08-24 16:39:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-08-25 19:48:39 (GMT)
commite7ffa38c6e726e8014b76297b06f78e008deb2d0 (patch)
tree23d35822320860fab73be8a70d75e5ba19067831 /builtin/am.c
parent12d6ce1dba504dfc5279b8d24da3edb4865c2820 (diff)
downloadgit-e7ffa38c6e726e8014b76297b06f78e008deb2d0.zip
git-e7ffa38c6e726e8014b76297b06f78e008deb2d0.tar.gz
git-e7ffa38c6e726e8014b76297b06f78e008deb2d0.tar.bz2
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 <gitster@pobox.com>
Diffstat (limited to 'builtin/am.c')
-rw-r--r--builtin/am.c10
1 files changed, 2 insertions, 8 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 9c57677..486ff59 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,