pub struct Commit {
pub metadata: Value,
pub parent: Option<Checksum>,
pub related: Vec<(String, Vec<u8>)>,
pub subject: String,
pub body: String,
pub timestamp: u64,
pub root_dirtree: Checksum,
pub root_dirmeta: Checksum,
}Expand description
An owned commit object.
§Wire form
A commit object is the GVariant tuple (a{sv}aya(say)sstayay). It holds
these members, in this order:
a{sv}: the metadata dictay: the checksum of the parent commit, empty for a root commita(say): the related objectss: the subjects: the bodyt: the timestamp, big-endianay: the checksum of the root dirtreeay: the checksum of the root dirmeta
The struct holds the timestamp in host byte order.
The metadata is a Value tree. It writes back to the same bytes,
because from_bytes accepts only normal form and to_bytes writes
normal form.
A walk of a long parent chain uses Commit::parse_link. A check of the
timestamp alone uses Commit::parse_timestamp.
Fields§
§metadata: ValueThe a{sv} metadata dict as a Value tree.
The tree is an array of two-element tuples, in on-disk order.
parent: Option<Checksum>The checksum of the parent commit, or None for a root commit.
The related objects.
The ostree command writes an empty array. The port uses the field
for the attachments of a commit: each entry is a name and the 32-byte
checksum of a commit. A parse keeps the entries as read, so the commit
serializes to the same bytes.
subject: StringThe commit subject, the first line of its message.
body: StringThe commit body, the rest of its message.
timestamp: u64The commit time, in seconds since the Unix epoch, UTC.
root_dirtree: ChecksumThe checksum of the dirtree object of the root directory.
root_dirmeta: ChecksumThe checksum of the dirmeta object of the root directory.
Implementations§
Source§impl Commit
impl Commit
Sourcepub fn parse(data: &[u8]) -> Result<Commit>
pub fn parse(data: &[u8]) -> Result<Commit>
Parses a serialized commit object.
§Errors
Error::GvariantwithNotNormalifdata, the metadata dict, or an entry of the related objects is not in normal form.Error::GvariantwithDepthExceededif the metadata dict nests deeper than the depth limit offrom_bytes.Error::InvalidCommitwith “parent checksum is neither empty nor 32 bytes” if the parent checksum has a length other than 0 or 32.Error::InvalidCommitwith “root dirtree checksum is not 32 bytes” if the root dirtree checksum has a length other than 32.Error::InvalidCommitwith “root dirmeta checksum is not 32 bytes” if the root dirmeta checksum has a length other than 32.
Sourcepub fn parse_with_metadata_entries(
data: &[u8],
) -> Result<(Commit, Vec<(String, Vec<u8>)>)>
pub fn parse_with_metadata_entries( data: &[u8], ) -> Result<(Commit, Vec<(String, Vec<u8>)>)>
Parses a serialized commit object, and returns the entries of its metadata dict as bytes beside it.
The returned commit holds an empty metadata dict. Each entry is the key
and the bytes of its v in normal form, in the order of the dict. A
key that occurs in more than one entry stays in each entry. The
function checks the metadata dict as Commit::parse does, and builds
no value tree of it.
§Errors
The errors of Commit::parse.
Sourcepub fn parse_link(data: &[u8]) -> Result<CommitLink>
pub fn parse_link(data: &[u8]) -> Result<CommitLink>
Parses the parent and the root checksums of a serialized commit object.
The function does not decode the metadata dict or the entries of the
related objects. It checks the tuple frame, the subject, the body, and
the three checksums as Commit::parse does.
§Errors
Error::GvariantwithNotNormalif the tuple frame, the subject, or the body is not in normal form.Error::InvalidCommitwith the messages ofCommit::parseif the parent, the root dirtree, or the root dirmeta checksum has a wrong length.
Sourcepub fn parse_timestamp(data: &[u8]) -> Result<u64>
pub fn parse_timestamp(data: &[u8]) -> Result<u64>
Parses the timestamp of a serialized commit object.
The function does not decode the metadata dict or the entries of the
related objects. It checks the tuple frame, the subject, the body, and
the three checksums as Commit::parse does. The timestamp is in host
byte order, as Commit::timestamp holds it.
§Errors
The errors of Commit::parse_link.
Sourcepub fn serialize(&self) -> Result<Vec<u8>>
pub fn serialize(&self) -> Result<Vec<u8>>
Serializes the commit to normal-form bytes.
The SHA-256 of these bytes is the commit checksum, which
checksum returns.
§Errors
Error::GvariantwithTypeMismatchifmetadatais not a value of typea{sv}.Error::GvariantwithInvalidValueif a string holds an interior NUL byte. This applies to the strings in the metadata, the subject, the body, and the names of the related objects.Error::GvariantwithDepthExceededif the metadata nests deeper than the depth limit ofto_bytes.
Sourcepub fn serialize_with_metadata(&self, metadata: &[u8]) -> Result<Vec<u8>>
pub fn serialize_with_metadata(&self, metadata: &[u8]) -> Result<Vec<u8>>
Serializes the commit with the serialized a{sv} dict metadata in
place of metadata.
The call writes metadata as it is and reads no field
metadata, so a caller that holds the metadata as
bytes builds no value tree. The call does not check metadata. If it
is not a normal-form a{sv} dict, Commit::parse refuses the
result. With the bytes of self.metadata, the result is the result of
serialize.
§Errors
Error::Gvariant with InvalidValue if a string holds an
interior NUL byte: the subject, the body, or the name of a related
object.
Sourcepub fn content_checksum(&self) -> Checksum
pub fn content_checksum(&self) -> Checksum
Returns the content checksum of the commit.
The content checksum is the SHA-256 of the 32-byte root dirtree checksum followed by the 32-byte root dirmeta checksum. The metadata and the timestamp of the commit do not change it.
Sourcepub fn metadata_value(&self, key: &str) -> Option<&Value>
pub fn metadata_value(&self, key: &str) -> Option<&Value>
Returns the child of the variant under key in the metadata dict.
If key occurs in more than one entry, the first entry applies. If no
entry has key, or if its value is not a variant, the result is None.
Sourcepub fn version(&self) -> Option<&str>
pub fn version(&self) -> Option<&str>
Returns the value of the version metadata key.
version is the only well-known key without the ostree. prefix. If
the key is absent, or if its value is not a string, the result is
None.
Sourcepub fn ref_bindings(&self) -> Vec<&str>
pub fn ref_bindings(&self) -> Vec<&str>
Returns the ref names in the ostree.ref-binding metadata key.
If the key is absent, or if the commit is bound to no ref, the list is empty.
Sourcepub fn collection_binding(&self) -> Option<&str>
pub fn collection_binding(&self) -> Option<&str>
Returns the value of the ostree.collection-binding metadata key.
If the key is absent, or if its value is not a string, the result is
None.