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§
- Object
Id - 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.Stringowns the text (sibling&strwould borrow Git’s output buffer).Hashlets the value be aHashMapkey. 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§
- Candidate
Mode - 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.
usizeis the unsigned integer every length and index uses (siblingsu32,u64,i64). Why:usizeis what.len()returns, so comparing needs no conversion. - SHA256_
HEX_ LENGTH - Length in hexadecimal digits of a SHA-256 object name,
for
--object-format=sha256repositories.
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 directory040000, the absent side000000) 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.