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

[PATCH v5 00/11] refs: fix "onbranch" conditions

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 22, 2026, 08:28 UTC
Message-ID
<20260622-b4-pks-refs-avoid-chdir-notify-reparent-v5-0-018475013dbc@pks.im>
In-Reply-To
<20260610-b4-pks-refs-avoid-chdir-notify-reparent-v1-0-56c864b01c43@pks.im>
Hi,

originally, this patch series was a follow-up of the discussion at [1], where it converted the reference backends to always use absolute paths internally so that we could drop the `chdir_notify_reparent()` machinery. But this focus shifted as we discovered that this led to quite a sizeable performance regression.

Instead, the series now focusses on fixing handling of the "onbranch" conditions. As part of the above work I discovered that we recurse when creating the main reference database in case we have "onbranch" conditions, and that recursion caused us to construct an ad-hoc reference store that we essentially discarded. The leak wasn't ever catched though because the store is kept alive by the `chdir_notify` infrastructure.

This is a deeper-running issue though: the reference backends respect some configuration guarded by "onbranch" conditions, but not all of them. This issue is fixed by this series by lazy-loading all configuration so that we don't need to read any configuration when we initialize the reference store. This fixes the recursion and makes us consistently honor those "onbranch" conditions.

This series is built on top of 1ff279f340 (The 13th batch, 2026-06-09) with ps/setup-centralize-odb-creation at 42b9d3dc9d (setup: construct object database in `apply_repository_format()`, 2026-06-04) merged into it.

Changes in v5:
  - Fix the "onbranch" recursion properly: instead of papering over the
    issue, this series now refactors reference store initialization to
    not read any configuration at all anymore. Instead, the config is
    now parsed lazily. This fixes the recursion, but also makes us
    respect configuration guarded by "onbranch" conditions properly.
  - Link to v4: https://patch.msgid.link/20260619-b4-pks-refs-avoid-chdir-notify-reparent-v4-0-a6472be7acc4@pks.im
Changes in v4:
  - Fix the "onbranch" recursion at the root of the problem by
    explicitly disabling the use of the ref store when parsing
    configuration at ref store initialization time.
  - Link to v3: https://patch.msgid.link/20260618-b4-pks-refs-avoid-chdir-notify-reparent-v3-0-2a5669e8f486@pks.im
Changes in v3:
  - Reduce the scope of applying the GIT_REFERENCE_BACKEND environment
    variable even further so that we really only do this when we end up
    applying the reference format.
  - Fix a commit message that still referred to the dropped last commit.
  - Link to v2: https://patch.msgid.link/20260615-b4-pks-refs-avoid-chdir-notify-reparent-v2-0-f4854aa99859@pks.im
Changes in v2:
  - Drop the last patch. This seemingly destroys the whole purpose of
    the patch series, but after Peff's hint that this is actually a
    performance optimization I'm less inclined to drop the chdir_notify
    infra. I still think that the remainder of the patches make sense
    standalone, as they simplify "setup.c" and clean memory leaks. Going
    forward I'd like to investigate the idea of introducing a `struct
    fsroot` infrastructure that uses the platform-equivalent of openat
    et al.
  - Improve a couple of commit messages.
  - Link to v1: https://patch.msgid.link/20260610-b4-pks-refs-avoid-chdir-notify-reparent-v1-0-56c864b01c43@pks.im
Thanks!
Patrick
[1]: <aifAVpxanV31KUpC@pks.im>
---
Patrick Steinhardt (11):
      setup: inline `check_and_apply_repository_format()`
      setup: stop applying repository format twice
      setup: don't apply "GIT_REFERENCE_BACKEND" without a repository
      refs: unregister reference stores from "chdir_notify"
      chdir-notify: drop unused `chdir_notify_reparent()`
      repository: free main reference database
      refs: move parsing of "core.logAllRefUpdates" back into ref stores
      refs/files: lazy-load configuration to fix chicken-and-egg
      reftable: split up write options
      refs/reftable: lazy-load configuration to fix chicken-and-egg
      refs: protect against chicken-and-egg recursion
 builtin/checkout.c                  |   7 +-
 chdir-notify.c                      |  26 -----
 chdir-notify.h                      |   6 +-
 refs.c                              |  17 +++-
 refs.h                              |   9 ++
 refs/files-backend.c                |  69 ++++++++++---
 refs/packed-backend.c               |  16 ++-
 refs/refs-internal.h                |   6 --
 refs/reftable-backend.c             | 177 ++++++++++++++++++++-------------
 reftable/reftable-stack.h           |  30 +++++-
 reftable/reftable-writer.h          |  17 +---
 reftable/stack.c                    | 100 ++++++++++++-------
 reftable/stack.h                    |   2 +-
 reftable/writer.c                   |  21 ++--
 reftable/writer.h                   |   1 +
 repo-settings.c                     |  16 ---
 repo-settings.h                     |   9 --
 repository.c                        |   5 +
 setup.c                             | 102 ++++++++-----------
 t/helper/test-reftable.c            |   2 +-
 t/t0600-reffiles-backend.sh         |  21 ++++
 t/t0613-reftable-write-options.sh   |  19 ++++
 t/t1400-update-ref.sh               |  12 +++
 t/unit-tests/lib-reftable.c         |   8 +-
 t/unit-tests/lib-reftable.h         |   2 +
 t/unit-tests/u-reftable-merged.c    |   9 +-
 t/unit-tests/u-reftable-readwrite.c |  38 ++++++--
 t/unit-tests/u-reftable-stack.c     | 189 ++++++++++++++++--------------------
 t/unit-tests/u-reftable-table.c     |   8 +-
 29 files changed, 555 insertions(+), 389 deletions(-)
Range-diff versus v4:
 1:  a70b0f44b2 =  1:  1a3e7849fb setup: inline `check_and_apply_repository_format()`
 2:  b33b51748b =  2:  9fee5b6ac2 setup: stop applying repository format twice
 3:  a22755337a =  3:  8eeaaa2359 setup: don't apply "GIT_REFERENCE_BACKEND" without a repository
 4:  848645c3e8 =  4:  19f0e381aa refs: unregister reference stores from "chdir_notify"
 5:  489e274577 =  5:  5b1ec8f62a chdir-notify: drop unused `chdir_notify_reparent()`
 6:  a9811da5c8 =  6:  44abab07fa repository: free main reference database
 7:  8de1023c6b =  7:  21d46ff924 refs: move parsing of "core.logAllRefUpdates" back into ref stores
 8:  cb3cf159d2 <  -:  ---------- refs/reftable-backend: manually parse "core.sharedRepository"
 9:  1a7c195c03 <  -:  ---------- refs: fix recursing `get_main_ref_store()` with "onbranch" config
10:  c9b019a1a5 <  -:  ---------- refs: drop local buffer in `refs_compute_filesystem_location()`
 -:  ---------- >  8:  22d65ada3d refs/files: lazy-load configuration to fix chicken-and-egg
 -:  ---------- >  9:  715b090f40 reftable: split up write options
 -:  ---------- > 10:  a941049373 refs/reftable: lazy-load configuration to fix chicken-and-egg
 -:  ---------- > 11:  7ca965fe73 refs: protect against chicken-and-egg recursion

--- base-commit: 255322df35357168daefec8523a3cdc849edd6c1 change-id: 20260609-b4-pks-refs-avoid-chdir-notify-reparent-a4eaf1edbcab

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 69 of 88 in “refs: stop using `chdir_notify_reparent()`”
  1. 0/9 refs: stop using `chdir_notify_reparent()`Patrick Steinhardt, Jun 10, 2026
  2. 1/9 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 10, 2026
  3. 2/9 setup: stop applying repository format twicePatrick Steinhardt, Jun 10, 2026
  4. Karthik NayakJun 12, 2026
  5. Patrick SteinhardtJun 15, 2026
  6. 3/9 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 10, 2026
  7. Junio C HamanoJun 10, 2026
  8. Patrick SteinhardtJun 12, 2026
  9. 4/9 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 10, 2026
  10. Karthik NayakJun 12, 2026
  11. Patrick SteinhardtJun 15, 2026
  12. 5/9 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 10, 2026
  13. 6/9 repository: free main reference databasePatrick Steinhardt, Jun 10, 2026
  14. Karthik NayakJun 12, 2026
  15. 7/9 refs: fix recursing `get_main_ref_store()` with "onbranch" configPatrick Steinhardt, Jun 10, 2026
  16. 8/9 refs: drop local buffer in `refs_compute_filesystem_location()`Patrick Steinhardt, Jun 10, 2026
  17. 9/9 refs: always use absolute paths for reference storesPatrick Steinhardt, Jun 10, 2026
  18. Karthik NayakJun 12, 2026
  19. Patrick SteinhardtJun 15, 2026
  20. Jeff KingJun 11, 2026
  21. Patrick SteinhardtJun 12, 2026
  22. Jeff KingJun 13, 2026
  23. Patrick SteinhardtJun 15, 2026
  24. 0/8 refs: stop using `chdir_notify_reparent()`Patrick Steinhardt, Jun 15, 2026
  25. 1/8 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 15, 2026
  26. 2/8 setup: stop applying repository format twicePatrick Steinhardt, Jun 15, 2026
  27. Justin ToblerJun 17, 2026
  28. 3/8 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 15, 2026
  29. Justin ToblerJun 17, 2026
  30. Patrick SteinhardtJun 18, 2026
  31. 4/8 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 15, 2026
  32. Justin ToblerJun 17, 2026
  33. Justin ToblerJun 17, 2026
  34. Patrick SteinhardtJun 18, 2026
  35. 5/8 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 15, 2026
  36. 6/8 repository: free main reference databasePatrick Steinhardt, Jun 15, 2026
  37. Justin ToblerJun 17, 2026
  38. 7/8 refs: fix recursing `get_main_ref_store()` with "onbranch" configPatrick Steinhardt, Jun 15, 2026
  39. Justin ToblerJun 17, 2026
  40. Patrick SteinhardtJun 18, 2026
  41. Justin ToblerJun 18, 2026
  42. Patrick SteinhardtJun 18, 2026
  43. Justin ToblerJun 18, 2026
  44. Jeff KingJun 18, 2026
  45. Patrick SteinhardtJun 19, 2026
  46. Jeff KingJun 21, 2026
  47. Patrick SteinhardtJun 22, 2026
  48. 8/8 refs: drop local buffer in `refs_compute_filesystem_location()`Patrick Steinhardt, Jun 15, 2026
  49. 0/8 refs: stop using `chdir_notify_reparent()`Patrick Steinhardt, Jun 18, 2026
  50. 1/8 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 18, 2026
  51. 2/8 setup: stop applying repository format twicePatrick Steinhardt, Jun 18, 2026
  52. 3/8 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 18, 2026
  53. 4/8 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 18, 2026
  54. 5/8 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 18, 2026
  55. 6/8 repository: free main reference databasePatrick Steinhardt, Jun 18, 2026
  56. 7/8 refs: fix recursing `get_main_ref_store()` with "onbranch" configPatrick Steinhardt, Jun 18, 2026
  57. 8/8 refs: drop local buffer in `refs_compute_filesystem_location()`Patrick Steinhardt, Jun 18, 2026
  58. 00/10 refs: stop using `chdir_notify_reparent()`Patrick Steinhardt, Jun 19, 2026
  59. 01/10 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 19, 2026
  60. 02/10 setup: stop applying repository format twicePatrick Steinhardt, Jun 19, 2026
  61. 03/10 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 19, 2026
  62. 04/10 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 19, 2026
  63. 05/10 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 19, 2026
  64. 06/10 repository: free main reference databasePatrick Steinhardt, Jun 19, 2026
  65. 07/10 refs: move parsing of "core.logAllRefUpdates" back into ref storesPatrick Steinhardt, Jun 19, 2026
  66. 08/10 refs/reftable-backend: manually parse "core.sharedRepository"Patrick Steinhardt, Jun 19, 2026
  67. 09/10 refs: fix recursing `get_main_ref_store()` with "onbranch" configPatrick Steinhardt, Jun 19, 2026
  68. 10/10 refs: drop local buffer in `refs_compute_filesystem_location()`Patrick Steinhardt, Jun 19, 2026
  69. 00/11 refs: fix "onbranch" conditionsPatrick Steinhardt, Jun 22, 2026
  70. 01/11 setup: inline `check_and_apply_repository_format()`Patrick Steinhardt, Jun 22, 2026
  71. 02/11 setup: stop applying repository format twicePatrick Steinhardt, Jun 22, 2026
  72. 03/11 setup: don't apply "GIT_REFERENCE_BACKEND" without a repositoryPatrick Steinhardt, Jun 22, 2026
  73. 04/11 refs: unregister reference stores from "chdir_notify"Patrick Steinhardt, Jun 22, 2026
  74. 05/11 chdir-notify: drop unused `chdir_notify_reparent()`Patrick Steinhardt, Jun 22, 2026
  75. 06/11 repository: free main reference databasePatrick Steinhardt, Jun 22, 2026
  76. 07/11 refs: move parsing of "core.logAllRefUpdates" back into ref storesPatrick Steinhardt, Jun 22, 2026
  77. Justin ToblerJun 24, 2026
  78. Patrick SteinhardtJun 25, 2026
  79. 08/11 refs/files: lazy-load configuration to fix chicken-and-eggPatrick Steinhardt, Jun 22, 2026
  80. Justin ToblerJun 24, 2026
  81. Patrick SteinhardtJun 25, 2026
  82. 09/11 reftable: split up write optionsPatrick Steinhardt, Jun 22, 2026
  83. Justin ToblerJun 24, 2026
  84. Patrick SteinhardtJun 25, 2026
  85. 10/11 refs/reftable: lazy-load configuration to fix chicken-and-eggPatrick Steinhardt, Jun 22, 2026
  86. Justin ToblerJun 24, 2026
  87. Patrick SteinhardtJun 25, 2026
  88. 11/11 refs: protect against chicken-and-egg recursionPatrick Steinhardt, Jun 22, 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.