Skip to main content

File

Struct File 

Source
pub struct File<T = MMap> { /* private fields */ }
Expand description

A representation of a pack index file

Implementations§

Source§

impl File<MMap>

Instantiation

Source

pub fn at(path: impl AsRef<Path>, object_hash: Kind) -> Result<Self, Error>

Open the pack index file at the given path.

The object_hash is a way to read (and write) the same file format with different hashes, as the hash kind isn’t stored within the file format itself.

Source§

impl<T> File<T>
where T: FileData,

Source

pub fn from_data( data: T, path: PathBuf, object_hash: Kind, ) -> Result<Self, Error>

Instantiate an index file from data as assumed to be read or memory-mapped from path.

Source§

impl<T> File<T>
where T: FileData,

Iteration and access

Source

pub fn oid_at_index(&self, index: EntryIndex) -> &oid

Returns the object hash at the given index in our list of (sorted) sha1 hashes. The index ranges from 0 to self.num_objects()

§Panics

If index is out of bounds.

Source

pub fn pack_offset_at_index(&self, index: EntryIndex) -> Offset

Returns the offset into our pack data file at which to start reading the object at index.

§Panics

If index is out of bounds.

Source

pub fn crc32_at_index(&self, index: EntryIndex) -> Option<u32>

Returns the CRC32 of the object at the given index.

Note: These are always present for index version 2 or higher.

§Panics

If index is out of bounds.

Source

pub fn lookup(&self, id: impl AsRef<oid>) -> Option<EntryIndex>

Returns the index of the given hash for use with the oid_at_index(), pack_offset_at_index() or crc32_at_index().

Source

pub fn lookup_prefix( &self, prefix: Prefix, candidates: Option<&mut Range<EntryIndex>>, ) -> Option<PrefixLookupResult>

Given a prefix, find an object that matches it uniquely within this index and return Some(Ok(entry_index)). If there is more than one object matching the object Some(Err(()) is returned.

Finally, if no object matches the index, the return value is None.

Pass candidates to obtain the set of entry-indices matching prefix, with the same return value as one would have received if it remained None. It will be empty if no object matched the prefix.

Source

pub fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = Entry> + 'a>

An iterator over all Entries of this index file.

Source

pub fn sorted_offsets(&self) -> Vec<Offset>

Return a vector of ascending offsets into our respective pack data file.

Useful to control an iteration over all pack entries in a cache-friendly way.

Source§

impl<T> File<T>
where T: FileData + Sync,

Traversal with index

Source

pub fn traverse_with_index<Processor, E, D>( &self, pack: &File<D>, processor: Processor, progress: &mut dyn DynNestedProgress, should_interrupt: &AtomicBool, _: Options, ) -> Result<Outcome, Error<E>>
where Processor: FnMut(Kind, &[u8], &Entry, &dyn Progress) -> Result<(), E> + Send + Clone, E: Error + Send + Sync + 'static, D: FileData + Send + Sync,

Iterate through all decoded objects in the given pack and handle them with a Processor, using an index to reduce waste at the cost of memory.

For more details, see the documentation on the traverse() method.

Source§

impl<T> File<T>
where T: FileData + Sync,

Verify and validate the content of the index file

Source

pub fn traverse_with_lookup<C, Processor, E, F, D>( &self, processor: Processor, pack: &File<D>, progress: &mut dyn DynNestedProgress, should_interrupt: &AtomicBool, _: Options<F>, ) -> Result<Outcome, Error<E>>
where C: DecodeEntry, E: Error + Send + Sync + 'static, Processor: FnMut(Kind, &[u8], &Entry, &dyn Progress) -> Result<(), E> + Send + Clone, F: Fn() -> C + Send + Clone, D: FileData + Send + Sync,

Iterate through all decoded objects in the given pack and handle them with a Processor using a cache to reduce the amount of waste while decoding objects.

For more details, see the documentation on the traverse() method.

Source§

impl<T> File<T>
where T: FileData + Sync,

Traversal of pack data files using an index file

Source

pub fn traverse<C, Processor, E, F, D>( &self, pack: &File<D>, progress: &mut dyn DynNestedProgress, should_interrupt: &AtomicBool, processor: Processor, _: Options<F>, ) -> Result<Outcome, Error<E>>
where C: DecodeEntry, E: Error + Send + Sync + 'static, Processor: FnMut(Kind, &[u8], &Entry, &dyn Progress) -> Result<(), E> + Send + Clone, F: Fn() -> C + Send + Clone, D: FileData + Send + Sync,

Iterate through all decoded objects in the given pack and handle them with a Processor. The return value is (pack-checksum, Outcome, progress), thus the pack traversal will always verify the whole packs checksum to assure it was correct. In case of bit-rod, the operation will abort early without verifying all objects using the interrupt mechanism mechanism.

§Algorithms

Using the Options::traversal field one can chose between two algorithms providing different tradeoffs. Both invoke new_processor() to create functions receiving decoded objects, their object kind, index entry and a progress instance to provide progress information.

Use thread_limit to further control parallelism and check to define how much the passed objects shall be verified beforehand.

Source§

impl<T> File<T>
where T: FileData + Sync,

Verify and validate the content of the index file

Source

pub fn index_checksum(&self) -> ObjectId

Returns the trailing hash stored at the end of this index file.

It’s a hash over all bytes of the index.

Source

pub fn pack_checksum(&self) -> ObjectId

Returns the hash of the pack data file that this index file corresponds to.

It should crate::data::File::checksum() of the corresponding pack data file.

Source

pub fn verify_checksum( &self, progress: &mut dyn Progress, should_interrupt: &AtomicBool, ) -> Result<ObjectId, Error>

Validate that our index_checksum() matches the actual contents of this index file, and return it if it does.

Source

pub fn verify_integrity<C, F, D>( &self, pack: Option<PackContext<'_, F, D>>, progress: &mut dyn DynNestedProgress, should_interrupt: &AtomicBool, ) -> Result<Outcome, Error<Error>>
where C: DecodeEntry, F: Fn() -> C + Send + Clone, D: FileData + Send + Sync,

The most thorough validation of integrity of both index file and the corresponding pack data file, if provided. Returns the checksum of the index file, the traversal outcome and the given progress if the integrity check is successful.

If pack is provided, it is expected (and validated to be) the pack belonging to this index. It will be used to validate internal integrity of the pack before checking each objects integrity is indeed as advertised via its SHA1 as stored in this index, as well as the CRC32 hash. The last member of the Option is a function returning an implementation of crate::cache::DecodeEntry to be used if the index::traverse::Algorithm is Lookup. To set this to None, use None::<(_, _, _, fn() -> crate::cache::Never)>.

The thread_limit optionally specifies the amount of threads to be used for the pack traversal. make_cache is only used in case a pack is specified, use existing implementations in the crate::cache module.

§Tradeoffs

The given progress is inevitably consumed if there is an error, which is a tradeoff chosen to easily allow using ? in the error case.

Source§

impl<T> File<T>
where T: FileData,

Basic file information

Source

pub fn version(&self) -> Version

The version of the pack index

Source

pub fn path(&self) -> &Path

The path of the opened index file

Source

pub fn num_objects(&self) -> EntryIndex

The amount of objects stored in the pack and index, as one past the highest entry index.

Source

pub fn object_hash(&self) -> Kind

The kind of hash we assume

Auto Trait Implementations§

§

impl<T> Freeze for File<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for File<T>
where T: RefUnwindSafe,

§

impl<T> Send for File<T>
where T: Send,

§

impl<T> Sync for File<T>
where T: Sync,

§

impl<T> Unpin for File<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for File<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for File<T>
where T: UnwindSafe,

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.