From: Patrick Steinhardt Date: Thu, 25 Jun 2026 09:19:58 GMT Subject: [PATCH v6 00/11] refs: fix "onbranch" conditions Message-ID: <20260625-b4-pks-refs-avoid-chdir-notify-reparent-v6-0-41fbca3cf5e3@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 v6: - Drop redundant condition when setting the default for "core.logallrefupdates". - Leave breakcrumb for why we lazy-load write options for the "files" backend. - Fix commit message typo. - Link to v5: https://patch.msgid.link/20260622-b4-pks-refs-avoid-chdir-notify-reparent-v5-0-018475013dbc@pks.im 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]: --- 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 | 76 ++++++++++++--- 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 | 101 ++++++++----------- 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, 561 insertions(+), 389 deletions(-) Range-diff versus v5: 1: 27cb4688d9 = 1: 9281850ec4 setup: inline `check_and_apply_repository_format()` 2: f0e9e95c25 = 2: cdd6a01554 setup: stop applying repository format twice 3: b3ecceae2e = 3: 748506f661 setup: don't apply "GIT_REFERENCE_BACKEND" without a repository 4: 8d70b43f8c = 4: 9ffc2e94c6 refs: unregister reference stores from "chdir_notify" 5: 190956a8f6 = 5: 080e7d175f chdir-notify: drop unused `chdir_notify_reparent()` 6: 504a0326c3 = 6: 5a2b973766 repository: free main reference database 7: 2f0ecfd9d9 ! 7: ecdbf37fde refs: move parsing of "core.logAllRefUpdates" back into ref stores @@ setup.c: static int create_default_files(struct repository *repo, + /* allow template config file to override the default */ - if (repo_settings_get_log_all_ref_updates(repo) == LOG_REFS_UNSET) -+ if (repo_config_get_string_tmp(repo, "core.logallrefupdates", &value) || -+ refs_parse_log_all_ref_updates_config(value) == LOG_REFS_UNSET) ++ if (repo_config_get_string_tmp(repo, "core.logallrefupdates", &value)) repo_config_set(repo, "core.logallrefupdates", "true"); + if (needs_work_tree_config(original_git_dir, work_tree)) 8: ea171d971d ! 8: 618df32bb6 refs/files: lazy-load configuration to fix chicken-and-egg @@ refs/files-backend.c: struct files_ref_store { - struct ref_store *packed_ref_store; + ++ /* ++ * Options used when writing references. These are parsed from the ++ * config lazily on first use via `files_ref_store_write_options()` so ++ * that we don't have to access the configuration when initializing the ++ * ref store. Do not access these fields directly, but use the accessor ++ * instead. ++ */ + struct files_ref_store_write_options { + enum log_refs_config log_all_ref_updates; + int prefer_symlink_refs; 9: e3bb0c90ef = 9: 13b14f9394 reftable: split up write options 10: 74b389c2f1 ! 10: ba12b6f164 refs/reftable: lazy-load configuration to fix chicken-and-egg @@ Commit message properly, add a generic test to t1400 that verifies that the user can configure "core.logAllRefUpdates" via an "onbranch" condition. This is mostly a nonsensical thing to do in the first place, but it serves as a - good sanity chekc. + good sanity check. Note that we had to move `should_write_log()` around so that it can access the new `reftable_be_write_options()` function. 11: 0cb5a85167 = 11: 85a675ada9 refs: protect against chicken-and-egg recursion --- base-commit: 255322df35357168daefec8523a3cdc849edd6c1 change-id: 20260609-b4-pks-refs-avoid-chdir-notify-reparent-a4eaf1edbcab