sequencer: lib'ify save_todo()
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 save_todo(), pick_commits() can already return errors, 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 save_todo() 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
221675de8d7ef363944161d8d887fb1b7afdf915
1 file changed
+15
-7
sequencer.c
+15
-7
@@ -943,24 +943,31 @@ fail:
943
return -1;
944
}
945
946
-static void save_todo(struct commit_list *todo_list, struct replay_opts *opts)
946
+static int save_todo(struct commit_list *todo_list, struct replay_opts *opts)
947
{
948
static struct lock_file todo_lock;
949
struct strbuf buf = STRBUF_INIT;
950
int fd;
951
952
- fd = hold_lock_file_for_update(&todo_lock, git_path_todo_file(), LOCK_DIE_ON_ERROR);
953
- if (format_todo(&buf, todo_list, opts) < 0)
954
- die(_("Could not format %s."), git_path_todo_file());
952
+ fd = hold_lock_file_for_update(&todo_lock, git_path_todo_file(), 0);
953
+ if (fd < 0)
954
+ return error_errno(_("Could not lock '%s'"),
955
+ git_path_todo_file());
956
+ if (format_todo(&buf, todo_list, opts) < 0) {
957
+ strbuf_release(&buf);
958
+ return error(_("Could not format %s."), git_path_todo_file());
959
+ }
960
if (write_in_full(fd, buf.buf, buf.len) < 0) {
961
strbuf_release(&buf);
957
- die_errno(_("Could not write to %s"), git_path_todo_file());
962
+ return error_errno(_("Could not write to %s"),
963
+ git_path_todo_file());
964
}
965
if (commit_lock_file(&todo_lock) < 0) {
966
strbuf_release(&buf);
961
- die(_("Error wrapping up %s."), git_path_todo_file());
967
+ return error(_("Error wrapping up %s."), git_path_todo_file());
968
}
969
strbuf_release(&buf);
970
+ return 0;
971
}
972
973
static void save_opts(struct replay_opts *opts)
@@ -1009,7 +1016,8 @@ static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
1016
return -1;
1017
1018
for (cur = todo_list; cur; cur = cur->next) {
1012
- save_todo(cur, opts);
1019
+ if (save_todo(cur, opts))
1020
+ return -1;
1021
res = do_pick_commit(cur->item, opts);
1022
if (res)
1023
return res;