Struct git_odb::loose::Store

source ·
pub struct Store { /* private fields */ }
Expand description

A database for reading and writing objects to disk, one file per object.

Implementations§

source§

impl Store

Object lookup

source

pub fn contains(&self, id: impl AsRef<oid>) -> bool

Returns true if the given id is contained in our repository.

source

pub fn lookup_prefix( &self, prefix: Prefix, candidates: Option<&mut HashSet<ObjectId>> ) -> Result<Option<Outcome>, Error>

Given a prefix, find an object that matches it uniquely within this loose object database as Ok(Some(Ok(<oid>))). If there is more than one object matching the object Ok(Some(Err(())) is returned.

Finally, if no object matches, the return value is Ok(None).

The outer Result is to indicate errors during file system traversal.

Pass candidates to obtain the set of all object ids matching prefix, with the same return value as one would have received if it remained None.

source

pub fn try_find<'a>( &self, id: impl AsRef<oid>, out: &'a mut Vec<u8> ) -> Result<Option<Data<'a>>, Error>

Return the object identified by the given ObjectId if present in this database, writing its raw data into the given out buffer.

Returns Err if there was an error locating or reading the object. Returns Ok<None> if there was no such object.

source

pub fn try_header( &self, id: impl AsRef<oid> ) -> Result<Option<(usize, Kind)>, Error>

Return only the decompressed size of the object and its kind without fully reading it into memory as tuple of (size, kind). Returns None if id does not exist in the database.

source§

impl Store

Iteration and traversal

source

pub fn iter(&self) -> Iter

Return an iterator over all objects contained in the database.

The Ids returned by the iterator can typically be used in the locate(…) method. Note that the result is not sorted or stable, thus ordering can change between runs.

Notes

loose::Iter is used instead of impl Iterator<…> to allow using this iterator in struct fields, as is currently needed if iterators need to be implemented by hand in the absence of generators.

source§

impl Store

source

pub fn verify_integrity( &self, progress: impl Progress, should_interrupt: &AtomicBool ) -> Result<Statistics, Error>

Check all loose objects for their integrity checking their hash matches the actual data and by decoding them fully.

source§

impl Store

Initialization

source

pub fn at(objects_directory: impl Into<PathBuf>, object_hash: Kind) -> Store

Initialize the Db with the objects_directory containing the hexadecimal first byte subdirectories, which in turn contain all loose objects.

In a git repository, this would be .git/objects.

The object_hash determines which hash to use when writing, finding or iterating objects.

source

pub fn path(&self) -> &Path

Return the path to our objects directory.

source

pub fn object_hash(&self) -> Kind

Return the kind of hash we would iterate and write.

Trait Implementations§

source§

impl Clone for Store

source§

fn clone(&self) -> Store

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl PartialEq<Store> for Store

source§

fn eq(&self, other: &Store) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Write for Store

source§

fn write_buf(&self, kind: Kind, from: &[u8]) -> Result<ObjectId, Self::Error>

Write the given buffer in from to disk in one syscall at best.

This will cost at least 4 IO operations.

source§

fn write_stream( &self, kind: Kind, size: u64, from: impl Read ) -> Result<ObjectId, Self::Error>

Write the given stream in from to disk with at least one syscall.

This will cost at least 4 IO operations.

§

type Error = Error

The error type used for all trait methods. Read more
source§

fn write(&self, object: impl WriteTo) -> Result<ObjectId, Self::Error>

Write objects using the intrinsic kind of hash into the database, returning id to reference it in subsequent reads.
source§

impl Eq for Store

source§

impl StructuralEq for Store

source§

impl StructuralPartialEq for Store

Auto Trait Implementations§

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnwindSafe for Store

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.