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

Re: [PATCH v3 2/8] refs: move duplicate refname update check to generic layer

From
Karthik Nayak <karthik.188@gmail.com>
Date
Mar 6, 2025, 09:46 UTC
Message-ID
<CAOLa=ZSW9TaD5_-9oQ97=hZXinZUGAkLOSeyDsg-YrTiOOorvw@mail.gmail.com>
In-Reply-To
<xmqq5xknkup2.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 34 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> Move the tracking of refnames in `affected_refnames` from individual
>> backends into the generic layer in 'refs.c'. This centralizes the
>> duplicate refname detection that was previously handled separately by
>> each backend.
>>
>> Make some changes to accommodate this move:
>>
>>   - Add a `string_list` field `refnames` to `ref_transaction` to contain
>>     all the references in a transaction. This field is updated whenever
>>     a new update is added via `ref_transaction_add_update`, so manual
>>     additions in reference backends are dropped.
>
> The transaction object is the most logical place to keep track of
> what is involved in the transaction.  Nice.
>
>>   - Modify the backends to use this field internally as needed. The
>>     backends need to check if an update for refname already exists when
>>     splitting symrefs or adding an update for 'HEAD'.
>
> The above reads to me as if you are saying that the files backend
> needs to notice that it is updating "HEAD", notice that it is a
> symbolic ref that points at "refs/heads/main", notice that "HEAD"
> and "refs/heads/main" are the two things involved in the
> transaction, and must check if an update is already queued.
>
> But when an update changes a symbolic ref in the sense that the
> underlying ref gets updated through it, the need to update both the
> underlying ref and the symbolic ref is common across backends, isn't
> it?  IOW, shouldn't "splitting symrefs" (which I take to mean "ah,
> we are updating HEAD so we need to update it and at the same time
> update the underlying refs/heads/main, two updates in total") be
> done also at the generic layer?

Yup that is correct, in the files backend, we do this via the 'split_symref_update()' function and in the reftable backend it is directly handled in the 'reftable_be_transaction_prepare()' function.

I don't have a reason for why I didn't undertake that too in this series. Mostly I think I didn't observe it. But it something that can/should be done in the future.

>
> And if that happens at the generic layer, should .refname member
> even be visible to backends?
>

It shouldn't be necessary anymore with that change. I think this is good step in that direction.

Show 15 quoted lines
>>   - In the reftable backend, within `reftable_be_transaction_prepare()`,
>>     move the `string_list_has_string()` check above
>>     `ref_transaction_add_update()`. Since `ref_transaction_add_update()`
>>     automatically adds the refname to `transaction->refnames`,
>>     performing the check after will always return true, so we perform
>>     the check before adding the update.
>
> This change makes perfect tense.  It is the most natural to check
> and modify at the transaction layer the .refnames member, as it
> belongs at the transaction layer after all.
>
>> This helps reduce duplication of functionality between the backends and
>> makes it easier to make changes in a more centralized manner.
>
> Nice.
Previous: Junio C HamanoNext: Karthik Nayak
Message 8 of 59 in “refs: introduce support for partial reference transactions”
  1. 0/8 refs: introduce support for partial reference transactionsKarthik Nayak, Mar 5, 2025
  2. 1/8 refs/files: remove redundant check in split_symref_update()Karthik Nayak, Mar 5, 2025
  3. Junio C HamanoMar 5, 2025
  4. Karthik NayakMar 6, 2025
  5. 3/8 refs/files: remove duplicate duplicates checkKarthik Nayak, Mar 5, 2025
  6. 2/8 refs: move duplicate refname update check to generic layerKarthik Nayak, Mar 5, 2025
  7. Junio C HamanoMar 5, 2025
  8. Karthik NayakMar 6, 2025
  9. 4/8 refs/reftable: extract code from the transaction preparationKarthik Nayak, Mar 5, 2025
  10. 5/8 refs: introduce enum-based transaction error typesKarthik Nayak, Mar 5, 2025
  11. 6/8 refs: implement partial reference transaction supportKarthik Nayak, Mar 5, 2025
  12. Jeff KingMar 7, 2025
  13. Junio C HamanoMar 7, 2025
  14. Junio C HamanoMar 7, 2025
  15. Karthik NayakMar 7, 2025
  16. config.mak.dev: enable -Wunreachable-codeJeff King, Mar 7, 2025
  17. Junio C HamanoMar 7, 2025
  18. Jeff KingMar 8, 2025
  19. Junio C HamanoMar 10, 2025
  20. Jeff KingMar 10, 2025
  21. Junio C HamanoMar 10, 2025
  22. Jeff KingMar 14, 2025
  23. Jeff KingMar 14, 2025
  24. Junio C HamanoMar 14, 2025
  25. Junio C HamanoMar 14, 2025
  26. Patrick SteinhardtMar 14, 2025
  27. Jeff KingMar 14, 2025
  28. Junio C HamanoMar 14, 2025
  29. Junio C HamanoMar 14, 2025
  30. Mike HommeyJun 3, 2025
  31. Junio C HamanoJun 3, 2025
  32. Mike HommeyJun 3, 2025
  33. Mike HommeyJun 3, 2025
  34. 0/3 -Wunreachable-codeJunio C Hamano, Mar 14, 2025
  35. 1/3 config.mak.dev: enable -Wunreachable-codeJunio C Hamano, Mar 14, 2025
  36. 2/3 run-command: use errno to check for sigfillset() errorJunio C Hamano, Mar 14, 2025
  37. Taylor BlauMar 17, 2025
  38. Junio C HamanoMar 17, 2025
  39. Junio C HamanoMar 18, 2025
  40. 3/3 git-compat-util: add NOT_A_CONST macro and use it in atfork_prepare()Junio C Hamano, Mar 14, 2025
  41. Junio C HamanoMar 14, 2025
  42. Jeff KingMar 17, 2025
  43. 0/3 -Wunreachable-codeJunio C Hamano, Mar 17, 2025
  44. 1/3 run-command: use errno to check for sigfillset() errorJunio C Hamano, Mar 17, 2025
  45. 2/3 git-compat-util: add NOT_CONSTANT macro and use it in atfork_prepare()Junio C Hamano, Mar 17, 2025
  46. Jeff KingMar 18, 2025
  47. Junio C HamanoMar 18, 2025
  48. Calvin WanMar 18, 2025
  49. Calvin WanMar 18, 2025
  50. Junio C HamanoMar 18, 2025
  51. 3/3 config.mak.dev: enable -Wunreachable-codeJunio C Hamano, Mar 17, 2025
  52. Jeff KingMar 18, 2025
  53. Karthik NayakMar 7, 2025
  54. Jeff KingMar 7, 2025
  55. Karthik NayakMar 7, 2025
  56. 7/8 refs: support partial update rejections during F/D checksKarthik Nayak, Mar 5, 2025
  57. 8/8 update-ref: add --allow-partial flag for stdin modeKarthik Nayak, Mar 5, 2025
  58. Junio C HamanoMar 5, 2025
  59. Karthik NayakMar 6, 2025

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.