Skip to content

Commit

Permalink
builtin/am: make sure state files are text
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Aug 24, 2015
1 parent 25b763b commit 57c867e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions builtin/am.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 57c867e

Please sign in to comment.