git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH RESEND] refs: Always pass old object name to reftx hook

From
Patrick Steinhardt <ps@pks.im>
Date
Jan 20, 2021, 06:28 UTC
Message-ID
<YAfNcyZ7mj4J69XT@ncase>
In-Reply-To
<xmqq4kjdkgol.fsf@gitster.c.googlers.com>
On Mon, Jan 18, 2021 at 02:45:30PM -0800, Junio C Hamano wrote:
Show 36 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > Inputs of the reference-transaction hook currently depends on the
> > command which is being run. For example if the command `git update-ref
> > $REF $A $B` is executed, it will receive "$B $A $REF" as input, but if
> > the command `git update-ref $REF $A` is executed without providing the
> > old value, then it will receive "0*40 $A $REF" as input. This is due to
> > the fact that we directly write queued transaction updates into the
> > hook's standard input, which will not contain the old object value in
> > case it wasn't provided.
> 
> In effect, the user says "I do not care if this update races with
> somebody else and it is perfectly OK if it overwrites their update"
> by not giving $B.
> 
> > While this behaviour reflects what is happening as part of the
> > repository, it doesn't feel like it is useful. The main intent of the
> > reference-transaction hook is to be able to completely audit all
> > reference updates, no matter where they come from. As such, it makes a
> > lot more sense to always provide actual values instead of what the user
> > wanted. Furthermore, it's impossible for the hook to distinguish whether
> > this is intended to be a branch creation or a branch update without
> > doing additional digging with the current format.
> 
> But shouldn't the transaction hook script be allowed to learn the
> end-user intention and behave differently?  If we replace the
> missing old object before calling the script, wouldn't it lose
> information?
> 
> The above is not an objection posed as two rhetoric questions.  I am
> purely curious why losing information is OK in this case, or why it
> may not be so OK but should still be acceptable because it is lessor
> evil than giving 0{40} to the hooks.
> 
> Even without this change, the current value the hook can learn by
> looking the ref up itself if it really wanted to, no?

I think the biggest problem is that right now, you cannot discern the actual intention of the user because the information provided to the hook is ambiguous in the branch creation case: "$ZERO_OID $NEW_OID $REF" could mean the user intends to create a new branch where it shouldn't have existed previously. BUT it could also mean that the user just doesn't care what the reference previously pointed to.

The user could now try to derive the intention by manually looking up the current state of the reference. But that does feel kind of awkward to me.

To me, having clearly defined semantics ("The script always gets old and new value of the branch regardless of what the user did") is preferable to having ambiguous semantics.

Patrick
Previous: Junio C HamanoNext: Junio C Hamano
Message 10 of 13 in “refs: Always pass old object name to reftx hook”
  1. refs: Always pass old object name to reftx hookPatrick Steinhardt, Nov 4, 2020
  2. Patrick SteinhardtDec 4, 2020
  3. Taylor BlauJan 12, 2021
  4. Patrick SteinhardtJan 13, 2021
  5. Taylor BlauJan 13, 2021
  6. Junio C HamanoJan 13, 2021
  7. Patrick SteinhardtJan 18, 2021
  8. refs: Always pass old object name to reftx hookPatrick Steinhardt, Jan 18, 2021
  9. Junio C HamanoJan 18, 2021
  10. Patrick SteinhardtJan 20, 2021
  11. Junio C HamanoJan 20, 2021
  12. Patrick SteinhardtJan 22, 2021
  13. Junio C HamanoJan 22, 2021

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.