Skip to main content

Pack2aRepository

Struct Pack2aRepository 

Source
pub struct Pack2aRepository { /* private fields */ }
Expand description

A 2a pack repository.

Reading is available immediately after open. Writing follows breezy’s write-group lifecycle on the same object: start_write_group, then add_*, then commit_write_group. The new-pack machinery is private (the [WriteGroup]); there is no separate writer type.

Implementations§

Source§

impl Pack2aRepository

Source

pub fn open(transport: SharedTransport) -> Result<Self, RepositoryError>

Open the repository whose .bzr/repository directory is rooted at transport.

The format marker is checked against the format registry: an unrecognised marker is RepositoryError::UnknownFormat, and a recognised but non-groupcompress (or otherwise unsupported) format is RepositoryError::UnsupportedFormat.

Source

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

The format this repository was opened as.

Source

pub fn create(transport: SharedTransport) -> Result<Self, RepositoryError>

Create an empty 2a repository at transport (rooted at the .bzr/repository directory), then open it.

Writes the format marker, an empty pack-names, and the indices/ and packs/ directories.

Source

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

All revision ids stored in this repository.

Source

pub 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 (present ones only), read from the revision store’s index.

Source

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

Read and parse a revision by id.

Source

pub fn get_inventory( &self, revision_id: &[u8], ) -> Result<CHKInventory<dyn VersionedFiles + Send + Sync>, RepositoryError>

Read the CHK inventory for a revision.

Reads the serialised CHKInventory header from the inventories store, then materializes it by walking the CHK maps through the shared chk-bytes store. Read the inventory for a revision as a (lazy, read-only) CHK inventory — this repository’s natural inventory type.

Source

pub 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.

Texts are keyed by (file_id, revision) — the revision that last modified the file, as recorded in its inventory entry (not necessarily the revision being inspected).

Source

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

Open a write group: subsequent add_* calls accumulate into a new pack, made durable by commit_write_group. Errors if a write group is already open.

Source

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

Add a revision to the open write group, serialising it to bencode (the 2a revision serializer).

Source

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

Build a CHK inventory from entries and add it to the open write group, returning the inventory sha1 to record on the revision.

Source

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

Add the inventory for new_revision_id by applying delta to the basis_revision_id inventory, writing only the changed CHK pages into the open write group. Returns the new inventory’s sha1.

The basis must already be committed (its inventory is read from the existing packs); a first commit uses an empty delta against the null revision via add_inventory_from_entries instead.

Source

pub 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

pub 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

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

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

Source

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

Flush the open write group: write its pack, indices and an updated pack-names. After this, re-open the repository to read the newly committed data (the in-memory read stores are not refreshed).

Source

pub fn stream_fetch_from( &mut self, source: &Pack2aRepository, missing: &[Vec<u8>], ) -> Result<(), RepositoryError>

Stream the missing revisions from another 2a repository into this one, copying raw records (revisions, inventories, texts, CHK pages, signatures) without decoding and re-encoding them.

This is the same-format fast path for crate::repository::fetch: both sides speak groupcompress + CHK, so records copy through verbatim. The CHK pages reachable from the fetched inventories (but not already in this repository) are found with crate::chk_map::iter_interesting_nodes. missing must be in topological order (parents before children) and already filtered to revisions absent here.

Requires no open write group.

Source

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

Reconcile: regenerate the repository’s storage keeping only the data reachable from its revisions, discarding any garbage (unreachable inventories, texts or CHK pages left behind by an interrupted operation).

Streams just the reachable revisions’ records into one fresh pack, rewrites pack-names to reference only it, and moves the old packs to obsolete_packs/. Returns the number of unreachable inventories that were dropped.

Requires no open write group.

Source

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

Combine all packs in this repository into a single new pack.

Every record (revisions, inventories, CHK pages, texts, signatures) is re-streamed into one fresh pack, pack-names is rewritten to reference only the new pack, and the old packs and their indices are moved into obsolete_packs/ (not deleted). A repository that already holds a single pack is left untouched (it is already optimal).

Requires no open write group. After packing, re-open the repository to read through the new pack.

Source

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

Repack the smallest packs when the repository has accumulated too many, according to the pack-distribution heuristic.

Computes each pack’s revision count (its .rix index key count), runs plan_autopack_combinations, and if it selects packs to combine, repacks just those into one new pack, leaving the rest in place. Returns true if a repack happened.

Requires no open write group.

Trait Implementations§

Source§

impl Repository for Pack2aRepository

Source§

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

Fast path for 2a-to-2a fetch: if source is also a 2a repository, copy raw records (no decode/re-encode); otherwise decline so the generic rebuild runs.

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

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

Combine the repository’s packs into a single pack. Read more
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. Read more
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). Read more
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 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 add_fallback_repository( &mut self, _fallback: Box<dyn Repository>, ) -> Result<(), RepositoryError>

Add a fallback repository consulted for objects this one lacks. Read more

Auto Trait Implementations§

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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<T> Ungil for T
where T: Send,