sequencer: refactor write_message() to take a pointer/length

Previously, we required an strbuf. But that limits the use case too much. In the upcoming patch series (for which the current patch series prepares the sequencer), we will want to write content to a file for which we have a pointer and a length, not an strbuf. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Oct 21, 2016 at 14:26 UTC 75871495e9e0012604861752d082715d9444333d
1 file changed +6 -4
sequencer.c
+6 -4
@@ -234,14 +234,14 @@ static void print_advice(int show_hint, struct replay_opts *opts)
234 }
235 }
236
237 -static int write_message(struct strbuf *msgbuf, const char *filename)
237 +static int write_message(const void *buf, size_t len, const char *filename)
238 {
239 static struct lock_file msg_file;
240
241 int msg_fd = hold_lock_file_for_update(&msg_file, filename, 0);
242 if (msg_fd < 0)
243 return error_errno(_("Could not lock '%s'"), filename);
244 - if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0) {
244 + if (write_in_full(msg_fd, buf, len) < 0) {
245 rollback_lock_file(&msg_file);
246 return error_errno(_("Could not write to '%s'"), filename);
247 }
@@ -747,12 +747,14 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
747 head, &msgbuf, opts);
748 if (res < 0)
749 return res;
750 - res |= write_message(&msgbuf, git_path_merge_msg());
750 + res |= write_message(msgbuf.buf, msgbuf.len,
751 + git_path_merge_msg());
752 } else {
753 struct commit_list *common = NULL;
754 struct commit_list *remotes = NULL;
755
755 - res = write_message(&msgbuf, git_path_merge_msg());
756 + res = write_message(msgbuf.buf, msgbuf.len,
757 + git_path_merge_msg());
758
759 commit_list_insert(base, &common);
760 commit_list_insert(next, &remotes);