Git development
 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 12:20:52 +0100	[thread overview]
Message-ID: <aw__FFq_lbwE9iTB@pks.im> (raw)
In-Reply-To: <e526719d-7442-4641-bd1e-10529108efd0@gmail.com>

On Wed, Dec 02, 2026 at 10:59:47AM +0000, Phillip Wood wrote:
> On 02/12/2026 06:23, Patrick Steinhardt wrote:
> > > 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.
> 
> To prepare a ref transaction you need to know the new object id. If we want
> to check we're not going to try and update the same ref as another process
> before we rewrite the commits then we cannot prepare a transaction. If we
> want to handle this entirely in the ref backend (which I agree would be
> ideal) we'd need to be able to say "check this ref points at this object and
> lock it. I'll tell you what to update it to later" before we rewrite the
> commits and then "here are the new values for those refs I asked to to lock,
> please update them now" after we've rewritten the commits.

True, and we know the new object IDs after we have called
`compute_pending_ref_updates()`.

I think ultimately, the discussion boils down to different ways to
perform the validation:

  - The proposed version does pre-flight checks, only, and does not
    verify whether the eventual updates that are actually queued match
    our expectations.

  - In my version, we'd perform cheap pre-flight checks that aren't as
    thorough, but then perform proper validation at the time of
    committing the ref updates.

I think the second version is superior because we validate what we
actually end up writing to the ref store, while still retaining most of
the pre-flight checks. It can thus be done in a (depending on the ref
backend) race-free way and is more thorough overall. I worry that we're
second-guessing what we're about to rewrite, and that introduces a bunch
of complexity that we could probably avoid if we instead were to verify
the ref updates themselves, while at the same time being less thorough.

But maybe I shouldn't let perfect be the enemy of good, because right
now we don't have any checks at all.

Patrick

  reply	other threads:[~2026-12-02 11:20 UTC|newest]

Thread overview: 24+ 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
2026-12-02 10:59         ` Phillip Wood
2026-12-02 11:20           ` 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__FFq_lbwE9iTB@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox