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

Re: [PATCH 1/2] wt-status: avoid passing NULL worktree

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 17, 2026, 18:47 UTC
Message-ID
<xmqqa4x7cile.fsf@gitster.g>
In-Reply-To
<409871a7d521b76c9eb811d3c49747e04de8defc.1771258688.git.phillip.wood@dunelm.org.uk>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 6 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> In preparation for removing the repository argument from
> worktree_git_path() add a function to construct a "struct worktree"
> from a "struct repository" and use that to avoid passing a NULL
> worktree to wt_status_check_bisect() and wt_status_check_rebase().
Hmph, I am afraid that
    "Construct a struct worktree from a struct repository"

is not quite sufficient. A repository can have more than one worktrees, so if you give a repository as a parameter, there needs a way for the implementation of this helper function to identify which one of them to construct a struct worktree for, and more importantly for you as the caller to be able to expect which one the implementation would pick, and what that particular worktree among many _means_ to you.

I know that the implementation uses repo->worktree but what does that path mean in the world-view of the worktree API set?

I am guessing that it is what the worktree API calls "current", but if so, perhaps the function should be explained with that word in it, and the function name should also contain that word, no?

Show 9 quoted lines
> +struct worktree *get_worktree_from_repository(struct repository *repo)
> +{
> +	struct worktree *wt = xcalloc(1, sizeof(*wt));
> +	char *gitdir = absolute_pathdup(repo->gitdir);
> +	char *commondir = absolute_pathdup(repo->commondir);
> +
> +	wt->repo = repo;
> +	if (repo->worktree)
> +		wt->path = absolute_pathdup(repo->worktree);

So, if the repository instance knows where the worktree is, we use that to wt->path. Otherwise wt->path is left NULL.

> +	wt->is_bare = !!repo->worktree;

I may be confused but don't we have one ! too many? If we have a worktree directory, "git checkout" would check the files there, and that is not quite a "bare" repository, no?

> +	if (fspathcmp(gitdir, commondir))
> +		wt->id = xstrdup(find_last_dir_sep(commondir) + 1);

OK. So gitdir and commondir would be the same for the primary and for everybody else we'd have "id" as the last directory component of the commondir.

> +	wt->is_current = is_current_worktree(wt);

Oh, so I guessed wrong and this is not about "current" worktree? What does the directory pointed at by repo->worktree mean to the callers of this function? I somehow thought that is_current would be always 1 here,.

Previous: Phillip WoodNext: Phillip Wood
Message 23 of 39 in “worktree: change representation and usage of primary worktree”
  1. Shreyansh PaliwalFeb 13, 2026
  2. [RFC][PATCH 1/2] worktree: represent the primary worktree with '/' instead of NULLShreyansh Paliwal, Feb 13, 2026
  3. Junio C HamanoFeb 13, 2026
  4. Shreyansh PaliwalFeb 14, 2026
  5. [RFC][PATCH 2/2] worktree: stop passing NULL as primary worktreeShreyansh Paliwal, Feb 13, 2026
  6. Junio C HamanoFeb 13, 2026
  7. Shreyansh PaliwalFeb 14, 2026
  8. Phillip WoodFeb 14, 2026
  9. Junio C HamanoFeb 14, 2026
  10. Shreyansh PaliwalFeb 15, 2026
  11. Phillip WoodFeb 16, 2026
  12. Junio C HamanoFeb 17, 2026
  13. Shreyansh PaliwalFeb 17, 2026
  14. 0/2 worktree_git_path(): remove repository argumentPhillip Wood, Feb 16, 2026
  15. 1/2 wt-status: avoid passing NULL worktreePhillip Wood, Feb 16, 2026
  16. Phillip WoodFeb 17, 2026
  17. Shreyansh PaliwalFeb 17, 2026
  18. Phillip WoodFeb 17, 2026
  19. Shreyansh PaliwalFeb 17, 2026
  20. Junio C HamanoFeb 17, 2026
  21. Karthik NayakFeb 17, 2026
  22. Phillip WoodFeb 18, 2026
  23. Junio C HamanoFeb 17, 2026
  24. Phillip WoodFeb 18, 2026
  25. 2/2 path: remove repository argument from worktree_git_path()Phillip Wood, Feb 16, 2026
  26. Karthik NayakFeb 17, 2026
  27. Shreyansh PaliwalFeb 17, 2026
  28. Phillip WoodFeb 17, 2026
  29. Shreyansh PaliwalFeb 17, 2026
  30. 0/2 worktree_git_path(): remove repository argumentPhillip Wood, Feb 19, 2026
  31. 1/2 wt-status: avoid passing NULL worktreePhillip Wood, Feb 19, 2026
  32. Junio C HamanoFeb 19, 2026
  33. Junio C HamanoFeb 19, 2026
  34. Phillip WoodFeb 25, 2026
  35. Junio C HamanoFeb 25, 2026
  36. Phillip WoodFeb 26, 2026
  37. Junio C HamanoFeb 26, 2026
  38. 2/2 path: remove repository argument from worktree_git_path()Phillip Wood, Feb 19, 2026
  39. Junio C HamanoFeb 19, 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.