Skip to main content

Commit

Struct Commit 

Source
pub struct Commit {
    pub hash: Hash,
    pub branch_name: String,
    pub parent_hash: Option<Hash>,
    pub merge_parent_hash: Option<Hash>,
    pub manifest_hash: Hash,
    pub author: String,
    pub message: Option<String>,
    pub timestamp: DateTime<Utc>,
    pub files: Vec<FileChange>,
}
Expand description

A commit within a branch.

§Commit messages and the new model

As of the “branch descriptions are the source of truth” refactor, commit messages no longer exist for local commits or feature-branch commits on the server. The message field is Some(_) only for commits on main that were produced by a squash-merge — and in that case the message is the merged branch’s description. Everything else is None.

Fields§

§hash: Hash§branch_name: String§parent_hash: Option<Hash>§merge_parent_hash: Option<Hash>§manifest_hash: Hash§author: String§message: Option<String>

Some(_) only on main-branch squash-merge commits (where the value is the merged branch’s description). None for every local commit and every feature-branch commit on the server.

§timestamp: DateTime<Utc>§files: Vec<FileChange>

Implementations§

Source§

impl Commit

Source

pub fn new( branch_name: String, parent_hash: Option<Hash>, merge_parent_hash: Option<Hash>, manifest_hash: Hash, author: String, message: Option<String>, files: Vec<FileChange>, ) -> Result<Self>

Create a new commit, computing the hash.

The timestamp is truncated to microsecond precision before hashing. The hash preimage embeds timestamp.to_rfc3339(), and the lowest-precision store a commit row must survive is the server’s Postgres TIMESTAMPTZ (microseconds) — a nanosecond-precision timestamp (Linux Utc::now()) would hash all nine digits, get truncated on store, and leave a row that can never reproduce its own hash. See Commit::rehydrate_verified for how already-stored nanosecond-hashed commits are still verified.

Source

pub fn with_timestamp( branch_name: String, parent_hash: Option<Hash>, merge_parent_hash: Option<Hash>, manifest_hash: Hash, author: String, message: Option<String>, files: Vec<FileChange>, timestamp: DateTime<Utc>, ) -> Result<Self>

Create a commit at a specific timestamp (instead of Utc::now()). Used when replaying commits from another VCS — oak clone <git-url> imports git history and needs the original commit dates preserved.

The hash preimage joins its fields with \n (see hash_format::hash_commit), so branch name and author must be \n/\t/\0-free or two distinct commits could hash identically. Both are Oak-generated or config values, so rejecting them here never refuses previously legal data. The message — the one field that may legitimately contain newlines — stays unambiguous because every neighboring field is now control-character-free.

Source

pub fn rehydrate_verified( claimed_hash: &Hash, branch_name: String, parent_hash: Option<Hash>, merge_parent_hash: Option<Hash>, manifest_hash: Hash, author: String, message: Option<String>, files: Vec<FileChange>, timestamp: DateTime<Utc>, ) -> Result<Self>

Reconstruct a commit from stored/wire fields, verifying that the fields reproduce claimed_hash — with tolerance for microsecond-truncated timestamps.

Server-side Postgres stores commit timestamps as TIMESTAMPTZ (microsecond precision), but every commit created on a nanosecond-resolution clock before Commit::new started truncating (every squash-merge the Linux server ever made) hashed all nine subsecond digits into its preimage. The stored row therefore can’t reproduce its own hash from its own fields.

When the exact fields don’t reproduce claimed_hash and the timestamp carries no sub-microsecond digits, this restores each possible lost nanosecond tail (1..=999) and accepts the one that reproduces the claimed hash — recovering, not trusting, the original preimage: a match proves the fields are byte-identical to what was hashed, minus precision the store dropped. The returned commit carries the recovered timestamp, so re-storing it locally yields an exactly self-verifying row.

A second legacy class is also tolerated: commits hashed before merge_parent_hash entered the v1 preimage verify against the frozen 6-field preimage (hash_format::hash_commit_v1_pre_merge_parent), strictly gated on the commit having no merge parent.

Source

pub fn verify_fields(&self) -> Result<()>

Check that this commit’s own fields reproduce its hash, under the same rules as Commit::rehydrate_verified. Most readers trust rows from the local store; this is the check for those that must not (repair passes, integrity inspection). File rows are not part of the v1 preimage, so they are not cloned into the check.

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<'de> Deserialize<'de> for Commit

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Commit

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Forget for Commit

§

impl Freeze for Commit

§

impl Move for Commit

§

impl RefUnwindSafe for Commit

§

impl Send for Commit

§

impl Sync for Commit

§

impl Unpin for Commit

§

impl UnsafeUnpin for Commit

§

impl UnwindSafe for Commit

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.