pub struct Repository<Storage: BlobStore + PinStore> { /* 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 PinStore 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<F: Into<Fragment>>(
storage: Storage,
signing_key: SigningKey,
commit_metadata: F,
) -> Result<Self, <Storage as BlobStorePut>::PutError>
pub fn new<F: Into<Fragment>>( storage: Storage, signing_key: SigningKey, commit_metadata: F, ) -> Result<Self, <Storage as BlobStorePut>::PutError>
Creates a new repository with the given storage, signing key, and repo-wide commit metadata.
commit_metadata accepts anything convertible into a Fragment —
either a raw TribleSet (auto-promoted with empty blob store via
impl From<TribleSet> for Fragment), or a Fragment built up via
entity!{} / attributes!::describe() that carries auxiliary blobs
(e.g. Handle<LongString> doc strings). The Fragment’s blobs are
absorbed into storage so handles referenced by the metadata facts
stay resolvable for any downstream reader that pulls a commit and
calls Workspace::checkout_metadata.
The resulting metadata blob is referenced from every commit produced by workspaces of this repository.
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) -> Inline<Handle<SimpleArchive>>
pub fn commit_metadata(&self) -> Inline<Handle<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 Self::create_branch 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>::GetError<UnarchiveError>>>
pub fn pull( &mut self, branch_id: Id, ) -> Result<Workspace<Storage>, PullError<Storage::HeadError, Storage::ReaderError, <Storage::Reader as BlobStoreGet>::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>::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>::GetError<UnarchiveError>>>
Same as Self::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.
Sourcepub fn compute_rollup(
&mut self,
branch_id: Id,
) -> Result<Inline<Handle<SuccinctArchiveBlob>>, RollupError<Storage>>
pub fn compute_rollup( &mut self, branch_id: Id, ) -> Result<Inline<Handle<SuccinctArchiveBlob>>, RollupError<Storage>>
Builds a SuccinctArchive rollup of the branch’s current HEAD,
stores it as a blob in the underlying storage, and attaches the
resulting handle to the branch metadata via CAS.
Returns the new rollup handle on success.
Returns RollupError::HeadAdvanced if the branch HEAD moved
between pull and the CAS-update. The caller may retry — the
archive blob is content-addressed, so subsequent calls dedupe
against already-uploaded blobs.
Returns RollupError::EmptyBranch if the branch has no HEAD
commit yet (nothing to roll up).
This is the sole public write-path for rollups. The companion
read-path is Workspace::rollup.
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§
impl<T> ArchiveOwner for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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