Skip to content

Commit f56fffe

Browse files
dschogitster
authored andcommitted
sequencer: teach write_message() to append an optional LF
This commit prepares for future callers that will have a pointer/length to some text to be written that lacks an LF, yet an LF is desired. Instead of requiring the caller to append an LF to the buffer (and potentially allocate memory to do so), the write_message() function learns to append an LF at the end of the file. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7587149 commit f56fffe

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sequencer.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ static void print_advice(int show_hint, struct replay_opts *opts)
234234
}
235235
}
236236

237-
static int write_message(const void *buf, size_t len, const char *filename)
237+
static int write_message(const void *buf, size_t len, const char *filename,
238+
int append_eol)
238239
{
239240
static struct lock_file msg_file;
240241

@@ -245,6 +246,10 @@ static int write_message(const void *buf, size_t len, const char *filename)
245246
rollback_lock_file(&msg_file);
246247
return error_errno(_("Could not write to '%s'"), filename);
247248
}
249+
if (append_eol && write(msg_fd, "\n", 1) < 0) {
250+
rollback_lock_file(&msg_file);
251+
return error_errno(_("Could not write eol to '%s"), filename);
252+
}
248253
if (commit_lock_file(&msg_file) < 0) {
249254
rollback_lock_file(&msg_file);
250255
return error(_("Error wrapping up %s."), filename);
@@ -748,13 +753,13 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
748753
if (res < 0)
749754
return res;
750755
res |= write_message(msgbuf.buf, msgbuf.len,
751-
git_path_merge_msg());
756+
git_path_merge_msg(), 0);
752757
} else {
753758
struct commit_list *common = NULL;
754759
struct commit_list *remotes = NULL;
755760

756761
res = write_message(msgbuf.buf, msgbuf.len,
757-
git_path_merge_msg());
762+
git_path_merge_msg(), 0);
758763

759764
commit_list_insert(base, &common);
760765
commit_list_insert(next, &remotes);

0 commit comments

Comments
 (0)