reset_head(): take struct rebase_head_opts

This function takes a confusingly large number of parameters which
makes it difficult to remember which order to pass them in. The
following commits will add a couple more parameters which makes the
problem worse. To address this change the function to take a struct of
options. Using a struct means that it is no longer necessary to
remember which order to pass the parameters in and anyone reading the
code can easily see which value is passed to each parameter.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Phillip Wood
2022-01-26 13:05:46 +00:00
committed by Junio C Hamano
parent ee464c4e37
commit 6ae8086161
4 changed files with 92 additions and 48 deletions

View File

@ -4115,6 +4115,7 @@ void create_autostash(struct repository *r, const char *path)
if (has_unstaged_changes(r, 1) ||
has_uncommitted_changes(r, 1)) {
struct child_process stash = CHILD_PROCESS_INIT;
struct reset_head_opts ropts = { .flags = RESET_HEAD_HARD };
struct object_id oid;
strvec_pushl(&stash.args,
@ -4136,10 +4137,8 @@ void create_autostash(struct repository *r, const char *path)
path);
write_file(path, "%s", oid_to_hex(&oid));
printf(_("Created autostash: %s\n"), buf.buf);
if (reset_head(r, NULL, NULL, RESET_HEAD_HARD, NULL, NULL,
NULL) < 0)
if (reset_head(r, &ropts) < 0)
die(_("could not reset --hard"));
if (discard_index(r->index) < 0 ||
repo_read_index(r) < 0)
die(_("could not read index"));