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§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
impl Commit
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub fn verify_fields(&self) -> Result<()>
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<'de> Deserialize<'de> for Commit
impl<'de> Deserialize<'de> for Commit
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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