[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.imChanges 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.imChanges 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.imChanges 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.imThanks!
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 recursionbuiltin/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