Skip to main content

Module refs

Module refs 

Source
Expand description

Ref compare-and-swap and ref-name helpers (SPEC-TRANSPORT-CONNECT §3, SPEC-TRANSPORT §4.2.1, SPEC-REFS §3 and §4).

The canonical copy of logic that lived in mkit serve’s pack_key_from_id/decode_update_ref (removed in WP-M0-13), vcs-worker’s former refs.rs (removed in WP-M0-17), and mkit-transport-connect 0.4’s refs_convert.rs and hashutil.rs (removed in WP-M0-15). apps/repo-worker keeps its own copy (planner decision Q11).

Enums§

CasDecision
The outcome of evaluate_cas or evaluate_condition. Invalid is a malformed request (invalid_argument); Conflict is a precondition failure the client can rebase and retry (failed_precondition).
ConflictReason
Why a CAS update could not commit.
DigestField
The wire field a digest came from; the ssh wire names it in its message.
RefExpectationWire
A CAS expectation as its wire number, aligned with mkit.transport.v1.RefExpectation. The numbers are load-bearing and match mkit.rpc.v1.ssh.RefExpectation and mkit.repo.v1.RefExpectation.
RefWireError
A malformed ref or digest field. Every variant is Code::InvalidArgument; the two message methods keep today’s text for each wire family, as crate::upload::UploadError does.
UnusedExpectedId
How a binding treats an expected_id sent with ANY or MISSING.

Constants§

MAX_REF_NAME_BYTES
Longest ref name, in bytes: SPEC-REFS §3’s bound, mkit_core::refs::MAX_REF_NAME_BYTES. It bounds every ref key (store::keys) below MAX_KEY_BYTES, with room for the longest repo name; store::keys asserts that at compile time. Clients check the same bound (mkit_rpc::MAX_REF_NAME) before sending.
REF_NAME_OUTSIDE_REFS
The public message for a ref name outside SERVED_REFS_PREFIX (SPEC-REFS §2), on every binding; mkit serve sends it as-is. It points an operator whose repo holds such refs, written by an older mkit serve, to the migration notes (docs/CLI.md, “Refs outside refs/”); it names no server path.
REF_NAME_TOO_LONG
The public message for a ref name or ListRefs prefix over MAX_REF_NAME_BYTES; mkit serve sends it as-is.
SERVED_REFS_PREFIX
The prefix of every ref name the pipeline serves: refs live under refs/ (SPEC-REFS §2: refs/heads/, refs/tags/, and mkit’s own refs/mkit/packmap/).

Functions§

condition_from_wire
Convert a wire (expectation, expected_id) pair into a RefWriteCondition. An absent expected_id is passed as empty. unused says what an expected_id sent with ANY or MISSING means.
evaluate_cas
Decide a CAS write from its wire form. current is the ref’s value (None when absent) and expected the MATCH target, which must be None for ANY and MISSING. Ids are compared as opaque bytes.
evaluate_condition
Decide a CAS write from a decoded RefWriteCondition, the check every storage backend shares. Same rules as evaluate_cas; a decoded condition is never Invalid.
hash_from_slice
Parse a 32-byte digest from a wire bytes field (None when absent).
is_served_ref_name
Whether the pipeline serves name: a valid ref name (validate_ref_name) under SERVED_REFS_PREFIX.
list_scan_prefix
The scan prefix of a validated ListRefs prefix (SPEC-REFS §4): empty for an empty prefix, otherwise the prefix with its trailing /s replaced by exactly one. A listing covers the refs whose full name starts with it, so a prefix matches only at a path-component boundary: refs/heads, refs/heads/ and refs// all scan refs/heads/ (and refs/), refs/heads/ma scans refs/heads/ma/ and does not match refs/heads/main, and a ref named exactly the prefix is never listed.
strip_listed_prefix
The name ListRefs returns for a stored ref full under prefix: full with list_scan_prefix(prefix) stripped, or None when it does not extend the prefix at a component boundary (SPEC-REFS §4).
validate_ref_name
Validate a ref name: the SPEC-REFS §3 grammar and at most MAX_REF_NAME_BYTES bytes (mkit_core::refs::validate_ref_name).
validate_ref_prefix
Validate a prefix passed to list_refs. An empty prefix is allowed. A single trailing / is allowed; otherwise the prefix must satisfy validate_ref_name.