All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: phillip.wood@dunelm.org.uk
Cc: Aniket Gupta <aniketgupta3001@gmail.com>,
	git@vger.kernel.org, Toon Claes <toon@iotcl.com>,
	Junio C Hamano <gitster@pobox.com>,
	Nikita Bobko <nikita@nbobko.com>
Subject: Re: [PATCH v2] history: refuse to rewrite branches used by other worktrees
Date: Wed, 2 Dec 2026 07:23:14 +0100	[thread overview]
Message-ID: <aw-5UoMbP0WOg25l@pks.im> (raw)
In-Reply-To: <3d2e9653-87ce-48f4-a154-2b5a1a31a84c@gmail.com>

On Tue, Dec 01, 2026 at 04:37:37PM +0000, Phillip Wood wrote:
> Hi Patrick
> 
> On 01/12/2026 13:18, Patrick Steinhardt wrote:
> > 
> > I'm probably missing something, but the way we handle `head_target`
> > seems weird to me. It is getting resolved to whatever we have checked
> > out in the current worktree. But do we even care about whether the
> > currently checked out branch is used anywhere else?
> 
> It's confusing if HEAD gets updated in one worktree because a branch was
> rewritten in a different worktree. That's why we have checks in "git rebase"
> to avoid rewriting branches that are checked out in other worktrees.

Yes, but we resolve `head_target` only for the current worktree, we
don't ever resolve it for any of the other worktrees. That's what's
confusing me. Each worktree has its own HEAD, so we'd need to verify
each of them separately, don't we? After all, rewriting history may
cause us to modify an arbitrary branch, and if such an arbitrary branch
is what HEAD points to in the other worktree then we suffer from the
same problem

> > What I would have expected us to do is that we take the list of pending
> > ref updates that we compute in `handle_reference_updates()` and verify
> > that none of those refs that we're updating is checked out or being
> > rebased/bisected. But as far as I can see, this check here comes before
> > we have even computed those ref updates in the first place.
> 
> We need to do the check before rewriting so that a user running "git history
> reword" does not spend time editing the commit message, only for us to
> refuse to update any refs.

The only point in time where we _need_ to check is when doing the actual
update, because this is where we may end up breaking the user's working
trees. But I agree that we _should_ also check before performing any
rewrites because that's simply a better UX.

> > So we're verifying the pre-rewrite state, not the state after already
> > having performed the history rewrite where the ref updates are now
> > pending. And consequently, I think we don't reject some updates that may
> > happen in worktrees.
> 
> Ideally we'd find all the branches that we want to rewrite, write those to
> "$GIT_DIR/history/ref-updates", then walk all the other worktrees checking
> which branch is checked out, being rebased etc. and read each worktree's
> "$GIT_DIR/history/ref-updates" to see if there is an active "git history"
> command rewriting the same branch. If a branch that we want to rewrite is
> being rewritten by a command running in another worktree we'd remove
> "$GIT_DIR/history/ref-updates" and error out. "git checkout", "git rebase"
> etc. would also check "$GIT_DIR/history/ref-updates" as well. By writing the
> list of refs we want to update before checking if any other worktree is
> updating them and removing the file after we've rewritten them, I think we
> avoid races where two commands started at the same time try and update the
> same branch. I don't think we necessarily need to implement that all at once
> though, the checks added in this patch are a good first step.

We can fully avoid the race by doing the checks when the ref transaction
is prepared though, can't we? Well, with reftables at least its trivial.
With the files backend it's a bit of a different story though,
unfortunately.

Patrick

  reply	other threads:[~2026-12-02  6:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 10:39 [PATCH] history: refuse to rewrite branches used by other worktrees Aniket Gupta
2026-11-23 13:10 ` Phillip Wood
2026-11-23 21:54   ` Aniket Gupta
2026-11-24 10:49     ` Phillip Wood
2026-11-24 14:09       ` Aniket Gupta
2026-11-23 20:14 ` Junio C Hamano
2026-11-23 21:54   ` Aniket Gupta
2026-11-27 17:32 ` [PATCH v2] " Aniket Gupta
2026-11-28  0:12   ` Junio C Hamano
2026-11-28  7:37     ` Aniket Gupta
2026-11-30 11:31   ` Toon Claes
2026-11-30 12:15     ` Aniket Gupta
2026-11-30 14:39     ` Phillip Wood
2026-11-30 17:13       ` Aniket Gupta
2026-11-30 14:49   ` Phillip Wood
2026-11-30 17:13     ` Aniket Gupta
2026-12-01 16:39       ` Phillip Wood
2026-12-01 17:36         ` Aniket Gupta
2026-12-01 13:18   ` Patrick Steinhardt
2026-12-01 16:37     ` Phillip Wood
2026-12-02  6:23       ` Patrick Steinhardt [this message]
2026-12-01 18:11     ` Aniket Gupta

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=aw-5UoMbP0WOg25l@pks.im \
    --to=ps@pks.im \
    --cc=aniketgupta3001@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nikita@nbobko.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=toon@iotcl.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.