Skip to content

Commit 57c867e

Browse files
committed
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>
1 parent 25b763b commit 57c867e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

builtin/am.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,19 @@ static inline const char *am_path(const struct am_state *state, const char *path
199199
static int write_state_text(const struct am_state *state,
200200
const char *name, const char *string)
201201
{
202-
return write_file(am_path(state, name), 1, "%s", string);
202+
const char *fmt;
203+
204+
if (*string && string[strlen(string) - 1] != '\n')
205+
fmt = "%s\n";
206+
else
207+
fmt = "%s";
208+
return write_file(am_path(state, name), 1, fmt, string);
203209
}
204210

205211
static int write_state_count(const struct am_state *state,
206212
const char *name, int value)
207213
{
208-
return write_file(am_path(state, name), 1, "%d", value);
214+
return write_file(am_path(state, name), 1, "%d\n", value);
209215
}
210216

211217
static int write_state_bool(const struct am_state *state,

0 commit comments

Comments
 (0)