Expand description
Repository path layout: the single authority for resolving on-disk
state under .mkit/ (issue #493, Phase 0).
Every piece of repository state is classified into exactly one of two directories:
- the common dir — state shared by every working tree of the repository: the object store, refs, config, signing keys, the history MMR, the recovery log, attestations, transport caches;
- the worktree state dir — state private to one working tree:
HEAD, the staging index, in-progress-operation files (MERGE_HEAD,rebase-apply/, …), the stash, and the worktree lock.
In the classic single-worktree layout both directories are the same
<root>/.mkit/, so RepoLayout::single produces byte-identical
paths to the historical ad-hoc joins. In a linked working tree
(#493 Phase 1) they differ: the linked tree’s per-tree state lives
under the main repository’s .mkit/worktrees/<id>/, and the linked
tree’s own .mkit is a plain FILE — the pointer file — instead of
a directory. Nothing outside this module may assume the two
directories coincide.
§Linked-worktree on-disk model (#493 Phase 1)
<main>/.mkit/ # common dir (shared state)
worktrees/<id>/ # one per linked tree
commondir # path to the common dir, `../..`
mkitdir # abs path of the tree's pointer file
HEAD, index, ORIG_HEAD, ... # per-tree state, as classified below
<linked-tree>/.mkit # pointer FILE, not a directory:
`mkitdir: <path to .mkit/worktrees/<id>>\n`The pointer path may be absolute or relative to the linked tree
root; commondir may be absolute or relative to the state dir.
Both files are UTF-8, single-line, LF-terminated, and capped at
MAX_POINTER_FILE_BYTES. Discovery (discover) fails closed on
any malformed or dangling pointer; a .mkit DIRECTORY (every
pre-Phase-1 repository) always resolves to the single-worktree
layout, byte-identical to before.
§Classification table
| Path (relative) | Class | Owner module |
|---|---|---|
objects/ | common | crate::store |
format | common | crate::store |
refs/ (+heads,tags,remotes) | common | crate::refs |
shallow | common | crate::refs |
config | common | CLI config |
keys/ | common | CLI config |
history/ | common | crate::history (feature-gated) |
recovery-log | common | crate::ops::recovery |
attestations/ | common | mkit-attest |
applied-packs/ | common | CLI remote dispatch (redownload cache, never a gc root) |
git/ | common | mkit-git-bridge |
sparse/ | common | CLI sparse bitmap cache |
pack-shards/ | common | CLI pack-shard output |
HEAD | worktree | crate::refs |
index | worktree | crate::index |
ORIG_HEAD | worktree | crate::ops::conflict_state |
MERGE_HEAD/MERGE_MSG | worktree | crate::ops::conflict_state |
CHERRY_PICK_HEAD/_MSG | worktree | crate::ops::conflict_state |
REVERT_HEAD/_MSG | worktree | crate::ops::conflict_state |
mkit-conflicts | worktree | crate::ops::conflict_state |
MKIT_OP_RESULT | worktree | crate::ops::conflict_state |
rebase-apply/ | worktree | crate::ops::rebase |
bisect | worktree | crate::ops::bisect |
stash | worktree | crate::ops::stash |
sparse-checkout | worktree | crate::ops::restore |
worktree.lock | worktree | CLI lock helper |
Rationale for the git-divergent entries: shallow is shared because
it constrains the one shared object graph; the stash is per-worktree
(unlike git’s refs/stash) because mkit’s stash is a worktree-state
manifest, not a ref — #493 specifies stash as tree-local.
§Invariants
- Both directories always end in a final
.mkitcomponent (a linked tree’s state dir will live under the main.mkit; that still satisfies the prefix rule below). - Every accessor resolves strictly inside
common_dir()orworktree_state_dir(); no accessor ever escapes them. RepoLayout::singleguaranteescommon_dir() == worktree_state_dir() == worktree_root().join(".mkit").
Structs§
- Repo
Layout - Resolved repository layout: worktree root plus the two state directories (see the module docs for the classification table).
- Worktree
Entry - One entry of the linked-worktree registry (
<common>/worktrees/*), as reported byworktrees.
Enums§
- Discover
Error - Errors surfaced by
discoveron a broken linked-worktree setup.
Constants§
- APPLIED_
PACKS_ DIR_ NAME - Per-remote applied-pack record directory name under the common dir. A redownload-avoidance cache — never a gc root source (#409).
- ATTESTATIONS_
DIR_ NAME - Attestation store directory name under the common dir.
- BACKPOINTER_
FILE_ NAME - File inside a per-tree state dir recording the absolute path of the
linked tree’s pointer file — the back-pointer
worktree prunechecks before deleting a state dir. - COMMONDIR_
FILE_ NAME - File inside a per-tree state dir recording the path back to the
common dir (relative to the state dir, or absolute). Written as
../..byworktree add. - CONFIG_
FILE_ NAME - Config file name under the common dir (written by the CLI).
- GIT_
STATE_ DIR_ NAME - Git-bridge per-remote state directory name under the common dir.
- HISTORY_
DIR_ NAME - Commit-history MMR directory name under the common dir. Canonical
here (rather than in
crate::history) because that module is feature-gated while the layout is not;history::HISTORY_DIRre-points at this constant. - INDEX_
FILE_ NAME - Staging-index file name under the worktree state dir.
- KEYS_
DIR_ NAME - Repository signing-key directory name under the common dir.
- MAX_
POINTER_ FILE_ BYTES - Hard cap on the pointer,
commondir, and back-pointer files. Far above any real path, small enough that a corrupt or hostile file cannot balloon discovery. - PACK_
SHARDS_ DIR_ NAME - Default pack-shard output directory name under the common dir.
- POINTER_
PREFIX - Prefix of the linked-tree pointer file (
<tree>/.mkitas a FILE):mkitdir: <path>\n— the analog of git’sgitdir:file. - SPARSE_
CACHE_ DIR_ NAME - Sparse bitmap-cache directory name under the common dir.
- SPARSE_
CHECKOUT_ FILE_ NAME - Sparse-checkout filter file name under the worktree state dir.
- STASH_
FILE_ NAME - Stash manifest file name under the worktree state dir.
- WORKTREES_
DIR_ NAME - Directory under the common dir holding one per-tree state dir per linked worktree.
Functions§
- all_
state_ layouts - Every per-tree STATE layout of the repository, for cross-worktree
root collection (#493 Phase 3): the main tree first, then one
layout per
worktrees/<id>state dir that exists on disk — in deterministic order (main, then ids ascending), so multi-lock acquisition over the result cannot deadlock against itself. - discover
- Resolve the
RepoLayoutfor the repository whose working tree is rooted atworktree_root(#493 Phase 1 discovery). - validate_
worktree_ id - Validate a linked-worktree id (the
worktrees/<id>directory name). - worktrees
- Enumerate the linked-worktree registry of
layout’s repository, sorted by id. The main worktree is NOT an entry — its state dir is the common dir itself. - write_
pointer_ file - Write the linked-tree pointer file:
<tree>/.mkitcontainingmkitdir: <state_dir>\n. Used byworktree add(#493 Phase 2); public now so the format has exactly one writer and one reader.