Expand description
Commit snapshots, ordered parent edges, identities, and messages.
A Commit names a root tree and ordered parents, plus author, committer, headers, and
message. A root commit has no parents; a merge has multiple parents. Parent order is meaningful.
Times are metadata, not a reliable ordering of ancestry. Use crate::history for graph
queries and crate::refs to make a stored commit reachable by name.
§Read graph records without normalizing the payload
use girt::{Commit, ObjectFormat, Tree};
let tree = Tree::new(ObjectFormat::Sha1, vec![])?;
let payload = format!("tree {}\n\nImported snapshot\n", tree.id());
let commit = Commit::parse(ObjectFormat::Sha1, payload.as_bytes())?;
assert_eq!(commit.tree(), tree.id());
assert!(commit.parents().is_empty());
assert_eq!(commit.message(), b"Imported snapshot\n");
assert_eq!(commit.encode(), payload.as_bytes());
// Graph records are readable even when construction fields are absent.
assert!(commit.author()?.is_none());
assert!(commit.to_fields().is_err());CommitPayload offers borrowed access to graph records and headers; Commit owns its
bytes. IdentityRef separates identity text from date interpretation. To create a new commit,
supply CommitFields with Signature values to Commit::new, then store it with
crate::LooseObjects::write_commit. Construction does not resolve parents or the tree.
§Preserve imported data and diagnose errors
Parsing preserves accepted bytes and the original ID, including unknown headers, non-UTF-8 text,
and unusual date spelling. Commit::validate applies construction rules without changing
bytes; Commit::to_fields requests editable fields and can fail on missing people or invalid
dates. Rebuilding those fields emits canonical spelling and can change identity even after
validation. Signatures embedded in headers are opaque; parsing does not verify them
cryptographically.
CommitError reports unreadable graph records, invalid construction fields, or mixed object
formats. Report stored-data errors with the object ID; correct newly supplied fields before
writing. Use bounded crate::Objects::read before parsing untrusted bytes. Parsing allocates
in proportion to the payload and does not validate the referenced graph.
Structs§
- Commit
- An owned SHA-1 or SHA-256 commit describing a tree, ordered parents, people, and a message.
- Commit
Builder - Collects fields for
Commit::new. The supplied author is also the default committer. - Commit
Fields - Decoded commit content, editable before passing ownership to
Commit::new. - Commit
Header - An opaque extra commit header, including an optional multiline value.
- Commit
Header Ref - A header occurrence borrowing its exact name and folded value from a
CommitPayload. - Commit
Payload - A borrowed commit payload with structural headers and uninterpreted values.
- Identity
Date - A numerically interpreted Git identity date, independent of canonical construction policy.
- Identity
Ref - Borrowed identity components and uninterpreted date bytes from an imported object.
- Signature
- A Git author, committer, or tagger identity and date, independent of text encoding.
Enums§
- Commit
Error - A commit lies outside the supported grammar or fails construction validation.
- Sign
Error - Commit construction or caller-owned signing failed; nothing has been stored.