From: Patrick Steinhardt Date: Thu, 16 Jul 2026 05:33:01 GMT Subject: [PATCH v3 0/6] refs: remove use of `the_repository` Message-ID: <20260716-pks-refs-wo-the-repository-v3-0-db0a804e0224@pks.im> In-Reply-To: <20260709-pks-refs-wo-the-repository-v1-0-1ad6f27529c9@pks.im> Hi, this patch series refactors the ref subsystem to drop uses of `the_repository`. These patches were part of a discarded attempt to make the initialization of the refdb eager. I guess they make sense by themselves though, so here we go. Note that these patches contain a slight tangent to also adapt "worktree.c". This is one of the subsystems that caused problems with eager refdb initialization because of `has_worktrees()`, so I refactored this subsystem while at it. The series is built on top of f85a7e6620 (Start Git 2.56 cycle, 2026-07-06) with ps/refs-writing-subcommands at 002fe677ca (builtin/refs: add "rename" subcommand, 2026-07-06) merged into it. Despite that, there's a small set of conflicts with "seen" that can be merged like this: diff --cc lib/setup.c index 505e8d7bf2,d31808130b..0000000000 --- a/lib/setup.c +++ b/lib/setup.c @@@ -2822,15 -2847,16 +2848,16 @@@ int init_db(struct repository *repo if (!exist_ok && !stat(real_git_dir, &st)) die(_("%s already exists"), real_git_dir); - set_git_dir(repo, real_git_dir, 1); + apply_and_export_relative_gitdir(repo, real_git_dir, 1); git_dir = repo_get_git_dir(repo); - separate_git_dir(git_dir, original_git_dir); + separate_git_dir(repo, git_dir, original_git_dir); - } - else { - set_git_dir(repo, git_dir, 1); + } else { + apply_and_export_relative_gitdir(repo, git_dir, 1); git_dir = repo_get_git_dir(repo); } - startup_info->have_repository = 1; + + if (worktree) + set_git_work_tree(repo, worktree); /* * Check to see if the repository version is right. diff --git a/lib/refs/files-backend.c b/lib/refs/files-backend.c index f672059333..3ba1b4eac4 100644 --- a/lib/refs/files-backend.c +++ b/lib/refs/files-backend.c @@ -859,7 +859,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs, } else { unable_to_lock_message(ref_file.buf, myerr, err); if (myerr == EEXIST) { - if (repo_ignore_case(the_repository) && + if (repo_ignore_case(refs->base.repo) && transaction_has_case_conflicting_update(transaction, update)) { /* * In case-insensitive filesystems, ensure that conflicts within a @@ -973,7 +973,7 @@ static enum ref_transaction_error lock_raw_ref(struct files_ref_store *refs, * conflicts between 'foo' and 'Foo/bar'. So let's lowercase * the refname. */ - if (repo_ignore_case(the_repository)) { + if (repo_ignore_case(refs->base.repo)) { struct strbuf lower = STRBUF_INIT; strbuf_addstr(&lower, refname); Changes in v3: - Merge the patch that removes `USE_THE_REPOSITORY_VARIABLE` from the "packed" backend into the patch that removes the last use of `the_repository`. - Link to v2: https://patch.msgid.link/20260715-pks-refs-wo-the-repository-v2-0-d00d364f5a3e@pks.im Changes in v2: - Fix default value for "core.packedRefsTimeout". - Link to v1: https://patch.msgid.link/20260709-pks-refs-wo-the-repository-v1-0-1ad6f27529c9@pks.im Thanks! Patrick --- Patrick Steinhardt (6): refs/packed: de-globalize handling of "core.packedRefsTimeout" refs/files: drop `USE_THE_REPOSITORY_VARIABLE` worktree: refactor code to use available repositories worktree: pass repository to file-local functions worktree: pass repository to public functions refs: remove remaining uses of `the_repository` branch.c | 6 +- builtin/branch.c | 16 +++-- builtin/check-ref-format.c | 2 +- builtin/checkout.c | 2 +- builtin/config.c | 2 +- builtin/fsck.c | 6 +- builtin/gc.c | 2 +- builtin/merge.c | 2 +- builtin/notes.c | 2 +- builtin/receive-pack.c | 2 +- builtin/reflog.c | 4 +- builtin/refs.c | 2 +- builtin/worktree.c | 32 +++++---- reachable.c | 4 +- ref-filter.c | 2 +- refs.c | 23 +++---- refs.h | 5 +- refs/files-backend.c | 31 +++++---- refs/packed-backend.c | 20 ++++-- revision.c | 6 +- setup.c | 7 +- submodule.c | 2 +- t/helper/test-ref-store.c | 2 +- worktree.c | 166 +++++++++++++++++++++++++-------------------- worktree.h | 27 +++++--- 25 files changed, 206 insertions(+), 169 deletions(-) Range-diff versus v2: 1: b0f7389eb2 ! 1: 2e2ec63de8 refs/packed: de-globalize handling of "core.packedRefsTimeout" @@ Commit message Fix the issue by moving the value into `struct packed_ref_store` so that it can be parsed per store. + This removes the last callsite that still used `the_repository`, so drop + the `USE_THE_REPOSITORY_VARIABLE` define. + Signed-off-by: Patrick Steinhardt ## refs/packed-backend.c ## +@@ +-#define USE_THE_REPOSITORY_VARIABLE + #define DISABLE_SIGN_COMPARE_WARNINGS + + #include "../git-compat-util.h" @@ refs/packed-backend.c: struct packed_ref_store { * `packed_ref_store`) must not be freed. */ 2: a36af82b03 < -: ---------- refs/packed: drop `USE_THE_REPOSITORY_VARIABLE` 3: 136db475ff = 2: ddba174b0d refs/files: drop `USE_THE_REPOSITORY_VARIABLE` 4: f0c028a2d7 = 3: 69aa7536f6 worktree: refactor code to use available repositories 5: 42df076903 = 4: a75b0b7228 worktree: pass repository to file-local functions 6: 8c7fd80674 = 5: b1a214131d worktree: pass repository to public functions 7: 618fc6497f = 6: 6d83181a30 refs: remove remaining uses of `the_repository` --- base-commit: f035246f779167db3506394141b59472d544af65 change-id: 20260618-pks-refs-wo-the-repository-7e43e29371ac