Skip to content

Commit 88d5a27

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

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

sequencer.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -970,37 +970,39 @@ static int save_todo(struct commit_list *todo_list, struct replay_opts *opts)
970970
return 0;
971971
}
972972

973-
static void save_opts(struct replay_opts *opts)
973+
static int save_opts(struct replay_opts *opts)
974974
{
975975
const char *opts_file = git_path_opts_file();
976+
int res = 0;
976977

977978
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");
979980
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");
981982
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");
983984
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");
985986
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");
987988
if (opts->mainline) {
988989
struct strbuf buf = STRBUF_INIT;
989990
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);
991992
strbuf_release(&buf);
992993
}
993994
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);
995996
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);
997998
if (opts->xopts) {
998999
int i;
9991000
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,
10011002
"options.strategy-option",
10021003
opts->xopts[i], "^$", 0);
10031004
}
1005+
return res;
10041006
}
10051007

10061008
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)
11471149
return error(_("Can't revert as initial commit"));
11481150
if (save_head(sha1_to_hex(sha1)))
11491151
return -1;
1150-
save_opts(opts);
1152+
if (save_opts(opts))
1153+
return -1;
11511154
return pick_commits(todo_list, opts);
11521155
}
11531156

0 commit comments

Comments
 (0)