pub struct Store { /* private fields */ }
Expand description
A database for reading and writing objects to disk, one file per object.
Implementations§
source§impl Store
impl Store
Object lookup
sourcepub fn contains(&self, id: &oid) -> bool
pub fn contains(&self, id: &oid) -> bool
Returns true if the given id is contained in our repository.
sourcepub fn lookup_prefix(
&self,
prefix: Prefix,
candidates: Option<&mut HashSet<ObjectId>>,
) -> Result<Option<Outcome>, Error>
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
.
sourcepub fn try_find<'a>(
&self,
id: &oid,
out: &'a mut Vec<u8>,
) -> Result<Option<Data<'a>>, Error>
pub fn try_find<'a>( &self, id: &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§impl Store
impl Store
Iteration and traversal
sourcepub fn iter(&self) -> Iter ⓘ
pub fn iter(&self) -> Iter ⓘ
Return an iterator over all objects contained in the database.
The Id
s 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
impl Store
sourcepub fn verify_integrity(
&self,
progress: &mut dyn DynNestedProgress,
should_interrupt: &AtomicBool,
) -> Result<Statistics, Error>
pub fn verify_integrity( &self, progress: &mut dyn DynNestedProgress, 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
impl Store
Access
sourcepub fn object_path(&self, id: &oid) -> PathBuf
pub fn object_path(&self, id: &oid) -> PathBuf
Return the path to the object with id
.
Note that is may not exist yet.
source§impl Store
impl Store
Initialization
sourcepub fn at(objects_directory: impl Into<PathBuf>, object_hash: Kind) -> Store
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.
sourcepub fn object_hash(&self) -> Kind
pub fn object_hash(&self) -> Kind
Return the kind of hash we would iterate and write.
Trait Implementations§
source§impl Write for Store
impl Write for Store
source§fn write_buf(&self, kind: Kind, from: &[u8]) -> Result<ObjectId, Error>
fn write_buf(&self, kind: Kind, from: &[u8]) -> Result<ObjectId, Error>
Write the given buffer in from
to disk in one syscall at best.
This will cost at least 4 IO operations.
impl Eq for Store
impl StructuralPartialEq for Store
Auto Trait Implementations§
impl Freeze for Store
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)