[PATCH 0/7] refs: remove use of `the_repository`
From: Patrick Steinhardt <hidden>
Date: 2026-07-09 08:29:26
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
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);
Thanks!
Patrick
---
Patrick Steinhardt (7):
refs/packed: de-globalize handling of "core.packedRefsTimeout"
refs/packed: drop `USE_THE_REPOSITORY_VARIABLE`
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 | 18 +++--
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, 204 insertions(+), 169 deletions(-)
---
base-commit: f035246f779167db3506394141b59472d544af65
change-id: 20260618-pks-refs-wo-the-repository-7e43e29371ac