From: Phillip Wood <phillip.wood123@gmail.com>
To: Patrick Steinhardt <ps@pks.im>, git@vger.kernel.org
Cc: Pablo Sabater <pabloosabaterr@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
Phillip Wood <phillip.wood@dunelm.org.uk>
Subject: Re: [PATCH v4 06/10] reset: introduce ability to skip updating HEAD
Date: Wed, 10 Jun 2026 14:11:04 +0100 [thread overview]
Message-ID: <cfade236-75bc-4679-a74a-6da82e6a5135@gmail.com> (raw)
In-Reply-To: <20260610-b4-pks-history-drop-v4-6-70d5f0ae8c25@pks.im>
Hi Patrick
On 10/06/2026 09:52, Patrick Steinhardt wrote:
> In a subsequent commit we'll introduce a new caller to
> `reset_working_tree()` that really only wants to update the index and
> working tree, without updating any references. Introduce a new flag that
> makes the caller opt in to updating HEAD and adapt all callers to set
> that flag.
>
> Note that in a previous iteration we instead introduced a flag that made
> callers opt out of updating any references. This was somewhat awkward
> though because we already have the `UPDATE_ORIG_HEAD` flag, so the
> result was somewhat inconsistent.
Thanks for doing this. I've grepped for all the callers of reset_head()
to confirm this patch adds RESET_HEAD_UPDATE_HEAD to them all.
I wonder if we should add a check for passing
RESET_HEAD_UPDATE_ORIG_HEAD without RESET_HEAD_UPDATE_HEAD that calls
BUG() as we don't support that. Everything else looks good.
Thanks
Phillip
> Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> builtin/rebase.c | 14 ++++++++++----
> reset.c | 6 ++++--
> reset.h | 9 ++++++---
> sequencer.c | 4 +++-
> 4 files changed, 23 insertions(+), 10 deletions(-)
>
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index 06dcbaf5e8..10a306310c 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -607,7 +607,8 @@ static int move_to_original_branch(struct rebase_options *opts)
> strbuf_addf(&head_reflog, "%s (finish): returning to %s",
> opts->reflog_action, opts->head_name);
> ropts.branch = opts->head_name;
> - ropts.flags = RESET_WORKING_TREE_REFS_ONLY;
> + ropts.flags = RESET_WORKING_TREE_REFS_ONLY |
> + RESET_WORKING_TREE_UPDATE_HEAD;
> ropts.branch_msg = branch_reflog.buf;
> ropts.head_msg = head_reflog.buf;
> ret = reset_working_tree(the_repository, &ropts);
> @@ -693,6 +694,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;
> + ropts.flags = RESET_WORKING_TREE_UPDATE_HEAD;
> reset_working_tree(the_repository, &ropts);
> error(_("\ngit encountered an error while preparing the "
> "patches to replay\n"
> @@ -862,7 +864,8 @@ static int checkout_up_to_date(struct rebase_options *options)
> options->reflog_action, options->switch_to);
> ropts.oid = &options->orig_head->object.oid;
> ropts.branch = options->head_name;
> - ropts.flags = RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;
> + ropts.flags = RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK |
> + RESET_WORKING_TREE_UPDATE_HEAD;
> if (!ropts.branch)
> ropts.flags |= RESET_WORKING_TREE_DETACH;
> ropts.head_msg = buf.buf;
> @@ -1384,7 +1387,8 @@ int cmd_rebase(int argc,
>
> rerere_clear(the_repository, &merge_rr);
> string_list_clear(&merge_rr, 1);
> - ropts.flags = RESET_WORKING_TREE_HARD;
> + ropts.flags = RESET_WORKING_TREE_HARD |
> + RESET_WORKING_TREE_UPDATE_HEAD;
> if (reset_working_tree(the_repository, &ropts) < 0)
> die(_("could not discard worktree changes"));
> remove_branch_state(the_repository, 0);
> @@ -1409,7 +1413,8 @@ int cmd_rebase(int argc,
> ropts.oid = &options.orig_head->object.oid;
> ropts.head_msg = head_msg.buf;
> ropts.branch = options.head_name;
> - ropts.flags = RESET_WORKING_TREE_HARD;
> + ropts.flags = RESET_WORKING_TREE_HARD |
> + RESET_WORKING_TREE_UPDATE_HEAD;
> if (reset_working_tree(the_repository, &ropts) < 0)
> die(_("could not move back to %s"),
> oid_to_hex(&options.orig_head->object.oid));
> @@ -1877,6 +1882,7 @@ int cmd_rebase(int argc,
> ropts.oid = &options.onto->object.oid;
> ropts.orig_head = &options.orig_head->object.oid;
> ropts.flags = RESET_WORKING_TREE_DETACH |
> + RESET_WORKING_TREE_UPDATE_HEAD |
> RESET_WORKING_TREE_UPDATE_ORIG_HEAD |
> RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK;
> ropts.head_msg = msg.buf;
> diff --git a/reset.c b/reset.c
> index 99f2c1b012..3ac99a51c0 100644
> --- a/reset.c
> +++ b/reset.c
> @@ -92,6 +92,7 @@ int reset_working_tree(struct repository *r,
> const char *switch_to_branch = opts->branch;
> unsigned reset_hard = opts->flags & RESET_WORKING_TREE_HARD;
> unsigned refs_only = opts->flags & RESET_WORKING_TREE_REFS_ONLY;
> + unsigned update_head = opts->flags & RESET_WORKING_TREE_UPDATE_HEAD;
> unsigned update_orig_head = opts->flags & RESET_WORKING_TREE_UPDATE_ORIG_HEAD;
> unsigned dry_run = opts->flags & RESET_WORKING_TREE_DRY_RUN;
> struct object_id *head = NULL, head_oid;
> @@ -129,7 +130,7 @@ int reset_working_tree(struct repository *r,
> oid = &head_oid;
>
> if (refs_only) {
> - if (!dry_run)
> + if (update_head)
> return update_refs(r, opts, oid, head);
> return 0;
> }
> @@ -197,7 +198,8 @@ int reset_working_tree(struct repository *r,
> goto leave_reset_head;
> }
>
> - if (oid != &head_oid || update_orig_head || switch_to_branch)
> + if (update_head &&
> + (oid != &head_oid || update_orig_head || switch_to_branch))
> ret = update_refs(r, opts, oid, head);
>
> leave_reset_head:
> diff --git a/reset.h b/reset.h
> index 898e4a1e95..38b2891b53 100644
> --- a/reset.h
> +++ b/reset.h
> @@ -19,14 +19,17 @@ enum reset_working_tree_flags {
> /* Only update refs, do not touch the worktree */
> RESET_WORKING_TREE_REFS_ONLY = (1 << 3),
>
> - /* Update ORIG_HEAD as well as HEAD */
> - RESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 4),
> + /* Update HEAD */
> + RESET_WORKING_TREE_UPDATE_HEAD = (1 << 4),
> +
> + /* Update ORIG_HEAD */
> + RESET_WORKING_TREE_UPDATE_ORIG_HEAD = (1 << 5),
>
> /*
> * Perform a dry-run by performing the operation without updating
> * any user-visible state.
> */
> - RESET_WORKING_TREE_DRY_RUN = (1 << 5),
> + RESET_WORKING_TREE_DRY_RUN = (1 << 6),
> };
>
> struct reset_working_tree_options {
> diff --git a/sequencer.c b/sequencer.c
> index 4efe831178..e905b1b2d9 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -4678,7 +4678,8 @@ static void create_autostash_internal(struct repository *r,
> has_uncommitted_changes(r, 1)) {
> struct child_process stash = CHILD_PROCESS_INIT;
> struct reset_working_tree_options ropts = {
> - .flags = RESET_WORKING_TREE_HARD,
> + .flags = RESET_WORKING_TREE_HARD |
> + RESET_WORKING_TREE_UPDATE_HEAD,
> };
> struct object_id oid;
>
> @@ -4873,6 +4874,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,
> .oid = onto,
> .orig_head = orig_head,
> .flags = RESET_WORKING_TREE_DETACH |
> + RESET_WORKING_TREE_UPDATE_HEAD |
> RESET_WORKING_TREE_UPDATE_ORIG_HEAD |
> RESET_WORKING_TREE_RUN_POST_CHECKOUT_HOOK,
> .head_msg = reflog_message(opts, "start", "checkout %s",
>
next prev parent reply other threads:[~2026-06-10 13:11 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-01 15:36 [PATCH 0/2] builtin/history: introduce "drop" subcommand Patrick Steinhardt
2026-06-01 15:36 ` [PATCH 1/2] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-01 15:36 ` [PATCH 2/2] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-01 23:43 ` Junio C Hamano
2026-06-03 10:06 ` Patrick Steinhardt
2026-06-02 7:31 ` Pablo Sabater
2026-06-03 10:06 ` Patrick Steinhardt
2026-06-03 16:13 ` [PATCH v2 0/9] builtin/history: introduce " Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 1/9] read-cache: split out function to drop unmerged entries to stage 0 Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 2/9] reset: drop `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 3/9] reset: modernize flags passed to `reset_head()` Patrick Steinhardt
2026-06-03 18:01 ` Kristoffer Haugsbakk
2026-06-05 15:08 ` Phillip Wood
2026-06-08 9:14 ` Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 4/9] reset: introduce dry-run mode Patrick Steinhardt
2026-06-03 18:18 ` Kristoffer Haugsbakk
2026-06-03 23:49 ` Junio C Hamano
2026-06-03 16:14 ` [PATCH v2 5/9] reset: introduce ability to skip reference updates Patrick Steinhardt
2026-06-03 23:51 ` Junio C Hamano
2026-06-04 9:01 ` Patrick Steinhardt
2026-06-05 15:12 ` Phillip Wood
2026-06-08 9:14 ` Patrick Steinhardt
2026-06-08 9:18 ` Patrick Steinhardt
2026-06-09 10:03 ` Phillip Wood
2026-06-10 7:31 ` Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 6/9] reset: allow the caller to specify the current HEAD object Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 7/9] reset: stop assuming that the caller passes in a clean index Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 8/9] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-03 16:14 ` [PATCH v2 9/9] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-03 19:04 ` Kristoffer Haugsbakk
2026-06-04 9:02 ` Patrick Steinhardt
2026-06-03 23:58 ` Junio C Hamano
2026-06-04 9:02 ` Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 0/9] builtin/history: introduce " Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 1/9] read-cache: split out function to drop unmerged entries to stage 0 Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 2/9] reset: drop `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 3/9] reset: modernize flags passed to `reset_head()` Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 4/9] reset: introduce dry-run mode Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 5/9] reset: introduce ability to skip reference updates Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 6/9] reset: allow the caller to specify the current HEAD object Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 7/9] reset: stop assuming that the caller passes in a clean index Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 8/9] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-08 10:23 ` [PATCH v3 9/9] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-10 8:52 ` [PATCH v4 00/10] builtin/history: introduce " Patrick Steinhardt
2026-06-10 8:52 ` [PATCH v4 01/10] read-cache: split out function to drop unmerged entries to stage 0 Patrick Steinhardt
2026-06-10 8:52 ` [PATCH v4 02/10] reset: drop `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2026-06-10 8:52 ` [PATCH v4 03/10] reset: rename `reset_head()` Patrick Steinhardt
2026-06-10 13:10 ` Phillip Wood
2026-06-10 8:52 ` [PATCH v4 04/10] reset: modernize flags passed to `reset_working_tree()` Patrick Steinhardt
2026-06-10 13:10 ` Phillip Wood
2026-06-10 8:52 ` [PATCH v4 05/10] reset: introduce dry-run mode Patrick Steinhardt
2026-06-10 8:52 ` [PATCH v4 06/10] reset: introduce ability to skip updating HEAD Patrick Steinhardt
2026-06-10 13:11 ` Phillip Wood [this message]
2026-06-10 8:52 ` [PATCH v4 07/10] reset: allow the caller to specify the current HEAD object Patrick Steinhardt
2026-06-10 8:52 ` [PATCH v4 08/10] reset: stop assuming that the caller passes in a clean index Patrick Steinhardt
2026-06-10 8:52 ` [PATCH v4 09/10] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-10 16:25 ` Junio C Hamano
2026-06-10 8:52 ` [PATCH v4 10/10] builtin/history: implement "drop" subcommand Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cfade236-75bc-4679-a74a-6da82e6a5135@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kristofferhaugsbakk@fastmail.com \
--cc=pabloosabaterr@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox