sequencer: lib'ify read_populate_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 read_populate_todo(), sequencer_continue() 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 read_populate_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 0ae42a038da1f63a5b090b70502087817cc54f5d
1 file changed +9 -5
sequencer.c
+9 -5
@@ -748,7 +748,7 @@ static int parse_insn_buffer(char *buf, struct commit_list **todo_list,
748 return 0;
749 }
750
751 -static void read_populate_todo(struct commit_list **todo_list,
751 +static int read_populate_todo(struct commit_list **todo_list,
752 struct replay_opts *opts)
753 {
754 struct strbuf buf = STRBUF_INIT;
@@ -756,18 +756,21 @@ static void read_populate_todo(struct commit_list **todo_list,
756
757 fd = open(git_path_todo_file(), O_RDONLY);
758 if (fd < 0)
759 - die_errno(_("Could not open %s"), git_path_todo_file());
759 + return error_errno(_("Could not open %s"),
760 + git_path_todo_file());
761 if (strbuf_read(&buf, fd, 0) < 0) {
762 close(fd);
763 strbuf_release(&buf);
763 - die(_("Could not read %s."), git_path_todo_file());
764 + return error(_("Could not read %s."), git_path_todo_file());
765 }
766 close(fd);
767
768 res = parse_insn_buffer(buf.buf, todo_list, opts);
769 strbuf_release(&buf);
770 if (res)
770 - die(_("Unusable instruction sheet: %s"), git_path_todo_file());
771 + return error(_("Unusable instruction sheet: %s"),
772 + git_path_todo_file());
773 + return 0;
774 }
775
776 static int populate_opts_cb(const char *key, const char *value, void *data)
@@ -1019,7 +1022,8 @@ static int sequencer_continue(struct replay_opts *opts)
1022 if (!file_exists(git_path_todo_file()))
1023 return continue_single_pick();
1024 read_populate_opts(&opts);
1022 - read_populate_todo(&todo_list, opts);
1025 + if (read_populate_todo(&todo_list, opts))
1026 + return -1;
1027
1028 /* Verify that the conflict has been resolved */
1029 if (file_exists(git_path_cherry_pick_head()) ||