[PATCH v3 0/8] refs: stop using `chdir_notify_reparent()`
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jun 18, 2026, 06:54 UTC
- Message-ID
- <20260618-b4-pks-refs-avoid-chdir-notify-reparent-v3-0-2a5669e8f486@pks.im>
- In-Reply-To
- <20260610-b4-pks-refs-avoid-chdir-notify-reparent-v1-0-56c864b01c43@pks.im>
Hi,
this patch series is a follow-up of the discussion at [1]. It converts the reference backends to always use absolute paths internally, which then allows us to drop the calls to `chdir_notify_reparent()`.
Unfortunately, the series has grown quite a bit larger than anticipated. This is due to a couple of weirdnesses in how the reference database is constructed with an "onbranch" condition. We essentially construct the refdb twice and loose one, but we never noticed because the chdir notification subsystem kept the pointer to it reachable.
Note that the first couple patches that touch "setup.c" aren't strictly required. They are a remnant of a previous iteration where I tried to solve the issue in a different way. But I ultimately figured that these changes are worth it by themselves as they simplify "setup.c" a bit.
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 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 (8):
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: fix recursing `get_main_ref_store()` with "onbranch" config
refs: drop local buffer in `refs_compute_filesystem_location()`chdir-notify.c | 26 -------------- chdir-notify.h | 6 +--- refs.c | 28 ++++++++++----- refs/files-backend.c | 22 ++++++++++-- refs/packed-backend.c | 16 ++++++++- refs/reftable-backend.c | 16 ++++++++- repository.c | 5 +++ setup.c | 95 +++++++++++++++++++------------------------------ 8 files changed, 112 insertions(+), 102 deletions(-)
Range-diff versus v2:
1: ea89bedaa2 = 1: 2be38c1e02 setup: inline `check_and_apply_repository_format()`
2: b87f1db13b = 2: 7fdcd81bb7 setup: stop applying repository format twice
3: f72a8dc251 ! 3: 2162480668 setup: don't apply "GIT_REFERENCE_BACKEND" without a repository
@@ setup.c: const char *setup_git_directory_gently(struct repository *repo, int *no
/*
@@ setup.c: const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
- startup_info->have_repository ||
- /* GIT_DIR_EXPLICIT */
- getenv(GIT_DIR_ENVIRONMENT)) {
-+ const char *ref_backend_uri;
-+
- if (!repo->gitdir) {
- const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
- if (!gitdir)
-@@ setup.c: const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
- setup_git_env_internal(repo, gitdir);
- }
-+ /*
-+ * The env variable should override the repository config
-+ * for 'extensions.refStorage'.
-+ */
-+ ref_backend_uri = getenv(GIT_REFERENCE_BACKEND_ENVIRONMENT);
-+ if (ref_backend_uri) {
-+ char *format;
+ if (startup_info->have_repository) {
+ struct strbuf err = STRBUF_INIT;
++ const char *ref_backend_uri;
+
-+ free(repo_fmt.ref_storage_payload);
++ /*
++ * The env variable should override the repository config
++ * for 'extensions.refStorage'.
++ */
++ ref_backend_uri = getenv(GIT_REFERENCE_BACKEND_ENVIRONMENT);
++ if (ref_backend_uri) {
++ char *format;
+
-+ parse_reference_uri(ref_backend_uri, &format, &repo_fmt.ref_storage_payload);
-+ repo_fmt.ref_storage_format = ref_storage_format_by_name(format);
-+ if (repo_fmt.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
-+ die(_("unknown ref storage format: '%s'"), format);
++ free(repo_fmt.ref_storage_payload);
+
-+ free(format);
-+ }
++ parse_reference_uri(ref_backend_uri, &format, &repo_fmt.ref_storage_payload);
++ repo_fmt.ref_storage_format = ref_storage_format_by_name(format);
++ if (repo_fmt.ref_storage_format == REF_STORAGE_FORMAT_UNKNOWN)
++ die(_("unknown ref storage format: '%s'"), format);
+
- if (startup_info->have_repository) {
- struct strbuf err = STRBUF_INIT;
++ free(format);
++ }
+ if (apply_repository_format(repo, &repo_fmt,
+ APPLY_REPOSITORY_FORMAT_HONOR_ENV, &err) < 0)
@@ setup.c: const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
setenv(GIT_PREFIX_ENVIRONMENT, "", 1);
}
4: 17bdcdb4c5 ! 4: 14daa680b1 refs: unregister reference stores from "chdir_notify"
@@ Commit message
Note that this requires us to use `chdir_notify_register()` instead of
`chdir_notify_reparent()`, as there is no infrastructure to unregister the
- latter. It ultimately doesn't matter much though: in a subsequent commit
- we'll drop this infrastructure completely. We merely require this step
- here so that we can fix the memory leaks ahead of time.
+ latter.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
5: c2f13a487e = 5: 89fe37ebe1 chdir-notify: drop unused `chdir_notify_reparent()`
6: 730e4caeda = 6: 4a96b70db4 repository: free main reference database
7: 1dda77cd19 = 7: e48fc2d69d refs: fix recursing `get_main_ref_store()` with "onbranch" config
8: 6d969bb023 = 8: 37935d50c8 refs: drop local buffer in `refs_compute_filesystem_location()`--- base-commit: 255322df35357168daefec8523a3cdc849edd6c1 change-id: 20260609-b4-pks-refs-avoid-chdir-notify-reparent-a4eaf1edbcab