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>
impl<'a> FileRepository<'a>
pub fn new(head: ObjectId, objects: &'a [FileObject]) -> Self
Sourcepub fn with_refs(self, head_ref: &'a str, refs: &'a [&'a str]) -> Result<Self>
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.
Sourcepub fn with_detached_head(self, refs: &'a [&'a str]) -> Result<Self>
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.
Sourcepub fn with_prepacked(
self,
fd: OwnedFd,
object_scratch: &mut [u8],
compare_scratch: &mut [u8],
) -> Result<Self>
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.
pub fn has_prepacked(&self) -> bool
Sourcepub fn write_pack_with_scratch(
&self,
scratch: &mut [u8],
output: &mut impl Write,
) -> Result<()>
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.
Sourcepub fn serve_with_scratch(
&self,
request: Request<'_>,
scratch: &mut [u8],
output: &mut impl Write,
) -> Result<Response>
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<'_>
impl Repository for FileRepository<'_>
Source§fn object_format(&self) -> ObjectFormat
fn object_format(&self) -> ObjectFormat
object_id.Source§fn head(&self) -> ObjectId
fn head(&self) -> ObjectId
head_state().id() when absence needs to be distinguished.fn head_state(&self) -> Head<'_>
fn object_count(&self) -> usize
fn object_info(&self, index: usize) -> Result<ObjectInfo>
Source§fn object_id(&self, index: usize) -> Option<ObjectId>
fn object_id(&self, index: usize) -> Option<ObjectId>
ObjectHasher computes them incrementally with caller-owned scratch.Source§fn read_object(
&self,
index: usize,
offset: u64,
storage: &mut [u8],
) -> Result<usize>
fn read_object( &self, index: usize, offset: u64, storage: &mut [u8], ) -> Result<usize>
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.fn head_ref(&self) -> &str
fn reference_count(&self) -> usize
fn reference_name(&self, index: usize) -> Option<&str>
Source§fn object(&self, _index: usize) -> Option<Object<'_>>
fn object(&self, _index: usize) -> Option<Object<'_>>
None and implement object_info, read_object, and object_id instead.