From: Phillip Wood Date: Wed, 10 Jun 2026 13:10:47 GMT Subject: Re: [PATCH v4 03/10] reset: rename `reset_head()` Message-ID: In-Reply-To: <20260610-b4-pks-history-drop-v4-3-70d5f0ae8c25@pks.im> Hi Patrick On 10/06/2026 09:52, Patrick Steinhardt wrote: > In a subsequent commit we're about to adapt `reset_head()` so that the > reference update to HEAD is optional, only. At this point the function > starts to feel misnamed, as it doesn't necessarily have anything to do > with the HEAD reference anymore. The gist of the function then is that > we reset the working tree to a specific new commit, updating both the > index and the checked-out files. > > Rename it to `reset_working_tree()` to better reflect that. That sounds good. Because we defer renaming the flags this patch is very straight forward. Thanks Phillip > Note that we don't adjust the flags yet. This will happen in a > subsequent commit. > > Suggested-by: Phillip Wood > --- > builtin/rebase.c | 20 ++++++++++---------- > reset.c | 5 +++-- > reset.h | 4 ++-- > sequencer.c | 8 ++++---- > 4 files changed, 19 insertions(+), 18 deletions(-) > > diff --git a/builtin/rebase.c b/builtin/rebase.c > index fa4f5d9306..22fbba3c62 100644 > --- a/builtin/rebase.c > +++ b/builtin/rebase.c > @@ -592,7 +592,7 @@ static int finish_rebase(struct rebase_options *opts) > static int move_to_original_branch(struct rebase_options *opts) > { > struct strbuf branch_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT; > - struct reset_head_opts ropts = { 0 }; > + struct reset_working_tree_options ropts = { 0 }; > int ret; > > if (!opts->head_name) > @@ -610,7 +610,7 @@ static int move_to_original_branch(struct rebase_options *opts) > ropts.flags = RESET_HEAD_REFS_ONLY; > ropts.branch_msg = branch_reflog.buf; > ropts.head_msg = head_reflog.buf; > - ret = reset_head(the_repository, &ropts); > + ret = reset_working_tree(the_repository, &ropts); > > strbuf_release(&branch_reflog); > strbuf_release(&head_reflog); > @@ -685,7 +685,7 @@ static int run_am(struct rebase_options *opts) > > status = run_command(&format_patch); > if (status) { > - struct reset_head_opts ropts = { 0 }; > + struct reset_working_tree_options ropts = { 0 }; > unlink(rebased_patches); > free(rebased_patches); > child_process_clear(&am); > @@ -693,7 +693,7 @@ static int run_am(struct rebase_options *opts) > ropts.oid = &opts->orig_head->object.oid; > ropts.branch = opts->head_name; > ropts.default_reflog_action = opts->reflog_action; > - reset_head(the_repository, &ropts); > + reset_working_tree(the_repository, &ropts); > error(_("\ngit encountered an error while preparing the " > "patches to replay\n" > "these revisions:\n" > @@ -855,7 +855,7 @@ static int rebase_config(const char *var, const char *value, > static int checkout_up_to_date(struct rebase_options *options) > { > struct strbuf buf = STRBUF_INIT; > - struct reset_head_opts ropts = { 0 }; > + struct reset_working_tree_options ropts = { 0 }; > int ret = 0; > > strbuf_addf(&buf, "%s: checkout %s", > @@ -866,7 +866,7 @@ static int checkout_up_to_date(struct rebase_options *options) > if (!ropts.branch) > ropts.flags |= RESET_HEAD_DETACH; > ropts.head_msg = buf.buf; > - if (reset_head(the_repository, &ropts) < 0) > + if (reset_working_tree(the_repository, &ropts) < 0) > ret = error(_("could not switch to %s"), options->switch_to); > strbuf_release(&buf); > > @@ -1116,7 +1116,7 @@ int cmd_rebase(int argc, > int reschedule_failed_exec = -1; > int allow_preemptive_ff = 1; > int preserve_merges_selected = 0; > - struct reset_head_opts ropts = { 0 }; > + struct reset_working_tree_options ropts = { 0 }; > struct option builtin_rebase_options[] = { > OPT_STRING(0, "onto", &options.onto_name, > N_("revision"), > @@ -1385,7 +1385,7 @@ int cmd_rebase(int argc, > rerere_clear(the_repository, &merge_rr); > string_list_clear(&merge_rr, 1); > ropts.flags = RESET_HEAD_HARD; > - if (reset_head(the_repository, &ropts) < 0) > + if (reset_working_tree(the_repository, &ropts) < 0) > die(_("could not discard worktree changes")); > remove_branch_state(the_repository, 0); > if (read_basic_state(&options)) > @@ -1410,7 +1410,7 @@ int cmd_rebase(int argc, > ropts.head_msg = head_msg.buf; > ropts.branch = options.head_name; > ropts.flags = RESET_HEAD_HARD; > - if (reset_head(the_repository, &ropts) < 0) > + if (reset_working_tree(the_repository, &ropts) < 0) > die(_("could not move back to %s"), > oid_to_hex(&options.orig_head->object.oid)); > strbuf_release(&head_msg); > @@ -1880,7 +1880,7 @@ int cmd_rebase(int argc, > RESET_HEAD_RUN_POST_CHECKOUT_HOOK; > ropts.head_msg = msg.buf; > ropts.default_reflog_action = options.reflog_action; > - if (reset_head(the_repository, &ropts)) { > + if (reset_working_tree(the_repository, &ropts)) { > ret = error(_("Could not detach HEAD")); > goto cleanup_autostash; > } > diff --git a/reset.c b/reset.c > index 3b3cb74dab..799596398b 100644 > --- a/reset.c > +++ b/reset.c > @@ -12,7 +12,7 @@ > #include "hook.h" > > static int update_refs(struct repository *repo, > - const struct reset_head_opts *opts, > + const struct reset_working_tree_options *opts, > const struct object_id *oid, > const struct object_id *head) > { > @@ -85,7 +85,8 @@ static int update_refs(struct repository *repo, > return ret; > } > > -int reset_head(struct repository *r, const struct reset_head_opts *opts) > +int reset_working_tree(struct repository *r, > + const struct reset_working_tree_options *opts) > { > const struct object_id *oid = opts->oid; > const char *switch_to_branch = opts->branch; > diff --git a/reset.h b/reset.h > index a28f81829d..f130152014 100644 > --- a/reset.h > +++ b/reset.h > @@ -17,7 +17,7 @@ > /* Update ORIG_HEAD as well as HEAD */ > #define RESET_ORIG_HEAD (1<<4) > > -struct reset_head_opts { > +struct reset_working_tree_options { > /* > * The commit to checkout/reset to. Defaults to HEAD. > */ > @@ -55,6 +55,6 @@ struct reset_head_opts { > const char *default_reflog_action; > }; > > -int reset_head(struct repository *r, const struct reset_head_opts *opts); > +int reset_working_tree(struct repository *r, const struct reset_working_tree_options *opts); > > #endif > diff --git a/sequencer.c b/sequencer.c > index 1ee4b2875b..d73ecf0384 100644 > --- a/sequencer.c > +++ b/sequencer.c > @@ -4677,7 +4677,7 @@ static void create_autostash_internal(struct repository *r, > 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 reset_working_tree_options ropts = { .flags = RESET_HEAD_HARD }; > struct object_id oid; > > strvec_pushl(&stash.args, > @@ -4707,7 +4707,7 @@ static void create_autostash_internal(struct repository *r, > > if (!silent) > printf(_("Created autostash: %s\n"), buf.buf); > - if (reset_head(r, &ropts) < 0) > + if (reset_working_tree(r, &ropts) < 0) > die(_("could not reset --hard")); > discard_index(r->index); > if (repo_read_index(r) < 0) > @@ -4867,7 +4867,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts, > const char *onto_name, const struct object_id *onto, > const struct object_id *orig_head) > { > - struct reset_head_opts ropts = { > + struct reset_working_tree_options ropts = { > .oid = onto, > .orig_head = orig_head, > .flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD | > @@ -4876,7 +4876,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts, > onto_name), > .default_reflog_action = sequencer_reflog_action(opts) > }; > - if (reset_head(r, &ropts)) { > + if (reset_working_tree(r, &ropts)) { > apply_autostash(rebase_path_autostash()); > sequencer_remove_state(opts); > return error(_("could not detach HEAD")); >