sequencer: lib'ify read_populate_opts()

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_opts(), 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_opts() callable from new callers that want it not to die, without changing the external behaviour of anything existing. Note that the function git_config_from_file(), called from read_populate_opts(), can currently still die() (in git_parse_source(), because the do_config_from_file() function sets die_on_error = 1). We do not try to fix that here, as it would have larger ramifications on the config code, and we also assume that we write the opts file programmatically, hence any parse errors would be bugs. 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 0d00da7bb3780c29e3d42ee255e0a09de8c43587
1 file changed +14 -6
sequencer.c
+14 -6
@@ -808,12 +808,20 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
808 return 0;
809 }
810
811 -static void read_populate_opts(struct replay_opts **opts_ptr)
811 +static int read_populate_opts(struct replay_opts **opts)
812 {
813 if (!file_exists(git_path_opts_file()))
814 - return;
815 - if (git_config_from_file(populate_opts_cb, git_path_opts_file(), *opts_ptr) < 0)
816 - die(_("Malformed options sheet: %s"), git_path_opts_file());
814 + return 0;
815 + /*
816 + * The function git_parse_source(), called from git_config_from_file(),
817 + * may die() in case of a syntactically incorrect file. We do not care
818 + * about this case, though, because we wrote that file ourselves, so we
819 + * are pretty certain that it is syntactically correct.
820 + */
821 + if (git_config_from_file(populate_opts_cb, git_path_opts_file(), *opts) < 0)
822 + return error(_("Malformed options sheet: %s"),
823 + git_path_opts_file());
824 + return 0;
825 }
826
827 static int walk_revs_populate_todo(struct commit_list **todo_list,
@@ -1021,8 +1029,8 @@ static int sequencer_continue(struct replay_opts *opts)
1029
1030 if (!file_exists(git_path_todo_file()))
1031 return continue_single_pick();
1024 - read_populate_opts(&opts);
1025 - if (read_populate_todo(&todo_list, opts))
1032 + if (read_populate_opts(&opts) ||
1033 + read_populate_todo(&todo_list, opts))
1034 return -1;
1035
1036 /* Verify that the conflict has been resolved */