git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/7] refs: remove use of `the_repository`

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 9, 2026, 08:29 UTC
Message-ID
<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);

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
Next: Patrick Steinhardt
Message 1 of 38 in “refs: remove use of `the_repository`”
  1. 0/7 refs: remove use of `the_repository`Patrick Steinhardt, Jul 9, 2026
  2. 1/7 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 9, 2026
  3. Junio C HamanoJul 9, 2026
  4. Patrick SteinhardtJul 10, 2026
  5. 2/7 refs/packed: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 9, 2026
  6. 3/7 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 9, 2026
  7. 4/7 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 9, 2026
  8. 5/7 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 9, 2026
  9. 6/7 worktree: pass repository to public functionsPatrick Steinhardt, Jul 9, 2026
  10. 7/7 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 9, 2026
  11. Junio C HamanoJul 9, 2026
  12. Patrick SteinhardtJul 10, 2026
  13. Patrick SteinhardtJul 10, 2026
  14. Junio C HamanoJul 10, 2026
  15. Junio C HamanoJul 10, 2026
  16. Junio C HamanoJul 10, 2026
  17. 0/7 refs: remove use of `the_repository`Patrick Steinhardt, Jul 15, 2026
  18. 1/7 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 15, 2026
  19. 2/7 refs/packed: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 15, 2026
  20. Toon ClaesJul 15, 2026
  21. Patrick SteinhardtJul 16, 2026
  22. 3/7 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 15, 2026
  23. 4/7 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 15, 2026
  24. 5/7 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 15, 2026
  25. 6/7 worktree: pass repository to public functionsPatrick Steinhardt, Jul 15, 2026
  26. 7/7 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 15, 2026
  27. Toon ClaesJul 15, 2026
  28. Junio C HamanoJul 15, 2026
  29. 0/6 refs: remove use of `the_repository`Patrick Steinhardt, Jul 16, 2026
  30. 1/6 refs/packed: de-globalize handling of "core.packedRefsTimeout"Patrick Steinhardt, Jul 16, 2026
  31. 2/6 refs/files: drop `USE_THE_REPOSITORY_VARIABLE`Patrick Steinhardt, Jul 16, 2026
  32. 3/6 worktree: refactor code to use available repositoriesPatrick Steinhardt, Jul 16, 2026
  33. 4/6 worktree: pass repository to file-local functionsPatrick Steinhardt, Jul 16, 2026
  34. 5/6 worktree: pass repository to public functionsPatrick Steinhardt, Jul 16, 2026
  35. 6/6 refs: remove remaining uses of `the_repository`Patrick Steinhardt, Jul 16, 2026
  36. Christian CouderJul 16, 2026
  37. Junio C HamanoJul 16, 2026
  38. Toon ClaesJul 16, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.