From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org, Pablo Sabater <pabloosabaterr@gmail.com>,
Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
Phillip Wood <phillip.wood@dunelm.org.uk>,
Christian Couder <chriscool@tuxfamily.org>
Subject: Re: [PATCH v7 11/11] builtin/history: implement "drop" subcommand
Date: Mon, 29 Jun 2026 12:49:42 -0700 [thread overview]
Message-ID: <xmqqv7b1unxl.fsf@gitster.g> (raw)
In-Reply-To: <20260629-b4-pks-history-drop-v7-11-6e9392a957d8@pks.im> (Patrick Steinhardt's message of "Mon, 29 Jun 2026 09:34:37 +0200")
Patrick Steinhardt <ps@pks.im> writes:
> +static int find_head_tree_change(struct repository *repo,
> + const struct replay_result *result,
> + struct commit **old_head,
> + struct commit **new_head,
> + bool *changed)
> +{
> + const struct replay_ref_update *head_update = NULL;
> + struct commit *old_head_commit, *new_head_commit;
> + struct tree *old_head_tree, *new_head_tree;
> + const char *head_target;
> + int head_flags;
> +
> + *changed = false;
> +
> + head_target = refs_resolve_ref_unsafe(get_main_ref_store(repo),
> + "HEAD", RESOLVE_REF_NO_RECURSE,
> + NULL, &head_flags);
> + if (!head_target)
> + return error(_("cannot look up HEAD"));
Here head_target would be something like "refs/heads/master", or
whatever the "HEAD" happens to point at.
> + if (!(head_flags & REF_ISSYMREF))
> + head_target = "HEAD";
But if it is not a symref, then it is a detached HEAD. We manually
set it to "HEAD" again. We know head_target was not NULL, so what
did we receive in it from refs_resolve_ref_unsafe() call, before we
overwrite it here?
> + for (size_t i = 0; i < result->updates_nr; i++) {
> + if (!strcmp(result->updates[i].refname, head_target)) {
> + head_update = &result->updates[i];
> + break;
> + }
> + }
We see if we are going to update the currently checked out branch.
The .updates[] array was earlier populated by the caller that called
compute_pending_ref_updates() before it called us.
> + if (!head_update)
> + return 0;
And we return if not. That is a simple and happy case. Otherwise
we'd tell the caller about the updated commit and tree (strictly
speaking that would be redundant, but since we have it already, it
is better to give them to the caller instead of forcing the caller
to unwrap the commit).
> +static int cmd_history_drop(int argc,
> + const char **argv,
> + const char *prefix,
> + struct repository *repo)
> +{
> +...
> + struct option options[] = {
> + OPT_CALLBACK_F(0, "update-refs", &action, "(branches|head)",
> + N_("control which refs should be updated"),
> + PARSE_OPT_NONEG, parse_ref_action),
> ...
> + OPT_END(),
> + };
> ...
> + ret = compute_pending_ref_updates(&revs, action, original, rewritten,
> + empty, &result);
Here we call the function. When action is "--update-refs=head",
doesn't this code in compute_pending_ref_updates() ...
if (action == REF_ACTION_HEAD &&
decoration->type != DECORATION_REF_HEAD)
continue;
... skip any reference name (loaded by load_ref_decorations() lazily
by calling get_name_decoration()) that is not "HEAD", which would
mean we end up not finding any hits in the find_head_tree_change()
function call we make later ...
> + if (ret) {
> + ret = error(_("failed replaying descendants"));
> + goto out;
> + }
> + ...
> + if (!is_bare_repository()) {
> + ret = find_head_tree_change(repo, &result, &old_head,
> + &new_head, &head_moves);
... here?
prev parent reply other threads:[~2026-06-29 19:49 UTC|newest]
Thread overview: 100+ 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
2026-06-11 11:47 ` Patrick Steinhardt
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
2026-06-11 13:27 ` [PATCH v5 00/10] builtin/history: introduce " Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 01/10] read-cache: split out function to drop unmerged entries to stage 0 Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 02/10] reset: drop `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 03/10] reset: rename `reset_head()` Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 04/10] reset: modernize flags passed to `reset_working_tree()` Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 05/10] reset: introduce dry-run mode Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 06/10] reset: introduce ability to skip updating HEAD Patrick Steinhardt
2026-06-11 18:00 ` Junio C Hamano
2026-06-15 12:45 ` Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 07/10] reset: allow the caller to specify the current HEAD object Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 08/10] reset: stop assuming that the caller passes in a clean index Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 09/10] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-11 13:27 ` [PATCH v5 10/10] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 00/10] builtin/history: introduce " Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 01/10] read-cache: split out function to drop unmerged entries to stage 0 Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 02/10] reset: drop `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 03/10] reset: rename `reset_head()` Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 04/10] reset: modernize flags passed to `reset_working_tree()` Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 05/10] reset: introduce dry-run mode Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 06/10] reset: introduce ability to skip updating HEAD Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 07/10] reset: allow the caller to specify the current HEAD object Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 08/10] reset: stop assuming that the caller passes in a clean index Patrick Steinhardt
2026-06-15 13:54 ` [PATCH v6 09/10] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-25 13:37 ` Christian Couder
2026-06-29 7:33 ` Patrick Steinhardt
2026-06-15 13:55 ` [PATCH v6 10/10] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-25 13:51 ` Christian Couder
2026-06-25 20:50 ` Junio C Hamano
2026-06-29 7:34 ` [PATCH v7 00/11] builtin/history: introduce " Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 01/11] read-cache: split out function to drop unmerged entries to stage 0 Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 02/11] reset: drop `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 03/11] reset: rename `reset_head()` Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 04/11] reset: modernize flags passed to `reset_working_tree()` Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 05/11] reset: introduce dry-run mode Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 06/11] reset: introduce ability to skip updating HEAD Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 07/11] reset: allow the caller to specify the current HEAD object Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 08/11] reset: stop assuming that the caller passes in a clean index Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 09/11] replay: expose `replay_result_queue_update()` Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 10/11] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-29 7:34 ` [PATCH v7 11/11] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-29 19:49 ` Junio C Hamano [this message]
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=xmqqv7b1unxl.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--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