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
impl Pack2aRepository
Sourcepub fn open(transport: SharedTransport) -> Result<Self, RepositoryError>
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.
Sourcepub fn format(&self) -> &'static RepositoryFormat
pub fn format(&self) -> &'static RepositoryFormat
The format this repository was opened as.
Sourcepub fn create(transport: SharedTransport) -> Result<Self, RepositoryError>
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.
Sourcepub fn all_revision_ids(&self) -> Result<Vec<Vec<u8>>, RepositoryError>
pub fn all_revision_ids(&self) -> Result<Vec<Vec<u8>>, RepositoryError>
All revision ids stored in this repository.
Sourcepub fn get_parent_map(
&self,
revision_ids: &[Vec<u8>],
) -> Result<HashMap<Vec<u8>, Vec<Vec<u8>>>, RepositoryError>
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.
Sourcepub fn get_revision(
&self,
revision_id: &[u8],
) -> Result<Revision, RepositoryError>
pub fn get_revision( &self, revision_id: &[u8], ) -> Result<Revision, RepositoryError>
Read and parse a revision by id.
Sourcepub fn get_inventory(
&self,
revision_id: &[u8],
) -> Result<CHKInventory<dyn VersionedFiles + Send + Sync>, RepositoryError>
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.
Sourcepub fn get_file_text(
&self,
file_id: &[u8],
revision: &[u8],
) -> Result<Vec<u8>, RepositoryError>
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).
Sourcepub fn start_write_group(&mut self) -> Result<(), RepositoryError>
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.
Sourcepub fn add_revision(
&mut self,
revision: &Revision,
parents: &[Vec<u8>],
) -> Result<(), RepositoryError>
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).
Sourcepub fn add_inventory_from_entries(
&mut self,
revision_id: &[u8],
parents: &[Vec<u8>],
root_id: &[u8],
entries: &[Entry],
) -> Result<Vec<u8>, RepositoryError>
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.
Sourcepub fn add_inventory_by_delta(
&mut self,
basis_revision_id: &[u8],
delta: &InventoryDelta,
new_revision_id: &[u8],
parents: &[Vec<u8>],
) -> Result<Vec<u8>, RepositoryError>
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.
Sourcepub fn add_text(
&mut self,
file_id: &[u8],
revision: &[u8],
parents: &[(Vec<u8>, Vec<u8>)],
bytes: &[u8],
) -> Result<(), RepositoryError>
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.
Sourcepub fn add_signature_text(
&mut self,
revision_id: &[u8],
signature: &[u8],
) -> Result<(), RepositoryError>
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.
Sourcepub fn get_signature_text(
&self,
revision_id: &[u8],
) -> Result<Option<Vec<u8>>, RepositoryError>
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.
Sourcepub fn commit_write_group(&mut self) -> Result<(), RepositoryError>
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).
Sourcepub fn stream_fetch_from(
&mut self,
source: &Pack2aRepository,
missing: &[Vec<u8>],
) -> Result<(), RepositoryError>
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.
Sourcepub fn reconcile(&mut self) -> Result<ReconcileResult, RepositoryError>
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.
Sourcepub fn pack(&mut self) -> Result<(), RepositoryError>
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.
Sourcepub fn autopack(&mut self) -> Result<bool, RepositoryError>
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
impl Repository for Pack2aRepository
Source§fn try_fetch_from(
&mut self,
source: &dyn Repository,
revision_ids: &[Vec<u8>],
) -> Result<bool, RepositoryError>
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
fn format(&self) -> &'static RepositoryFormat
Source§fn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
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>
fn all_revision_ids(&self) -> Result<Vec<Vec<u8>>, RepositoryError>
Source§fn get_parent_map(
&self,
revision_ids: &[Vec<u8>],
) -> Result<HashMap<Vec<u8>, Vec<Vec<u8>>>, RepositoryError>
fn get_parent_map( &self, revision_ids: &[Vec<u8>], ) -> Result<HashMap<Vec<u8>, Vec<Vec<u8>>>, RepositoryError>
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>
fn get_revision(&self, revision_id: &[u8]) -> Result<Revision, RepositoryError>
Source§fn get_inventory(
&self,
revision_id: &[u8],
) -> Result<Box<dyn Inventory>, RepositoryError>
fn get_inventory( &self, revision_id: &[u8], ) -> Result<Box<dyn Inventory>, RepositoryError>
Source§fn get_file_text(
&self,
file_id: &[u8],
revision: &[u8],
) -> Result<Vec<u8>, RepositoryError>
fn get_file_text( &self, file_id: &[u8], revision: &[u8], ) -> Result<Vec<u8>, RepositoryError>
Source§fn start_write_group(&mut self) -> Result<(), RepositoryError>
fn start_write_group(&mut self) -> Result<(), RepositoryError>
Repository::commit_write_group.Source§fn add_revision(
&mut self,
revision: &Revision,
parents: &[Vec<u8>],
) -> Result<(), RepositoryError>
fn add_revision( &mut self, revision: &Revision, parents: &[Vec<u8>], ) -> Result<(), RepositoryError>
Source§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_from_entries( &mut self, revision_id: &[u8], parents: &[Vec<u8>], root_id: &[u8], entries: &[Entry], ) -> Result<Vec<u8>, RepositoryError>
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>
fn add_inventory_by_delta( &mut self, basis_revision_id: &[u8], delta: &InventoryDelta, new_revision_id: &[u8], parents: &[Vec<u8>], ) -> Result<Vec<u8>, RepositoryError>
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>
fn add_text( &mut self, file_id: &[u8], revision: &[u8], parents: &[(Vec<u8>, Vec<u8>)], bytes: &[u8], ) -> Result<(), RepositoryError>
(file_id, revision)) to the open write
group.Source§fn add_signature_text(
&mut self,
revision_id: &[u8],
signature: &[u8],
) -> Result<(), RepositoryError>
fn add_signature_text( &mut self, revision_id: &[u8], signature: &[u8], ) -> Result<(), RepositoryError>
revision_id to the open write group.Source§fn get_signature_text(
&self,
revision_id: &[u8],
) -> Result<Option<Vec<u8>>, RepositoryError>
fn get_signature_text( &self, revision_id: &[u8], ) -> Result<Option<Vec<u8>>, RepositoryError>
revision_id, or None if unsigned.Source§fn commit_write_group(&mut self) -> Result<(), RepositoryError>
fn commit_write_group(&mut self) -> Result<(), RepositoryError>
Source§fn pack(&mut self) -> Result<(), RepositoryError>
fn pack(&mut self) -> Result<(), RepositoryError>
Source§fn autopack(&mut self) -> Result<bool, RepositoryError>
fn autopack(&mut self) -> Result<bool, RepositoryError>
Source§fn reconcile(&mut self) -> Result<ReconcileResult, RepositoryError>
fn reconcile(&mut self) -> Result<ReconcileResult, RepositoryError>
ReconcileResult). Read moreSource§fn has_revision(&self, revision_id: &[u8]) -> Result<bool, RepositoryError>
fn has_revision(&self, revision_id: &[u8]) -> Result<bool, RepositoryError>
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>
fn revision_tree( &self, revision_id: &[u8], ) -> Result<RevisionTree, RepositoryError>
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>
fn get_file_text_at_path( &self, path: &str, revision: &[u8], ) -> Result<Vec<u8>, RepositoryError>
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>
fn check(&self) -> Result<CheckResult, RepositoryError>
CheckResult). Format-neutral: it cross-checks
the data every format exposes through this trait.