Skip to main content

Commit

Struct Commit 

Source
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:

  1. a{sv}: the metadata dict
  2. ay: the checksum of the parent commit, empty for a root commit
  3. a(say): the related objects
  4. s: the subject
  5. s: the body
  6. t: the timestamp, big-endian
  7. ay: the checksum of the root dirtree
  8. ay: 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: Value

The 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.

§related: Vec<(String, Vec<u8>)>

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: String

The commit subject, the first line of its message.

§body: String

The commit body, the rest of its message.

§timestamp: u64

The commit time, in seconds since the Unix epoch, UTC.

§root_dirtree: Checksum

The checksum of the dirtree object of the root directory.

§root_dirmeta: Checksum

The checksum of the dirmeta object of the root directory.

Implementations§

Source§

impl Commit

Source

pub fn parse(data: &[u8]) -> Result<Commit>

Parses a serialized commit object.

§Errors
  • Error::Gvariant with NotNormal if data, the metadata dict, or an entry of the related objects is not in normal form.
  • Error::Gvariant with DepthExceeded if the metadata dict nests deeper than the depth limit of from_bytes.
  • Error::InvalidCommit with “parent checksum is neither empty nor 32 bytes” if the parent checksum has a length other than 0 or 32.
  • Error::InvalidCommit with “root dirtree checksum is not 32 bytes” if the root dirtree checksum has a length other than 32.
  • Error::InvalidCommit with “root dirmeta checksum is not 32 bytes” if the root dirmeta checksum has a length other than 32.
Source

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.

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
Source

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.

Source

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
Source

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.

Source

pub fn checksum(&self) -> Result<Checksum>

Returns the commit checksum, the SHA-256 of the serialized bytes.

§Errors

The errors of serialize.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Commit

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Commit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Commit

Source§

impl GvEncode for Commit

Source§

fn encode(&self, out: &mut Vec<u8>) -> Result<()>

Appends the normal-form bytes of self to out. Read more
Source§

impl GvType for Commit

Source§

const SIGNATURE: &'static str = "(a{sv}aya(say)sstayay)"

The GVariant type signature, or "" for a container type. Read more
Source§

const ALIGNMENT: usize = 8

The alignment of the serialized form, in bytes.
Source§

const FIXED_SIZE: Option<usize> = None

The serialized size, or None for a variable-size type.
Source§

impl PartialEq for Commit

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Commit

Auto Trait Implementations§

§

impl Forget for Commit

§

impl Freeze for Commit

§

impl Move for Commit

§

impl RefUnwindSafe for Commit

§

impl Send for Commit
where RawVecInner: Send, BoxRaw<Value>: Send, BoxRaw<(Type, Value)>: Send,

§

impl Sync for Commit
where RawVecInner: Sync, BoxRaw<Value>: Sync, BoxRaw<(Type, Value)>: Sync,

§

impl Unpin for Commit
where *const u8 is !null: Unpin, Box<Value>: Unpin, Box<(Type, Value)>: Unpin,

§

impl UnsafeUnpin for Commit

§

impl UnwindSafe for Commit
where RawVecInner: UnwindSafe, BoxRaw<Value>: UnwindSafe, BoxRaw<(Type, Value)>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.