sequencer: lib'ify write_message()

Instead of dying there, let the caller high up in the callchain notice the error and handle it (by dying, still). The only caller of write_message(), do_pick_commit() already checks the return value and passes it on to its callers, so its caller must be already prepared to handle error returns, and with this step, we make it notice an error return from this function. So this is a safe conversion to make write_message() callable from new callers that want it not to die, without changing the external behaviour of anything existing. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Sep 9, 2016 at 16:37 UTC 4ef3d8f0336d4d1d5a57de9ac7c0cfdb09b974b1
1 file changed +11 -8
sequencer.c
+11 -8
@@ -180,17 +180,20 @@ static void print_advice(int show_hint, struct replay_opts *opts)
180 }
181 }
182
183 -static void write_message(struct strbuf *msgbuf, const char *filename)
183 +static int write_message(struct strbuf *msgbuf, const char *filename)
184 {
185 static struct lock_file msg_file;
186
187 - int msg_fd = hold_lock_file_for_update(&msg_file, filename,
188 - LOCK_DIE_ON_ERROR);
187 + int msg_fd = hold_lock_file_for_update(&msg_file, filename, 0);
188 + if (msg_fd < 0)
189 + return error_errno(_("Could not lock '%s'"), filename);
190 if (write_in_full(msg_fd, msgbuf->buf, msgbuf->len) < 0)
190 - die_errno(_("Could not write to %s"), filename);
191 + return error_errno(_("Could not write to %s"), filename);
192 strbuf_release(msgbuf);
193 if (commit_lock_file(&msg_file) < 0)
193 - die(_("Error wrapping up %s."), filename);
194 + return error(_("Error wrapping up %s."), filename);
195 +
196 + return 0;
197 }
198
199 static struct tree *empty_tree(void)
@@ -564,16 +567,16 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
567 head, &msgbuf, opts);
568 if (res < 0)
569 return res;
567 - write_message(&msgbuf, git_path_merge_msg());
570 + res |= write_message(&msgbuf, git_path_merge_msg());
571 } else {
572 struct commit_list *common = NULL;
573 struct commit_list *remotes = NULL;
574
572 - write_message(&msgbuf, git_path_merge_msg());
575 + res = write_message(&msgbuf, git_path_merge_msg());
576
577 commit_list_insert(base, &common);
578 commit_list_insert(next, &remotes);
576 - res = try_merge_command(opts->strategy, opts->xopts_nr, opts->xopts,
579 + res |= try_merge_command(opts->strategy, opts->xopts_nr, opts->xopts,
580 common, sha1_to_hex(head), remotes);
581 free_commit_list(common);
582 free_commit_list(remotes);