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

[PATCH v3 3/6] worktree: refactor code to use available repositories

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 16, 2026, 05:33 UTC
Message-ID
<20260716-pks-refs-wo-the-repository-v3-3-db0a804e0224@pks.im>
In-Reply-To
<20260716-pks-refs-wo-the-repository-v3-0-db0a804e0224@pks.im>

In "worktree.c" we have lots of users of `the_repository` that already have a repository available to them. Convert all of them to use that repository instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 worktree.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/worktree.c b/worktree.c
index 30125827fd..8b10dea179 100644
--- a/worktree.c
+++ b/worktree.c
@@ -392,7 +392,7 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
 	if (!is_absolute_path(wt->path)) {
 		strbuf_addf_gently(errmsg,
 				   _("'%s' file does not contain absolute path to the working tree location"),
-				   repo_common_path_replace(the_repository, &buf, "worktrees/%s/gitdir", wt->id));
+				   repo_common_path_replace(wt->repo, &buf, "worktrees/%s/gitdir", wt->id));
 		goto done;
 	}
 
@@ -414,12 +414,12 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
 		goto done;
 	}
 
-	strbuf_realpath(&realpath, repo_common_path_replace(the_repository, &buf, "worktrees/%s", wt->id), 1);
+	strbuf_realpath(&realpath, repo_common_path_replace(wt->repo, &buf, "worktrees/%s", wt->id), 1);
 	ret = fspathcmp(path, realpath.buf);
 
 	if (ret)
 		strbuf_addf_gently(errmsg, _("'%s' does not point back to '%s'"),
-				   wt->path, repo_common_path_replace(the_repository, &buf,
+				   wt->path, repo_common_path_replace(wt->repo, &buf,
 								      "worktrees/%s", wt->id));
 done:
 	free(path);
@@ -440,7 +440,7 @@ void update_worktree_location(struct worktree *wt, const char *path_,
 	if (is_main_worktree(wt))
 		BUG("can't relocate main worktree");
 
-	wt_gitdir = repo_common_path(the_repository, "worktrees/%s/gitdir", wt->id);
+	wt_gitdir = repo_common_path(wt->repo, "worktrees/%s/gitdir", wt->id);
 	strbuf_realpath(&gitdir, wt_gitdir, 1);
 	strbuf_realpath(&path, path_, 1);
 	strbuf_addf(&dotgit, "%s/.git", path.buf);
@@ -658,7 +658,7 @@ static void repair_gitfile(struct worktree *wt,
 		goto done;
 	}
 
-	path = repo_common_path(the_repository, "worktrees/%s", wt->id);
+	path = repo_common_path(wt->repo, "worktrees/%s", wt->id);
 	strbuf_realpath(&repo, path, 1);
 	strbuf_addf(&dotgit, "%s/.git", wt->path);
 	strbuf_addf(&gitdir, "%s/gitdir", repo.buf);
@@ -727,7 +727,7 @@ void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path
 	if (is_main_worktree(wt))
 		goto done;
 
-	path = repo_common_path(the_repository, "worktrees/%s/gitdir", wt->id);
+	path = repo_common_path(wt->repo, "worktrees/%s/gitdir", wt->id);
 	strbuf_realpath(&gitdir, path, 1);
 
 	if (strbuf_read_file(&dotgit, gitdir.buf, 0) < 0)
@@ -1042,7 +1042,7 @@ int init_worktree_config(struct repository *r)
 	 */
 	if (r->repository_format_worktree_config)
 		return 0;
-	if ((res = repo_config_set_gently(the_repository, "extensions.worktreeConfig", "true")))
+	if ((res = repo_config_set_gently(r, "extensions.worktreeConfig", "true")))
 		return error(_("failed to set extensions.worktreeConfig setting"));
 
 	common_config_file = xstrfmt("%s/config", r->commondir);
-- 
2.55.0.313.g8d093f411d.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 32 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.