From: Patrick Steinhardt Date: Mon, 15 Jun 2026 13:56:46 GMT Subject: [PATCH v2 0/8] refs: stop using `chdir_notify_reparent()` Message-ID: <20260615-b4-pks-refs-avoid-chdir-notify-reparent-v2-0-f4854aa99859@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 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 (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 | 96 ++++++++++++++++++++----------------------------- 8 files changed, 113 insertions(+), 102 deletions(-) Range-diff versus v1: 1: ef72346c7d = 1: 3902fecdb9 setup: inline `check_and_apply_repository_format()` 2: 157fc098b3 ! 2: 9479ffc370 setup: stop applying repository format twice @@ Commit message When discovering the repository in "setup.c" we apply the final repository format multiple times: - - Once via `repository_format_configure()`, where we configure the - repository format for both `struct repository_format` and `struct - repository`. + - Once via `repository_format_configure()`, where we apply the hash + algorithm and ref storage format to both `struct repository_format` + and `struct repository`. - - And once via `apply_repository_format()`, where we then apply the - `struct repository_format` to the `struct repository` again. + - And once via `apply_repository_format()`, where we apply these two + settings from `struct repository_format` to `struct repository`. - As the format will be applied to the repository when applying the format - it's thus somewhat unnecessary to also apply it to the repository when - adapting the discovered format. The only reason we have to do this is - because we call `repository_format_configure()` after we have already - applied it. + With the current flow both of these are in fact necessary. But this is + only because we call `repository_format_configure()` after we have + called `apply_repository_format()`. Consequently, if we only changed the + repository format in `repository_format_configure()` it would never + propagate to the repository. Refactor the code so that we first configure the repository format before applying it to the repository so that we can stop setting the 3: f1429ae8c9 = 3: 09299c488d setup: don't apply "GIT_REFERENCE_BACKEND" without a repository 4: 4137f0f083 ! 4: dff1bfec7a refs: unregister reference stores from "chdir_notify" @@ Commit message a subsequent commit. Note that this requires us to use `chdir_notify_register()` instead of - `chdir_notify_parent()`, as there is no infrastructure to unregister the + `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. 5: dbda87ab6a = 5: 367806c5ba chdir-notify: drop unused `chdir_notify_reparent()` 6: b1d2f39def = 6: e8eb346876 repository: free main reference database 7: f7f5028a10 = 7: 090f80707c refs: fix recursing `get_main_ref_store()` with "onbranch" config 8: 818c0878f9 = 8: 14b12a8f10 refs: drop local buffer in `refs_compute_filesystem_location()` 9: 7408f9b69f < -: ---------- refs: always use absolute paths for reference stores --- base-commit: 255322df35357168daefec8523a3cdc849edd6c1 change-id: 20260609-b4-pks-refs-avoid-chdir-notify-reparent-a4eaf1edbcab