sequencer: lib'ify save_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 save_opts(), sequencer_pick_revisions() 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_opts() 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 88d5a271b01cbbdcfe558a6bf98b601911c33c03
1 file changed +14 -11
sequencer.c
+14 -11
@@ -970,37 +970,39 @@ static int save_todo(struct commit_list *todo_list, struct replay_opts *opts)
970 return 0;
971 }
972
973 -static void save_opts(struct replay_opts *opts)
973 +static int save_opts(struct replay_opts *opts)
974 {
975 const char *opts_file = git_path_opts_file();
976 + int res = 0;
977
978 if (opts->no_commit)
978 - git_config_set_in_file(opts_file, "options.no-commit", "true");
979 + res |= git_config_set_in_file_gently(opts_file, "options.no-commit", "true");
980 if (opts->edit)
980 - git_config_set_in_file(opts_file, "options.edit", "true");
981 + res |= git_config_set_in_file_gently(opts_file, "options.edit", "true");
982 if (opts->signoff)
982 - git_config_set_in_file(opts_file, "options.signoff", "true");
983 + res |= git_config_set_in_file_gently(opts_file, "options.signoff", "true");
984 if (opts->record_origin)
984 - git_config_set_in_file(opts_file, "options.record-origin", "true");
985 + res |= git_config_set_in_file_gently(opts_file, "options.record-origin", "true");
986 if (opts->allow_ff)
986 - git_config_set_in_file(opts_file, "options.allow-ff", "true");
987 + res |= git_config_set_in_file_gently(opts_file, "options.allow-ff", "true");
988 if (opts->mainline) {
989 struct strbuf buf = STRBUF_INIT;
990 strbuf_addf(&buf, "%d", opts->mainline);
990 - git_config_set_in_file(opts_file, "options.mainline", buf.buf);
991 + res |= git_config_set_in_file_gently(opts_file, "options.mainline", buf.buf);
992 strbuf_release(&buf);
993 }
994 if (opts->strategy)
994 - git_config_set_in_file(opts_file, "options.strategy", opts->strategy);
995 + res |= git_config_set_in_file_gently(opts_file, "options.strategy", opts->strategy);
996 if (opts->gpg_sign)
996 - git_config_set_in_file(opts_file, "options.gpg-sign", opts->gpg_sign);
997 + res |= git_config_set_in_file_gently(opts_file, "options.gpg-sign", opts->gpg_sign);
998 if (opts->xopts) {
999 int i;
1000 for (i = 0; i < opts->xopts_nr; i++)
1000 - git_config_set_multivar_in_file(opts_file,
1001 + res |= git_config_set_multivar_in_file_gently(opts_file,
1002 "options.strategy-option",
1003 opts->xopts[i], "^$", 0);
1004 }
1005 + return res;
1006 }
1007
1008 static int pick_commits(struct commit_list *todo_list, struct replay_opts *opts)
@@ -1147,7 +1149,8 @@ int sequencer_pick_revisions(struct replay_opts *opts)
1149 return error(_("Can't revert as initial commit"));
1150 if (save_head(sha1_to_hex(sha1)))
1151 return -1;
1150 - save_opts(opts);
1152 + if (save_opts(opts))
1153 + return -1;
1154 return pick_commits(todo_list, opts);
1155 }
1156