Expand description
Which commit service instance belongs to a worktree: its name, socket and unit instances.
What:
Which commit service instance belongs to a worktree: a name made from the worktree’s own Git directory, and the
socket, the unit instances and the journal directory that name gives.
Why:
One service instance runs per worktree, the way Bazel runs one server per workspace, so a wait in one worktree (a foreign
holder of its index lock, a slow push) never delays another’s commits. A worktree’s own Git directory (the main
worktree’s .git, or .git/worktrees/<id> of a linked one) holds its HEAD, its index and its work records, and Git
allows one branch to be checked out in one worktree only, so the instances never write the same branch
(doc/planning/cli-git-resident-service.md, “One service per worktree”). The name is a hash because an escaped path
does not fit a unit name for an ordinary home directory, and the hash is the same in the wrapper and in the service,
which are built together. A collision of two worktrees would only make one instance serve both, never land anywhere
wrong.
In TS you’d write (pseudocode):
const socket = join(runtimeDir, 'cli-git', `${instanceOf(gitDir)}.sock`);Constants§
- INSTANCE_
LENGTH - The number of hexadecimal digits of an instance name.
- LEGACY_
SOCKET_ RELATIVE - The socket of the one service every worktree of an account shared until the release that gave each worktree its own. A service still listening here is asked to retire and its units are removed.
- SOCKET_
DIRECTORY - Directory of the sockets under the user’s runtime directory.
Functions§
- instance_
of - What: The instance name of a worktree: 32 hexadecimal digits of the FNV-1a hash of its real Git directory path. Why: The real path makes two spellings of one directory (a link, a relative part) one instance. A directory that cannot be resolved is hashed as given.
- service_
unit_ instance - The name of the service unit instance of a worktree.
- socket_
for - The socket of the worktree whose own Git directory is
git_dir. - socket_
path - The socket of an instance under the user’s runtime directory.
- socket_
unit_ instance - The name of the socket unit instance of a worktree.