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

Re: [PATCH v2] refs: implement reference transaction hook

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 3, 2020, 18:03 UTC
Message-ID
<xmqq7dworpqy.fsf@gitster.c.googlers.com>
In-Reply-To
<CAFQ2z_OSfsKKkOu_wKEAWi-Zihp4g265jtmXzteaU=BQZohEAQ@mail.gmail.com>
Han-Wen Nienhuys <hanwen@google.com> writes:
Show 6 quoted lines
>> +For each reference update that was added to the transaction, the hook
>> +receives on standard input a line of the format:
>> +
>> +  <old-value> SP <new-value> SP <ref-name> LF
>
> Does this work for symrefs as well? Should it?
That's a good question.

I am assuming that you are asking about updating the value of the underlying ref the symbolic ref points at (i.e. <ref-name> would be "HEAD" and old- and new-value are commits at the tip of the branch that is currently checked out), and not about repointing the symbolic ref to a different underlying ref. I suspect we do not want to. In such a case, we'd have a separate "refs/heads/master moved from old to new" record anyway, so we probably should not even talk about symbolic refs when we report "a ref got updated to point a different object" in the above format.

And obviously the above format cannot talk about repointing HEAD to a different branch (well, it can in a sense that old and new branch both would have some object name that can be filled in the old- and new-value fields, but the record misses the most interesting part of the "branch switching" without the actual old and new refnames), so there must be another format that allows us to report such an event.

    "Sym" SP <old-refname> SP <new-refname> SP <symbolic-ref-name> LF
or something like that, so that
	$ git checkout next
may yield
    "Sym" SP "refs/heads/master" SP "refs/heads/next" SP "HEAD"

if we originally were on the 'master' branch. Obviously we need a way to represent different kinds of transition, like (1) a new symbolic ref has been created, pointing at some underlying ref (which may or may not exist), (2) an existing ref that pointed directly at an object now has become a symbolic ref, (3) a symbolic ref stopped pointing at a ref and now points directly at an object, and (4) a symbolic ref has been removed.

Both (1) and (4) would be a trivial variation of the above format, I guess, using some special token to denote void (say, we'd use an empty string for that):

    "Sym" "" SP <new-refname> SP <symbolic-ref-name> LF
    "Sym" <old-refname> SP "" SP <symbolic-ref-name> LF

(2) and (3) are interesting. We could represent them as two separate operations inside the same transaction, e.g.

    "Sym" "refs/heads/master" SP "" SP "HEAD" LF
    "0{40}" SP "b3d7a52fac39193503a0b6728771d1bf6a161464" SP "HEADD" LF

or we'd need to invent different type of record to represent such "detaching" and "reattaching" events.

    
Previous: Han-Wen NienhuysNext: Patrick Steinhardt
Message 14 of 26 in “refs: implement reference transaction hooks”
  1. refs: implement reference transaction hooksPatrick Steinhardt, Jun 2, 2020
  2. Junio C HamanoJun 2, 2020
  3. Patrick SteinhardtJun 3, 2020
  4. SZEDER GáborJun 7, 2020
  5. Patrick SteinhardtJun 8, 2020
  6. SZEDER GáborJun 2, 2020
  7. Patrick SteinhardtJun 3, 2020
  8. refs: implement reference transaction hookPatrick Steinhardt, Jun 3, 2020
  9. Taylor BlauJun 3, 2020
  10. Patrick SteinhardtJun 4, 2020
  11. Taylor BlauJun 15, 2020
  12. Patrick SteinhardtJun 16, 2020
  13. Han-Wen NienhuysJun 3, 2020
  14. Junio C HamanoJun 3, 2020
  15. refs: implement reference transaction hookPatrick Steinhardt, Jun 18, 2020
  16. Junio C HamanoJun 18, 2020
  17. refs: implement reference transaction hookPatrick Steinhardt, Jun 19, 2020
  18. Jeff KingOct 23, 2020
  19. Junio C HamanoOct 23, 2020
  20. Taylor BlauOct 23, 2020
  21. Taylor BlauOct 23, 2020
  22. Patrick SteinhardtOct 26, 2020
  23. Taylor BlauOct 26, 2020
  24. Jeff KingOct 27, 2020
  25. Patrick SteinhardtOct 28, 2020
  26. Taylor BlauOct 23, 2020

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.