Skip to main content

IndexedRepository

Struct IndexedRepository 

Source
pub struct IndexedRepository<'index, 'objects, R: Repository + ?Sized> { /* private fields */ }
Expand description

Index a stable repository without allocating or copying object bodies.

Construction reads the source count once, reads and hashes each object once, and sorts an ID index in place. Subsequent object enumeration and ID access are O(1); lookup by ID is O(log n). Object order, HEAD, and refs are preserved. The source still owns the bodies and must satisfy Repository’s stability contract. It must expose borrowed bodies through object; this wrapper does not index streaming-only providers, validate object graphs, or deduplicate them.

Implementations§

Source§

impl<'index, 'objects, R: Repository + ?Sized> IndexedRepository<'index, 'objects, R>

Source

pub fn new( repository: &'objects R, object_storage: &'index mut [Option<ObjectMetadata<'objects>>], index_storage: &'index mut [usize], ) -> Result<Self>

Both arrays need at least repository.object_count() elements. Extra slots are untouched. Initialize metadata with [None; N]. Insufficient capacity fails before reading any object. A missing source object returns ObjectNotFound; discard partial arrays after an error.

use git_zero_core::{File, IndexedRepository, Repository, Snapshot};

let files = [File { name: "hello", contents: b"hello\n" }];
let mut tree = [0; 128];
let mut commit = [0; 256];
let snapshot = Snapshot::new(&files, &mut tree, &mut commit)?;
let mut objects = [None; 3]; // Commit, tree, and blob.
let mut by_id = [0; 3];
let indexed = IndexedRepository::new(&snapshot, &mut objects, &mut by_id)?;
assert_eq!(indexed.find(indexed.head()).unwrap().kind,
           git_zero_core::ObjectKind::Commit);
Source

pub fn metadata(&self, index: usize) -> Option<&ObjectMetadata<'objects>>

Metadata in the source repository’s enumeration order.

Trait Implementations§

Source§

impl<R: Repository + ?Sized> Repository for IndexedRepository<'_, '_, R>

Source§

fn object_format(&self) -> ObjectFormat

Fixed for the entire repository, including unborn HEAD. Defaults to SHA-1; SHA-256 providers must override this independently of object_id.
Source§

fn head(&self) -> ObjectId

Resolved commit ID, or the all-zero sentinel for an unborn HEAD. Use head_state().id() when absence needs to be distinguished.
Source§

fn head_state(&self) -> Head<'_>

Source§

fn object_count(&self) -> usize

Source§

fn object(&self, index: usize) -> Option<Object<'_>>

Optional borrowed-body fast path. Streaming providers can leave this as None and implement object_info, read_object, and object_id instead.
Source§

fn object_id(&self, index: usize) -> Option<ObjectId>

Return an object’s ID. Streaming providers must supply precomputed IDs; ObjectHasher computes them incrementally with caller-owned scratch.
Source§

fn head_ref(&self) -> &str

Source§

fn reference_count(&self) -> usize

Source§

fn reference_name(&self, index: usize) -> Option<&str>

Source§

fn reference_id(&self, index: usize) -> Option<ObjectId>

Defaults preserve snapshot commit aliases. Override for independent tips.
Source§

fn reference_symbolic_target(&self, index: usize) -> Option<&str>

Source§

fn reference_peeled(&self, index: usize) -> Option<ObjectId>

Source§

fn find_index(&self, id: ObjectId) -> Option<usize>

Lookup without requiring a borrowed body. Metadata providers can index it.
Source§

fn object_info(&self, index: usize) -> Result<ObjectInfo>

Source§

fn read_object( &self, index: usize, offset: u64, storage: &mut [u8], ) -> Result<usize>

Read at most storage.len() body bytes starting at a byte offset. Short reads are allowed. Return zero only at EOF or for empty storage. Calls must be independent of earlier reads, enabling interleaved readers and retries. Errors may modify storage but must not change the object.
Source§

fn find(&self, id: ObjectId) -> Option<Object<'_>>

Auto Trait Implementations§

§

impl<'index, 'objects, R> Freeze for IndexedRepository<'index, 'objects, R>
where &'objects R: Freeze, R: ?Sized,

§

impl<'index, 'objects, R> RefUnwindSafe for IndexedRepository<'index, 'objects, R>

§

impl<'index, 'objects, R> Send for IndexedRepository<'index, 'objects, R>
where &'objects R: Send, R: ?Sized,

§

impl<'index, 'objects, R> Sync for IndexedRepository<'index, 'objects, R>
where &'objects R: Sync, R: ?Sized,

§

impl<'index, 'objects, R> Unpin for IndexedRepository<'index, 'objects, R>
where &'objects R: Unpin, R: ?Sized,

§

impl<'index, 'objects, R> UnsafeUnpin for IndexedRepository<'index, 'objects, R>

§

impl<'index, 'objects, R> UnwindSafe for IndexedRepository<'index, 'objects, R>

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.