diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2017-02-08 18:31:44 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-02-08 15:59:12 -0800 |
commit | d3c6e5dfc28baa1f66d95c1bf19cf1916ece5c5f (patch) | |
tree | 5d821885972dd835f361e8269cc5fc5c6ddc41a8 /worktree.h | |
parent | f947b583ebf4e9f68638906b750b1545455f026d (diff) | |
download | git-nd/worktree-gc-protection.tar.gz |
worktree.c: use submodule interface to access refs from another worktreend/worktree-gc-protection
The patch itself is relatively simple: manual parsing code is replaced
with a call to resolve_ref_submodule(). The manual parsing code must die
because only refs/files-backend.c should do that. Why submodule here is
a more interesting question.
From an outside look, any .git/worktrees/foo is seen as a "normal"
repository. You can set GIT_DIR to it and have access to everything,
even shared things that are not literally inside that directory, like
object db or shared refs.
On top of that, linked worktrees point to those directories with ".git"
files. These two make a linked worktree's path "X" a "submodule" (*) (**)
because X/.git is a file that points to a repository somewhere.
As such, we can just linked worktree's path as a submodule. We just need
to make sure they are unique because they are used to lookup submodule
refs store.
Main worktree is a a bit trickier. If we stand at a linked worktree, we
may still need to peek into main worktree's HEAD, for example. We can
treat main worktree's path as submodule as well since git_path_submodule()
can tolerate ".git" dirs, in addition to ".git" files.
The constraint is, if main worktree is X, then the git repo must be at
X/.git. If the user separates .git repo far away and tell git to point
to it via GIT_DIR or something else, then the "main worktree as submodule"
trick fails. Within multiple worktree context, I think we can limit
support to "standard" layout, at least for now.
(*) The differences in sharing object database and refs between
submodules and linked worktrees don't really matter in this context.
(**) At this point, we may want to rename refs *_submodule API to
something more neutral, maybe s/_submodule/_remote/
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'worktree.h')
-rw-r--r-- | worktree.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/worktree.h b/worktree.h index d59ce1fee8..961252e713 100644 --- a/worktree.h +++ b/worktree.h @@ -4,7 +4,7 @@ struct worktree { char *path; char *id; - char *head_ref; + char *head_ref; /* NULL if HEAD is broken or detached */ char *lock_reason; /* internal use */ unsigned char head_sha1[20]; int is_detached; |