From: Patrick Steinhardt Date: Thu, 11 Jun 2026 06:44:38 GMT Subject: [PATCH v2 0/7] setup: drop global state Message-ID: <20260611-b4-pks-setup-drop-global-state-v2-0-a6f7269c841d@pks.im> In-Reply-To: <20260610-b4-pks-setup-drop-global-state-v1-0-5dff3eec8f06@pks.im> Hi, this patch series continues to refactor "setup.c", where the focus is to drop remaining global state that we have in "setup.c". The most important consequence of this is that we don't need to rely on `the_repository` in `is_bare_repository()` anymore. 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: - Improve documentation for some aspects of `check_repository_format_gently()`. - Link to v1: https://patch.msgid.link/20260610-b4-pks-setup-drop-global-state-v1-0-5dff3eec8f06@pks.im Thanks! Patrick --- Patrick Steinhardt (7): builtin/init: stop modifying global `git_work_tree_cfg` variable builtin/init: simplify logic to configure worktree setup: remove global `git_work_tree_cfg` variable builtin/init: stop modifying `is_bare_repository_cfg` environment: split up concerns of `is_bare_repository_cfg` environment: stop using `the_repository` in `is_bare_repository()` treewide: drop USE_THE_REPOSITORY_VARIABLE attr.c | 4 ++-- builtin/bisect.c | 2 +- builtin/blame.c | 2 +- builtin/check-attr.c | 2 +- builtin/fetch.c | 2 +- builtin/gc.c | 2 +- builtin/history.c | 2 +- builtin/init-db.c | 44 +++++++++++++++++++++++++----------------- builtin/repack.c | 3 +-- builtin/repo.c | 2 +- builtin/reset.c | 2 +- builtin/rev-parse.c | 2 +- environment.c | 10 +++------- environment.h | 6 ++---- git.c | 2 +- mailmap.c | 6 ++---- refs/files-backend.c | 2 +- refs/reftable-backend.c | 4 +--- repository.c | 1 + repository.h | 7 +++++++ setup.c | 51 +++++++++++++++++++++++++++++-------------------- setup.h | 6 ++++++ transport.c | 4 ++-- worktree.c | 4 ++-- 24 files changed, 97 insertions(+), 75 deletions(-) Range-diff versus v1: 1: 0281a4bca9 = 1: 96b71f5223 builtin/init: stop modifying global `git_work_tree_cfg` variable 2: 6fdc8d77e8 = 2: a51c0ff79d builtin/init: simplify logic to configure worktree 3: ce31595ff5 ! 3: e06393ddc5 setup: remove global `git_work_tree_cfg` variable @@ Commit message Refactor the code so that we instead use the worktree configuration as discovered via the repository format. Drop the global variable. + Note that in `check_repository_format_gently()` we now have to free the + candidate work tree variable. This change is required to retain previous + semantics: before we essentially had an implicit `else` branch where we + set `git_work_tree_cfg = NULL`, but we were able to elide that branch + because we already knew that it would be `NULL` anyway. Now that we use + the candidate work tree directly to populate the repository's work tree + though we have to clear it to retain those semantics. + Signed-off-by: Patrick Steinhardt ## setup.c ## 4: 6a69dc853c = 4: 628ed54c8c builtin/init: stop modifying `is_bare_repository_cfg` 5: afa2d8bbda ! 5: 02ceaf4a20 environment: split up concerns of `is_bare_repository_cfg` @@ setup.c: static int check_repository_format_gently(const char *gitdir, + * dictate bareness; it is inherited from the main worktree. + */ + candidate->is_bare = -1; ++ ++ /* ++ * Furthermore, "core.worktree" is supposed to be ignored when ++ * we have a commondir configured, unless it comes from the ++ * per-worktree configuration. ++ */ FREE_AND_NULL(candidate->work_tree); } 6: 04849a2cb5 = 6: a08aef5685 environment: stop using `the_repository` in `is_bare_repository()` 7: 78191c7557 = 7: f93f6599df treewide: drop USE_THE_REPOSITORY_VARIABLE --- base-commit: f5a08a09a0fdf0fc2a355eba7979e2cfd65659e5 change-id: 20260422-b4-pks-setup-drop-global-state-6b1374aed5db