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.