Skip to content

Commit 221675d

Browse files
dschogitster
authored andcommitted
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>
1 parent 311fd39 commit 221675d

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

sequencer.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,24 +943,31 @@ static int sequencer_rollback(struct replay_opts *opts)
943943
return -1;
944944
}
945945

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)
947947
{
948948
static struct lock_file todo_lock;
949949
struct strbuf buf = STRBUF_INIT;
950950
int fd;
951951

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+
}
955960
if (write_in_full(fd, buf.buf, buf.len) < 0) {
956961
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());
958964
}
959965
if (commit_lock_file(&todo_lock) < 0) {
960966
strbuf_release(&buf);
961-
die(_("Error wrapping up %s."), git_path_todo_file());
967+
return error(_("Error wrapping up %s."), git_path_todo_file());
962968
}
963969
strbuf_release(&buf);
970+
return 0;
964971
}
965972

966973
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)
10091016
return -1;
10101017

10111018
for (cur = todo_list; cur; cur = cur->next) {
1012-
save_todo(cur, opts);
1019+
if (save_todo(cur, opts))
1020+
return -1;
10131021
res = do_pick_commit(cur->item, opts);
10141022
if (res)
10151023
return res;

0 commit comments

Comments
 (0)