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>
impl<Storage> Repository<Storage>
Sourcepub fn close(self) -> Result<(), <Storage as StorageClose>::Error>
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>
impl<Storage> Repository<Storage>
Sourcepub fn new(
storage: Storage,
signing_key: SigningKey,
commit_metadata: TribleSet,
) -> Result<Self, <Storage as BlobStorePut<Blake3>>::PutError>
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.
Sourcepub fn into_storage(self) -> Storage
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.
Sourcepub fn storage_mut(&mut self) -> &mut Storage
pub fn storage_mut(&mut self) -> &mut Storage
Borrow the underlying storage backend mutably.
Sourcepub fn set_signing_key(&mut self, signing_key: SigningKey)
pub fn set_signing_key(&mut self, signing_key: SigningKey)
Replace the repository signing key.
Sourcepub fn commit_metadata(&self) -> Value<Handle<Blake3, SimpleArchive>>
pub fn commit_metadata(&self) -> Value<Handle<Blake3, SimpleArchive>>
Returns the repository commit metadata handle.
Sourcepub fn create_branch(
&mut self,
branch_name: &str,
commit: Option<CommitHandle>,
) -> Result<ExclusiveId, BranchError<Storage>>
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.
Sourcepub fn create_branch_with_key(
&mut self,
branch_name: &str,
commit: Option<CommitHandle>,
signing_key: SigningKey,
) -> Result<ExclusiveId, BranchError<Storage>>
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.
Sourcepub fn lookup_branch(
&mut self,
name: &str,
) -> Result<Option<Id>, LookupError<Storage>>
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.
Sourcepub fn ensure_branch(
&mut self,
name: &str,
commit: Option<CommitHandle>,
) -> Result<Id, EnsureBranchError<Storage>>
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).
Sourcepub fn pull(
&mut self,
branch_id: Id,
) -> Result<Workspace<Storage>, PullError<Storage::HeadError, Storage::ReaderError, <Storage::Reader as BlobStoreGet<Blake3>>::GetError<UnarchiveError>>>
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.
Sourcepub 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>>>
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.
Sourcepub fn push(
&mut self,
workspace: &mut Workspace<Storage>,
) -> Result<(), PushError<Storage>>
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).
Sourcepub fn try_push(
&mut self,
workspace: &mut Workspace<Storage>,
) -> Result<Option<Workspace<Storage>>, PushError<Storage>>
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> 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> 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