summaryrefslogtreecommitdiff
path: root/builtin/am.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-08-24 16:43:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-08-24 20:01:59 (GMT)
commit57c867efe4e005e40cfdee8a64550d7a95bbb9a0 (patch)
tree9e7b8f7e0a6ea2be11e55cefd672c42895b08887 /builtin/am.c
parent25b763ba7a544d05fc46ad601f3f9c50a4cea8b0 (diff)
downloadgit-57c867efe4e005e40cfdee8a64550d7a95bbb9a0.zip
git-57c867efe4e005e40cfdee8a64550d7a95bbb9a0.tar.gz
git-57c867efe4e005e40cfdee8a64550d7a95bbb9a0.tar.bz2
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>
Diffstat (limited to 'builtin/am.c')
-rw-r--r--builtin/am.c10
1 files 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,