Skip to main content

Module candidate_object

Module candidate_object 

Source
Expand description

Validated Git object names and the file modes a candidate can carry. What: The two Git vocabulary types every candidate carries: an object name and a file mode. Why: Object names are written into the object reader’s request stream, so only text proven to be a complete hexadecimal name may ever become one; modes decide whether a candidate has blob content at all.

In TS you’d write (pseudocode):

type ObjectId = string & { readonly brand: 'ObjectId' };
type CandidateMode = 'regular' | 'executable' | 'symlink' | 'gitlink';

Structs§

ObjectId
What: A complete Git object name: 40 or 64 lowercase hexadecimal digits. The field is private, so the only way to obtain a value is parse_object_id. String owns the text (sibling &str would borrow Git’s output buffer). Hash lets the value be a HashMap key. Why: A value of this type is safe to send as one request line: it cannot contain a line feed, a space or a revision expression. The name outlives the Git output it was parsed from, so it owns its text.

Enums§

CandidateMode
What: The file modes Git records for a path that can be a candidate. Why: Regular, executable and symbolic-link entries name a blob; a gitlink names a commit of another repository (a submodule), which this repository’s object store does not hold.

Constants§

SHA1_HEX_LENGTH
What: Length in hexadecimal digits of a SHA-1 object name. usize is the unsigned integer every length and index uses (siblings u32, u64, i64). Why: usize is what .len() returns, so comparing needs no conversion.
SHA256_HEX_LENGTH
Length in hexadecimal digits of a SHA-256 object name, for --object-format=sha256 repositories.

Functions§

mode_from_git
What: Map Git’s six-digit mode text to a candidate mode. b"100644" is a byte-string literal, compared with == byte for byte. Why: Any other mode (a directory 040000, the absent side 000000) cannot be a candidate; the caller reports it instead of guessing.
parse_object_id
What: Accept bytes as an object name only when they are exactly 40 or 64 lowercase hexadecimal digits. &[u8] borrows bytes; Option<ObjectId> is “a name or nothing”. Why: Everything Git prints as an object name passes; anything else (abbreviations, revision expressions, text containing a line feed) is refused before it can reach the reader’s request stream.