git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 17:29 UTC

Re: [PATCH 1/1] Add preparing state to reference-transaction hook

From
Peijian Ju <eric.peijian@gmail.com>
Date
Mar 16, 2026, 03:09 UTC
Message-ID
<CAN2LT1D+_JRz4uknimQw0Fw559gxAwSJvhjfqGNZbZCwG6oNkg@mail.gmail.com>
In-Reply-To
<xmqqpl572zq2.fsf@gitster.g>
On Fri, Mar 13, 2026 at 5:20 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
>
> eric.peijian@gmail.com writes:
>
> > From: Eric Ju <eric.peijian@gmail.com>
> >
> > From: Eric Ju <eju@gitlab.com>
>
> This is curious.  The former matches the sign-off, but I somehow
> suspect that the @gitlab.com identity may be what you want to use
> for both of them, if this is a company sponsored work by an
> employee?  I dunno.
>

Thank you for pointing this out. During internal review, I used eju@gitlab.com, but I intended to use eric.peijian@gmail.com for the mailing list submission. The two `From:` lines got out of sync as a result. Fixed.

Show 7 quoted lines
> Also the commit title deviates from the established "<area>: <what
> is done>" format.
>
>     Subject: [PATCH] refs: add 'preparing" phase to the transaction hook
>
> or something?
>
Thank you. Fixed.
> Other than that, both the cover letter and the proposed log message
> very well explain the motivation behind the new feature.  I wish
> everybody wrote their log messages as clearly as this one.
>

Thank you. Much of the credit goes to Patrick (ps@pks.im), who helped shape the log message.

Show 11 quoted lines
> > The "reference-transaction" hook is invoked multiple times during a ref
> > transaction. Each invocation corresponds to a different phase:
> >
> > - The "prepared" phase indicates that references have been locked.
> > - The "commit" phase indicates that all updates have been written to disk.
> > - The "abort" phase indicates that the transaction has been aborted and that
> >   all changes have been rolled back.
>
> "commit" -> "committed" and "abort" -> "aborted", if the existing
> documentation is to be trusted.
>
Thank you. Fixed.
Show 20 quoted lines
> > This hook can be used to learn about the updates that Git wants to perform.
> > For example, forges use it to coordinate reference updates across multiple
> > nodes.
> >
> > However, the phases are insufficient for some specific use cases. The earliest
> > observable phase in the "reference-transaction" hook is "prepared", at which
> > point Git has already taken exclusive locks on every affected reference. This
> > makes it suitable for last-chance validation, but not for serialization. So by
> > the time a hook sees the "prepared" phase, it has no way to defer locking, and
> > thus it cannot rearrange multiple concurrent ref transactions relative to one
> > another.
>
> I cannot quite picture how "rearrangement" would happen, though.
>
> Would the hook notice "ah there is a preparing hook invocation
> incoming", stall the caller by not immediately returning and instead
> wait for a different Git process to invoke the same ref-transaction
> hook "preparing" invocation, and somehow decide to let the latter go
> first before releasing the former?
>

Thank you for asking, happy to clarify. The intended use case is serializing concurrent write calls in Gitaly/Praefect. When the hook fires in the "preparing" state, the hook handler contacts Praefect asking "can I proceed with these ref updates?" Praefect coordinates across multiple concurrent hook callbacks and uses this window to determine ordering: if all callers vote for the same write, they are allowed to proceed; other write requests are held or aborted until the current one completes.

Show 11 quoted lines
> > Introduce a new "preparing" phase that runs before the "prepared" phase, that
> > is before Git acquires any reference lock on disk. This gives callers a
> > well-defined window to perform validation, enable higher-level ordering of
> > concurrent transactions, or reject the transaction entirely, all without
> > interfering with the locking state.
> >
> > This change is strictly speaking not backwards compatible. Existing hook
> > scripts that do not know to handle unknown phases handle the "preparing" state
>
> "know to handle unknown phrases handle"?
>
Fixed.
Show 17 quoted lines
> > string will encounter an unknown phase, and that might cause them to return an
> > error now. But the hook is considered to expose internal implementation details
> > of how Git works, and as such we have been a bit more lenient with changing its
> > exact semantics, like for example in a8ae923f85 (refs: support symrefs in
> > 'reference-transaction' hook, 2024-05-07).
> >
> > An alternative would be to introduce a "reference-transaction-v2" hook that
> > knows about the new phase. This feels like a rather heavy-weight option though,
> > and was thus discarded.
>
> And documenting the design alternatives and decision like these two
> paragraphs is very much appreciated.
>
> The insertion of a new hook invocation itself is at a very much
> expected place in the code path.  Well written.
>
> Will queue.  Thanks.
Thank you.
- Eric
Previous: Junio C HamanoNext: Peijian Ju
Message 6 of 15 in “Add "preparing" phase to reference-transaction hook”
  1. 0/1 Add "preparing" phase to reference-transaction hookeric.peijian@gmail.com, Mar 13, 2026
  2. 1/1 Add preparing state to reference-transaction hookeric.peijian@gmail.com, Mar 13, 2026
  3. Junio C HamanoMar 13, 2026
  4. Justin ToblerMar 13, 2026
  5. Junio C HamanoMar 13, 2026
  6. Peijian JuMar 16, 2026
  7. Peijian JuMar 16, 2026
  8. 0/1 refs: add 'preparing' phase to the reference-transaction hookEric Ju, Mar 16, 2026
  9. 1/1 refs: add 'preparing' phase to the reference-transaction hookEric Ju, Mar 16, 2026
  10. Patrick SteinhardtMar 16, 2026
  11. Junio C HamanoMar 16, 2026
  12. Peijian JuMar 16, 2026
  13. Peijian JuMar 16, 2026
  14. 0/1 refs: add 'preparing' phase to the reference-transaction hookEric Ju, Mar 17, 2026
  15. 1/1 refs: add 'preparing' phase to the reference-transaction hookEric Ju, Mar 17, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.