I've got a better version [1] that fixes everything I can think of
(there's still some room for improvements). I'm going to use it a bit
longer before reposting again. But here's its basic design without
going down to code

New .git file format includes two lines:
-- 8< --
gitid: <id>
gitdir: <path>
-- 8< --

Which would set $GIT_COMMON_DIR to <path> and $GIT_DIR to
<path>/repos/<id>. Repository split is the same as before, worktree
stuff in $GIT_DIR, the rest in $GIT_COMMON_DIR. This .git file format
takes precedence over core.worktree but can still be overriden with
$GIT_WORK_TREE. The main interface to create new worktree is "git
checkout --to".

"repos" belongs to $GIT_COMMON_DIR (i.e. shared across all checkouts).
The new worktrees (which I call "linked checkouts") can also access
HEAD of the original worktree via a virtual path "main/HEAD". This
makes it possible for a linked checkout to detach HEAD of the main
one.

There are three entries in repos/<id>: "gitdir" should point to the
.git file that points it back here. Every time a linked checkout is
used, git should update mtime of this "gitdir" file to help pruning.
It should update the file content too if the repo is moved. "link" is
a hardlink to .git file, if supported, again for pruning support.
"locked", if exists, means no automatic pruning (e.g. the linked
checkout is on a portable device).

The interesting thing is support for third party scripts (or hooks,
maybe) so that they could work with both old and new git versions
without some sort of git version/feature detection. Of course old git
versions will only work with ordinary worktrees. To that end, "git
rev-parse --git-dir" behavior could be changed by two environment
variables. $GIT_ONE_PATH makes 'rev-parse --git-dir' return the .git
_file_ in this case, which makes it much easier to pass the repo's
checkout view around with "git --git-dir=... ".$GIT_COMMON_DIR_PATH
makes 'rev-parse --git-dir' return $GIT_COMMON_DIR if it's from a
linked checkout, or $GIT_DIR otherwise. This makes 'rev-parse
--git-dir' falls back safely when running using old git versions. The
last patch in [1] that updates git-completion.bash could demonstrate
how it's used.

[1] https://github.com/pclouds/git.git checkout-new-worktree
-- 
Duy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to