[PATCH v2 0/7] refs: remove use of `the_repository`
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jul 15, 2026, 07:39 UTC
- Message-ID
- <20260715-pks-refs-wo-the-repository-v2-0-d00d364f5a3e@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 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 (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 | 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 v1: 1: e2de4a7ae9 ! 1: 5c9df5ce44 refs/packed: de-globalize handling of "core.packedRefsTimeout" @@ refs/packed-backend.c: int packed_refs_lock(struct ref_store *ref_store, int fla - repo_config_get_int(the_repository, "core.packedrefstimeout", &timeout_value); - timeout_configured = 1; + if (!refs->timeout_configured) { -+ repo_config_get_int(ref_store->repo, "core.packedrefstimeout", &refs->timeout_value); ++ if (repo_config_get_int(ref_store->repo, "core.packedrefstimeout", ++ &refs->timeout_value)) ++ refs->timeout_value = 1000; + refs->timeout_configured = true; } 2: 3c96ed5d22 = 2: 39d91a88ad refs/packed: drop `USE_THE_REPOSITORY_VARIABLE` 3: a724abf676 = 3: 5d3d4c505f refs/files: drop `USE_THE_REPOSITORY_VARIABLE` 4: ce64ae5edd = 4: cff8c31110 worktree: refactor code to use available repositories 5: fa5b6c95e2 = 5: b53b5f67f7 worktree: pass repository to file-local functions 6: 89b0263583 = 6: 0927572842 worktree: pass repository to public functions 7: e4ac64f7c2 = 7: bb3b3b1e80 refs: remove remaining uses of `the_repository` --- base-commit: f035246f779167db3506394141b59472d544af65 change-id: 20260618-pks-refs-wo-the-repository-7e43e29371ac