Skip to main content

FileRepository

Struct FileRepository 

Source
pub struct FileRepository<'a> { /* private fields */ }
Expand description

A caller-owned manifest of immutable file-backed objects and commit aliases.

No filesystem scan, allocation, or object-sized buffer is needed. Keep the FileObject array alive; each element owns one descriptor. Object enumeration follows manifest order; lookup is linear unless wrapped in ValidatedRepository. Construction does not check IDs or graph closure. Those remain Repository preconditions until checked with the core validator.

Implementations§

Source§

impl<'a> FileRepository<'a>

Source

pub fn new(head: ObjectId, objects: &'a [FileObject]) -> Self

Source

pub fn with_refs(self, head_ref: &'a str, refs: &'a [&'a str]) -> Result<Self>

Advertise sorted, unique refs that all alias head, including head_ref.

Source

pub fn with_detached_head(self, refs: &'a [&'a str]) -> Result<Self>

Serve a direct commit HEAD without a symbolic branch. Refs remain aliases of that commit, and may be empty. The graph still needs core validation.

Source

pub fn with_prepacked( self, fd: OwnedFd, object_scratch: &mut [u8], compare_scratch: &mut [u8], ) -> Result<Self>

Attach an immutable, already-generated complete pack in a regular file. Compare every byte with pack::write_with_scratch, including framing, object closure/order, encoder bytes and checksum, before accepting it. Only this encoder’s exact output is accepted; arbitrary compressed/delta packs remain future work. No pack-sized buffer is needed. Both scratch buffers need at least one byte for nonempty streamed data. A mismatch, extra/truncated bytes or a nonregular file returns CorruptPack. Verification costs one encoding pass; subsequent writes only read the pack file. Refs may change afterwards without changing pack identity.

Source

pub fn has_prepacked(&self) -> bool

Source

pub fn write_pack_with_scratch( &self, scratch: &mut [u8], output: &mut impl Write, ) -> Result<()>

Stream the verified stored pack, or generate one from the raw files. Scratch needs at least one byte. Discard partial output on error.

Source

pub fn serve_with_scratch( &self, request: Request<'_>, scratch: &mut [u8], output: &mut impl Write, ) -> Result<Response>

Core HTTP routes with verified prepacked reuse for upload-pack responses. Dumb loose objects continue to be encoded from their raw file bodies. Use core http::serve_with_pack to pair this writer with a validated index.

Trait Implementations§

Source§

impl Repository for FileRepository<'_>

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_info(&self, index: usize) -> Result<ObjectInfo>

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 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 head_ref(&self) -> &str

Source§

fn reference_count(&self) -> usize

Source§

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

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 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(&self, id: ObjectId) -> Option<Object<'_>>

Source§

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

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

Auto Trait Implementations§

§

impl<'a> Freeze for FileRepository<'a>

§

impl<'a> RefUnwindSafe for FileRepository<'a>

§

impl<'a> Send for FileRepository<'a>

§

impl<'a> Sync for FileRepository<'a>

§

impl<'a> Unpin for FileRepository<'a>

§

impl<'a> UnsafeUnpin for FileRepository<'a>

§

impl<'a> UnwindSafe for FileRepository<'a>

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.