worktree: refactor code to use available repositories

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 16, 2026 at 07:33 UTC 28723dad6465d98d15208d2c7692a3b873b03e3b
1 file changed +7 -7
worktree.c
+7 -7
@@ -392,7 +392,7 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
392 if (!is_absolute_path(wt->path)) {
393 strbuf_addf_gently(errmsg,
394 _("'%s' file does not contain absolute path to the working tree location"),
395 - repo_common_path_replace(the_repository, &buf, "worktrees/%s/gitdir", wt->id));
395 + repo_common_path_replace(wt->repo, &buf, "worktrees/%s/gitdir", wt->id));
396 goto done;
397 }
398
@@ -414,12 +414,12 @@ int validate_worktree(const struct worktree *wt, struct strbuf *errmsg,
414 goto done;
415 }
416
417 - strbuf_realpath(&realpath, repo_common_path_replace(the_repository, &buf, "worktrees/%s", wt->id), 1);
417 + strbuf_realpath(&realpath, repo_common_path_replace(wt->repo, &buf, "worktrees/%s", wt->id), 1);
418 ret = fspathcmp(path, realpath.buf);
419
420 if (ret)
421 strbuf_addf_gently(errmsg, _("'%s' does not point back to '%s'"),
422 - wt->path, repo_common_path_replace(the_repository, &buf,
422 + wt->path, repo_common_path_replace(wt->repo, &buf,
423 "worktrees/%s", wt->id));
424 done:
425 free(path);
@@ -440,7 +440,7 @@ void update_worktree_location(struct worktree *wt, const char *path_,
440 if (is_main_worktree(wt))
441 BUG("can't relocate main worktree");
442
443 - wt_gitdir = repo_common_path(the_repository, "worktrees/%s/gitdir", wt->id);
443 + wt_gitdir = repo_common_path(wt->repo, "worktrees/%s/gitdir", wt->id);
444 strbuf_realpath(&gitdir, wt_gitdir, 1);
445 strbuf_realpath(&path, path_, 1);
446 strbuf_addf(&dotgit, "%s/.git", path.buf);
@@ -658,7 +658,7 @@ static void repair_gitfile(struct worktree *wt,
658 goto done;
659 }
660
661 - path = repo_common_path(the_repository, "worktrees/%s", wt->id);
661 + path = repo_common_path(wt->repo, "worktrees/%s", wt->id);
662 strbuf_realpath(&repo, path, 1);
663 strbuf_addf(&dotgit, "%s/.git", wt->path);
664 strbuf_addf(&gitdir, "%s/gitdir", repo.buf);
@@ -727,7 +727,7 @@ void repair_worktree_after_gitdir_move(struct worktree *wt, const char *old_path
727 if (is_main_worktree(wt))
728 goto done;
729
730 - path = repo_common_path(the_repository, "worktrees/%s/gitdir", wt->id);
730 + path = repo_common_path(wt->repo, "worktrees/%s/gitdir", wt->id);
731 strbuf_realpath(&gitdir, path, 1);
732
733 if (strbuf_read_file(&dotgit, gitdir.buf, 0) < 0)
@@ -1042,7 +1042,7 @@ int init_worktree_config(struct repository *r)
1042 */
1043 if (r->repository_format_worktree_config)
1044 return 0;
1045 - if ((res = repo_config_set_gently(the_repository, "extensions.worktreeConfig", "true")))
1045 + if ((res = repo_config_set_gently(r, "extensions.worktreeConfig", "true")))
1046 return error(_("failed to set extensions.worktreeConfig setting"));
1047
1048 common_config_file = xstrfmt("%s/config", r->commondir);