Skip to content

RFC worktree: change representation and usage of primary worktree

Shreyansh Paliwal git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 10 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2worktree: represent the primary worktree with '/' instead of NULLworktree.c+9 -52 replies
2/2worktree: stop passing NULL as primary worktreebuiltin/fsck.c builtin/worktree.c path.c +6 more+65 -5134 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC][PATCH 0/2] worktree: change representation and usage of primary worktree

While working on reducing global state in wt-status [1], it became clear that some cleanup in the worktree API would be helpful before moving ahead.

As of now Primary worktree is represented in three ways,

* by passing NULL as a worktree
* by a struct worktree whose wt->id is NULL, and
* in the ref-store map, by using "/" as the key.

This creates ambiguity, callers and helpers often need extra checks for a NULL worktree, and the implicit NULL form makes it harder to rely on fields like wt->repo without falling back to global state.

So this patch series involves making the worktree API more robust by removing the usage of NULL as the representation and using wt->id = '/' as the marker for a primary worktree.

In patch 1/2, change the internal representation in worktree.c so that the main worktree is identified by '/' instead of NULL.

In patch 2/2, update the API usage by modifying callers to obtain the primary worktree via helper and pass an actual struct worktree rather than NULL.

I would like to get feedback whether this implementation is in the right direction, and if there is anything else that I should be doing in this cleanup series.

[1]- https://lore.kernel.org/git/[email protected]/T/#u

Shreyansh Paliwal (2):
worktree: represent the primary worktree with "/" instead of NULL
worktree: stop passing NULL as primary worktree

 builtin/fsck.c     |  2 +-
 builtin/worktree.c | 10 +++++++---
 path.c             | 27 +++++++++++++--------------
 path.h             |  9 +++------
 refs.c             |  4 ++--
 revision.c         |  6 ++++--
 worktree.c         | 43 +++++++++++++++++++++++++------------------
 worktree.h         |  7 +++++++
 wt-status.c        | 22 ++++++++++++----------
 9 files changed, 74 insertions(+), 56 deletions(-)

--
2.53.0