Skip to main content

Repository

Struct Repository 

Source
pub struct Repository<Storage: BlobStore<Blake3> + BranchStore<Blake3>> { /* private fields */ }
Expand description

High-level wrapper combining a blob store and branch store into a usable repository API.

The Repository type exposes convenience methods for creating branches, committing data and pushing changes while delegating actual storage to the given BlobStore and BranchStore implementations.

Implementations§

Source§

impl<Storage> Repository<Storage>

Source

pub fn close(self) -> Result<(), <Storage as StorageClose>::Error>

Close the repository’s underlying storage if it supports explicit close operations.

This method is only available when the storage type implements StorageClose. It consumes the repository and delegates to the storage’s close implementation, returning any error produced.

Source§

impl<Storage> Repository<Storage>
where Storage: BlobStore<Blake3> + BranchStore<Blake3>,

Source

pub fn new( storage: Storage, signing_key: SigningKey, commit_metadata: TribleSet, ) -> Result<Self, <Storage as BlobStorePut<Blake3>>::PutError>

Creates a new repository with the given storage, signing key, and commit metadata.

The commit_metadata TribleSet is stored as a blob in the repository and attached to every commit created through this repository’s workspaces.

Source

pub fn into_storage(self) -> Storage

Consume the repository and return the underlying storage backend.

This is useful for callers that need to take ownership of the storage (for example to call close() on a Pile) instead of letting the repository drop it implicitly.

Source

pub fn storage(&self) -> &Storage

Borrow the underlying storage backend.

Source

pub fn storage_mut(&mut self) -> &mut Storage

Borrow the underlying storage backend mutably.

Source

pub fn set_signing_key(&mut self, signing_key: SigningKey)

Replace the repository signing key.

Source

pub fn commit_metadata(&self) -> Value<Handle<Blake3, SimpleArchive>>

Returns the repository commit metadata handle.

Source

pub fn create_branch( &mut self, branch_name: &str, commit: Option<CommitHandle>, ) -> Result<ExclusiveId, BranchError<Storage>>

Initializes a new branch in the repository. Branches are the only mutable state in the repository, and are used to represent the state of a commit chain at a specific point in time. A branch must always point to a commit, and this function can be used to create a new branch.

Creates a new branch in the repository. This branch is a pointer to a specific commit in the repository. The branch is created with name and is initialized to point to the opionally given commit. The branch is signed by the branch signing key.

§Parameters
  • branch_name - Name of the new branch.
  • commit - Commit to initialize the branch from.
Source

pub fn create_branch_with_key( &mut self, branch_name: &str, commit: Option<CommitHandle>, signing_key: SigningKey, ) -> Result<ExclusiveId, BranchError<Storage>>

Same as [branch_from] but uses the provided signing key.

Source

pub fn lookup_branch( &mut self, name: &str, ) -> Result<Option<Id>, LookupError<Storage>>

Look up a branch by name.

Iterates all branches, reads each one’s metadata, and returns the ID of the branch whose name matches. Returns Ok(None) if no branch has that name, or LookupError::NameConflict if multiple branches share it.

Source

pub fn ensure_branch( &mut self, name: &str, commit: Option<CommitHandle>, ) -> Result<Id, EnsureBranchError<Storage>>

Ensure a branch with the given name exists, creating it if necessary.

If a branch named name already exists, returns its ID. If no such branch exists, creates a new one (optionally from the given commit) and returns its ID.

Errors if multiple branches share the same name (ambiguous).

Source

pub fn pull( &mut self, branch_id: Id, ) -> Result<Workspace<Storage>, PullError<Storage::HeadError, Storage::ReaderError, <Storage::Reader as BlobStoreGet<Blake3>>::GetError<UnarchiveError>>>

Pulls an existing branch using the repository’s signing key. The workspace inherits the repository default metadata if configured.

Source

pub fn pull_with_key( &mut self, branch_id: Id, signing_key: SigningKey, ) -> Result<Workspace<Storage>, PullError<Storage::HeadError, Storage::ReaderError, <Storage::Reader as BlobStoreGet<Blake3>>::GetError<UnarchiveError>>>

Same as [pull] but overrides the signing key.

Source

pub fn push( &mut self, workspace: &mut Workspace<Storage>, ) -> Result<(), PushError<Storage>>

Pushes the workspace’s new blobs and commit to the persistent repository. This syncs the local BlobSet with the repository’s BlobStore and performs an atomic branch update (using the stored base_branch_meta).

Source

pub fn try_push( &mut self, workspace: &mut Workspace<Storage>, ) -> Result<Option<Workspace<Storage>>, PushError<Storage>>

Single-attempt push: upload local blobs and try to update the branch head once. Returns Ok(None) on success, or Ok(Some(conflict_ws)) when the branch was updated concurrently and the caller should merge.

Auto Trait Implementations§

§

impl<Storage> Freeze for Repository<Storage>
where Storage: Freeze,

§

impl<Storage> RefUnwindSafe for Repository<Storage>
where Storage: RefUnwindSafe,

§

impl<Storage> Send for Repository<Storage>
where Storage: Send,

§

impl<Storage> Sync for Repository<Storage>
where Storage: Sync,

§

impl<Storage> Unpin for Repository<Storage>
where Storage: Unpin,

§

impl<Storage> UnsafeUnpin for Repository<Storage>
where Storage: UnsafeUnpin,

§

impl<Storage> UnwindSafe for Repository<Storage>
where Storage: 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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V