Skip to main content

Repository

Trait Repository 

Source
pub trait Repository: Send + Sync {
Show 24 methods // Required methods fn format(&self) -> &'static RepositoryFormat; fn as_any(&self) -> &dyn Any; fn all_revision_ids(&self) -> Result<Vec<Vec<u8>>, RepositoryError>; fn get_parent_map( &self, revision_ids: &[Vec<u8>], ) -> Result<HashMap<Vec<u8>, Vec<Vec<u8>>>, RepositoryError>; fn get_revision( &self, revision_id: &[u8], ) -> Result<Revision, RepositoryError>; fn get_inventory( &self, revision_id: &[u8], ) -> Result<Box<dyn Inventory>, RepositoryError>; fn get_file_text( &self, file_id: &[u8], revision: &[u8], ) -> Result<Vec<u8>, RepositoryError>; fn start_write_group(&mut self) -> Result<(), RepositoryError>; fn add_revision( &mut self, revision: &Revision, parents: &[Vec<u8>], ) -> Result<(), RepositoryError>; fn add_inventory_from_entries( &mut self, revision_id: &[u8], parents: &[Vec<u8>], root_id: &[u8], entries: &[Entry], ) -> Result<Vec<u8>, RepositoryError>; fn add_inventory_by_delta( &mut self, basis_revision_id: &[u8], delta: &InventoryDelta, new_revision_id: &[u8], parents: &[Vec<u8>], ) -> Result<Vec<u8>, RepositoryError>; fn add_text( &mut self, file_id: &[u8], revision: &[u8], parents: &[(Vec<u8>, Vec<u8>)], bytes: &[u8], ) -> Result<(), RepositoryError>; fn add_signature_text( &mut self, revision_id: &[u8], signature: &[u8], ) -> Result<(), RepositoryError>; fn get_signature_text( &self, revision_id: &[u8], ) -> Result<Option<Vec<u8>>, RepositoryError>; fn commit_write_group(&mut self) -> Result<(), RepositoryError>; // Provided methods fn try_fetch_from( &mut self, _source: &dyn Repository, _revision_ids: &[Vec<u8>], ) -> Result<bool, RepositoryError> { ... } fn has_revision(&self, revision_id: &[u8]) -> Result<bool, RepositoryError> { ... } fn revision_tree( &self, revision_id: &[u8], ) -> Result<RevisionTree, RepositoryError> { ... } fn get_file_text_at_path( &self, path: &str, revision: &[u8], ) -> Result<Vec<u8>, RepositoryError> { ... } fn pack(&mut self) -> Result<(), RepositoryError> { ... } fn autopack(&mut self) -> Result<bool, RepositoryError> { ... } fn check(&self) -> Result<CheckResult, RepositoryError> { ... } fn reconcile(&mut self) -> Result<ReconcileResult, RepositoryError> { ... } fn add_fallback_repository( &mut self, _fallback: Box<dyn Repository>, ) -> Result<(), RepositoryError> { ... }
}
Expand description

The common read interface to a bzr repository.

Object-safe: get_inventory returns Box<dyn Inventory>, so a repository can be held as Box<dyn Repository> while each format keeps its own inventory representation (a lazy CHK inventory for 2a, an in-memory one for knit-pack) behind the box — no conversion between them.

Required Methods§

Source

fn format(&self) -> &'static RepositoryFormat

The format this repository was opened as.

Source

fn as_any(&self) -> &dyn Any

Downcast support, so a backend’s format-specific fast path can recover a same-format source (e.g. another Pack2aRepository). Each backend returns self; a downcast to a different concrete type fails and the caller uses the generic path. Used by try_fetch_from implementations, not by the generic fetcher.

Source

fn all_revision_ids(&self) -> Result<Vec<Vec<u8>>, RepositoryError>

All revision ids in this repository, sorted.

Source

fn get_parent_map( &self, revision_ids: &[Vec<u8>], ) -> Result<HashMap<Vec<u8>, Vec<Vec<u8>>>, RepositoryError>

The stored parent ids of each of revision_ids, as a map. Revision ids not present in the repository are omitted from the result. The parents come straight from the revision store’s index (no body deserialisation), which is the raw graph data callers build a revision graph from.

Source

fn get_revision(&self, revision_id: &[u8]) -> Result<Revision, RepositoryError>

Read and parse a revision by id.

Source

fn get_inventory( &self, revision_id: &[u8], ) -> Result<Box<dyn Inventory>, RepositoryError>

Read the inventory for a revision.

Source

fn get_file_text( &self, file_id: &[u8], revision: &[u8], ) -> Result<Vec<u8>, RepositoryError>

Read the full text of a versioned file at a given revision.

Source

fn start_write_group(&mut self) -> Result<(), RepositoryError>

Open a write group: a batch of additions flushed atomically by Repository::commit_write_group.

Source

fn add_revision( &mut self, revision: &Revision, parents: &[Vec<u8>], ) -> Result<(), RepositoryError>

Add a revision to the open write group, serialising it with the format’s own revision serializer (bencode for 2a, XML for knit-pack).

Source

fn add_inventory_from_entries( &mut self, revision_id: &[u8], parents: &[Vec<u8>], root_id: &[u8], entries: &[Entry], ) -> Result<Vec<u8>, RepositoryError>

Build the inventory for a revision from entries and add it to the open write group, returning the inventory sha1 to record on the revision. Each format stores the inventory in its own representation (a CHK inventory for 2a, serialised XML for knit-pack).

Source

fn add_inventory_by_delta( &mut self, basis_revision_id: &[u8], delta: &InventoryDelta, new_revision_id: &[u8], parents: &[Vec<u8>], ) -> Result<Vec<u8>, RepositoryError>

Build the inventory for new_revision_id by applying delta to the already-committed basis_revision_id inventory, adding it to the open write group and returning its sha1. Formats that can share storage (2a’s CHK inventory) write only the changed pages; others fall back to re-serialising the whole inventory.

Source

fn add_text( &mut self, file_id: &[u8], revision: &[u8], parents: &[(Vec<u8>, Vec<u8>)], bytes: &[u8], ) -> Result<(), RepositoryError>

Add a file text (keyed by (file_id, revision)) to the open write group.

Source

fn add_signature_text( &mut self, revision_id: &[u8], signature: &[u8], ) -> Result<(), RepositoryError>

Add a signature text for revision_id to the open write group.

Source

fn get_signature_text( &self, revision_id: &[u8], ) -> Result<Option<Vec<u8>>, RepositoryError>

The signature text stored for revision_id, or None if unsigned.

Source

fn commit_write_group(&mut self) -> Result<(), RepositoryError>

Flush the open write group, committing its additions.

Provided Methods§

Source

fn try_fetch_from( &mut self, _source: &dyn Repository, _revision_ids: &[Vec<u8>], ) -> Result<bool, RepositoryError>

Try to copy revision_ids (topologically ordered, already filtered to revisions absent here) from source into this repository using a format-specific fast path, opening and committing the write group itself.

Returns Ok(true) if the fast path applied and the revisions were copied, Ok(false) if no fast path is available for this source/target pair (the caller then uses the generic rebuild). The default has no fast path. This is where per-format streaming lives, so crate::repository::fetch needs no knowledge of concrete formats.

Source

fn has_revision(&self, revision_id: &[u8]) -> Result<bool, RepositoryError>

Whether revision_id is present in this repository. Defaults to a single-key get_parent_map lookup; backends may override with a cheaper index probe.

Source

fn revision_tree( &self, revision_id: &[u8], ) -> Result<RevisionTree, RepositoryError>

A read-only view of the tree at revision_id: its inventory paired with the revision id. This is the basis a commit builds its inventory delta against.

Source

fn get_file_text_at_path( &self, path: &str, revision: &[u8], ) -> Result<Vec<u8>, RepositoryError>

Read the full text of the file at tree-relative path in revision, resolving the path to a file id through that revision’s inventory. Errors with RepositoryError::NoSuchRevision if path is not in the tree (reusing the closest variant for “not found”).

Source

fn pack(&mut self) -> Result<(), RepositoryError>

Combine the repository’s packs into a single pack.

The default is a no-op (formats without packs have nothing to combine); the pack backends override it.

Source

fn autopack(&mut self) -> Result<bool, RepositoryError>

Repack the smallest packs if the repository has accumulated too many, per the pack-distribution heuristic. Returns whether a repack happened.

The default is a no-op returning false; the pack backends override it.

Source

fn check(&self) -> Result<CheckResult, RepositoryError>

Check the integrity of this repository, returning a report of any inconsistencies (see CheckResult). Format-neutral: it cross-checks the data every format exposes through this trait.

Source

fn reconcile(&mut self) -> Result<ReconcileResult, RepositoryError>

Reconcile this repository: regenerate its storage keeping only the data reachable from its revisions, discarding garbage (e.g. inventories or texts left behind by an interrupted operation), and report what was dropped (see ReconcileResult).

The default does nothing (formats without packs have no garbage to collect); the pack backends override it.

Source

fn add_fallback_repository( &mut self, _fallback: Box<dyn Repository>, ) -> Result<(), RepositoryError>

Add a fallback repository consulted for objects this one lacks.

This is how a stacked branch wires its base repository in: reads that miss in this repository are retried against the fallback chain, in order. The default returns RepositoryError::UnsupportedFormat; only StackedRepository (which a stacked-branch open wraps the primary in) supports it.

Implementations§

Source§

impl dyn Repository + '_

Source

pub fn get_commit_builder( &mut self, parents: Vec<Vec<u8>>, new_revision_id: Vec<u8>, committer: String, timestamp: u64, timezone: i32, ) -> CommitBuilder<'_>

Start an incremental commit against the given parents (the first is the basis the changes are recorded against; an empty list means a first commit against the null revision). The repository must already have an open write group.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§