Expand description
Refs subsystem.
Implements the local-disk side of docs/SPEC-REFS.md: ref names,
the 65-byte wire encoding, the symbolic-or-detached HEAD file, and
shallow-boundary persistence at .mkit/shallow.
Wire format (per SPEC-REFS §1): exactly 64 lowercase-hex characters
plus a trailing 0x0A newline = 65 bytes. Uppercase hex is rejected
on read. Trailing \r and ASCII whitespace are tolerated when
parsing local files (so a Windows-edited HEAD does not brick a
repo), but fresh writes always emit the strict 65-byte form.
Ref name grammar (SPEC-REFS §3): [A-Za-z0-9._-]+ segments joined
by /, with no leading/trailing /, no ./.. segments, no
backslashes, no NULs. In addition, no segment may end in .lock
(the canonical lock-file suffix) and the final segment may not be
the literal HEAD (which would shadow the repo-level HEAD
pointer). We share the validator with the future transport layer
via validate_ref_name / validate_ref_prefix.
CAS variants for update_ref follow SPEC-REFS §5: Any (clobber),
Missing (fail if it exists), Match(H) (fail if current value !=
H). The local-filesystem Match is not atomic across processes
— that is the documented v1 gap; transports that need true atomicity
must use s3/http/ssh.
Structs§
- Ref
- A listed ref entry: name (with
refs/heads/or similar prefix stripped) plus the resolved hash, when readable.
Enums§
- Head
- HEAD pointer: either a symbolic reference to a branch name, or a detached hash.
- RefError
- Errors raised by this module.
- RefWrite
Condition - CAS condition for
update_ref.
Constants§
- HEADS_
DIR - Subdirectory holding branch refs (
.mkit/refs/heads). - HEAD_
FILE - HEAD file relative to the
.mkitroot. - REFS_
DIR - Subdirectory holding all refs (
.mkit/refs). - REMOTES_
DIR - Subdirectory holding remote-tracking refs (
.mkit/refs/remotes). - SHALLOW_
FILE - Shallow-boundary file relative to the
.mkitroot. - TAGS_
DIR - Subdirectory holding tag refs (
.mkit/refs/tags).
Functions§
- decode_
ref_ wire - Decode a ref wire blob into a
Hash. Tolerates a trailing newline /\r/ ASCII whitespace (so files round-tripped through a Windows editor still parse), but rejects uppercase hex per SPEC-REFS §1. - delete_
ref - Delete a branch ref. Errors with
RefError::NotFoundif absent. - delete_
ref_ safe - Delete a branch ref unless it is the currently checked-out branch.
- delete_
remote_ ref - Delete a remote-tracking branch ref (e.g. after the upstream
deleted the branch). Errors with
RefError::NotFoundif absent. - delete_
tag - Delete a tag ref.
- encode_
ref_ wire - Encode
hto its 65-byte wire form (lowercase hex +\n). - init
- Initialise the ref directory layout under
mkit_dir(the.mkit/directory). Creates therefs/,refs/heads/,refs/tags/,refs/remotes/subdirectories and writes a defaultHEAD = ref: refs/heads/main\nifHEADdoes not already exist. - list_
refs - List all branch refs, sorted lexicographically by name.
- list_
remote_ names - List the remote names that have at least one tracking ref on disk
(the immediate subdirectories of
refs/remotes/), sorted. A missingrefs/remotes/yields an empty list. Entries whose names fail the ref grammar are skipped (consistent with how malformed ref files are skipped bylist_refs). - list_
remote_ refs - List all remote-tracking refs for one remote.
- list_
tags - List all tag refs, sorted lexicographically by name.
- load_
shallow_ boundaries - Load shallow-boundary hashes from
.mkit/shallow. ReturnsOk(None)if the file does not exist or is empty. - read_
head - Read
HEADfrom<mkit_dir>/HEAD. - read_
ref - Read the hash a branch ref points to. Returns
Ok(None)if the ref file does not exist. - read_
remote_ ref - Read a remote-tracking branch ref.
- read_
tag - Read the hash a tag points to.
- resolve_
head - Resolve
HEADto a commit hash. ReturnsOk(None)when HEAD points at a branch that has no commit yet. - update_
head - Update the ref HEAD currently points at (or HEAD itself, if
detached) to
commit_hash. - update_
ref - CAS-aware ref write per SPEC-REFS §5.
- update_
ref_ with_ history - Combined ref-write + history-MMR-append, protected by a single repo-level lock. Issue #157, Phase 2.
- update_
tag - CAS-aware tag write — same semantics as
update_refbut forrefs/tags/. - validate_
ref_ name - Validate a ref name per SPEC-REFS §3. Used at every transport boundary; transports MUST NOT silently lower-case or canonicalise.
- validate_
ref_ prefix - Validate a prefix passed to
list_refs. An empty prefix is allowed. A single trailing/is allowed; otherwise the prefix must satisfyvalidate_ref_name. - write_
head_ branch - Write
HEADas a symbolic ref pointing atbranch. - write_
head_ detached - Write
HEADas a detached hash. - write_
ref - Write a branch ref (unconditional — equivalent to
update_ref(branch, RefWriteCondition::Any, h)). - write_
remote_ ref - Write a remote-tracking branch ref unconditionally.
- write_
shallow_ boundaries - Write shallow-boundary hashes to
.mkit/shallow. Passing an empty slice removes the file. - write_
tag - Write a tag ref (unconditional).
Type Aliases§
- RefResult
- Result alias used throughout this module.