pub struct Handle<S>{
pub refresh: RefreshMode,
pub max_recursion_depth: usize,
pub ignore_replacements: bool,
/* private fields */
}
Expand description
This effectively acts like a handle but exists to be usable from the actual crate::Handle
implementation which adds caches on top.
Each store is quickly cloned and contains thread-local state for shared packs.
Fields§
§refresh: RefreshMode
Defines what happens when there is no more indices to load.
max_recursion_depth: usize
The maximum recursion depth for resolving ref-delta base objects, that is objects referring to other objects within a pack. Recursive loops are possible only in purposefully crafted packs. This value doesn’t have to be huge as in typical scenarios, these kind of objects are rare and chains supposedly are even more rare.
ignore_replacements: bool
If true, replacements will not be performed even if these are available.
Implementations§
source§impl<S> Handle<S>
impl<S> Handle<S>
sourcepub fn packed_object_count(&self) -> Result<u64, Error>
pub fn packed_object_count(&self) -> Result<u64, Error>
Return the exact number of packed objects after loading all currently available indices as last seen on disk.
sourcepub fn disambiguate_prefix(
&self,
candidate: Candidate,
) -> Result<Option<Prefix>, Error>
pub fn disambiguate_prefix( &self, candidate: Candidate, ) -> Result<Option<Prefix>, Error>
Given a prefix candidate
with an object id and an initial hex_len
, check if it only matches a single
object within the entire object database and increment its hex_len
by one until it is unambiguous.
Return Ok(None)
if no object with that prefix exists.
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>
Find the only object matching prefix
and return it as Ok(Some(Ok(<ObjectId>)))
, or return Ok(Some(Err(()))
if multiple different objects with the same prefix were found.
Return Ok(None)
if no object matched the prefix
.
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
.
§Performance Note
- Unless the handles refresh mode is set to
Never
, each lookup will trigger a refresh of the object databases files on disk if the prefix doesn’t lead to ambiguous results. - Since all objects need to be examined to assure non-ambiguous return values, after calling this method all indices will be loaded.
- If
candidates
isSome(…)
, the traversal will continue to obtain all candidates, which takes more time as there is no early abort.
source§impl<S> Handle<S>
impl<S> Handle<S>
sourcepub fn iter(&self) -> Result<AllObjects, Error>
pub fn iter(&self) -> Result<AllObjects, Error>
Return an iterator over all, possibly duplicate, objects, first the ones in all packs of all linked databases (via alternates), followed by all loose objects.
source§impl<S> Handle<S>
impl<S> Handle<S>
sourcepub fn prevent_pack_unload(&mut self)
pub fn prevent_pack_unload(&mut self)
Call once if pack ids are stored and later used for lookup, meaning they should always remain mapped and not be unloaded even if they disappear from disk. This must be called if there is a chance that git maintenance is happening while a pack is created.
sourcepub fn refresh_never(&mut self)
pub fn refresh_never(&mut self)
Set the handle to never cause ODB refreshes if an object could not be found.
The latter is the default, as typically all objects referenced in a git repository are contained in the local clone. More recently, however, this doesn’t always have to be the case due to sparse checkouts and other ways to only have a limited amount of objects available locally.
sourcepub fn refresh_mode(&mut self) -> RefreshMode
pub fn refresh_mode(&mut self) -> RefreshMode
Return the current refresh mode.
Trait Implementations§
source§impl<S> Find for Handle<S>
impl<S> Find for Handle<S>
source§fn try_find_cached<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
pack_cache: &mut dyn DecodeEntry,
) -> Result<Option<(Data<'a>, Option<Location>)>, Error>
fn try_find_cached<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, pack_cache: &mut dyn DecodeEntry, ) -> Result<Option<(Data<'a>, Option<Location>)>, Error>
Find::try_find()
, but with support for controlling the pack cache.
A pack_cache
can be used to speed up subsequent lookups, set it to crate::cache::Never
if the
workload isn’t suitable for caching. Read moresource§fn location_by_oid(&self, id: &oid, buf: &mut Vec<u8>) -> Option<Location>
fn location_by_oid(&self, id: &oid, buf: &mut Vec<u8>) -> Option<Location>
id
can be found in the database, or None
if there is no pack
holding the object. Read moresource§fn pack_offsets_and_oid(&self, pack_id: u32) -> Option<Vec<(u64, ObjectId)>>
fn pack_offsets_and_oid(&self, pack_id: u32) -> Option<Vec<(u64, ObjectId)>>
source§fn try_find<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<Option<(Data<'a>, Option<Location>)>, Box<dyn Error + Send + Sync>>
fn try_find<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<Option<(Data<'a>, Option<Location>)>, Box<dyn Error + Send + Sync>>
id
in the database while placing its raw, decoded data into buffer
.
A pack_cache
can be used to speed up subsequent lookups, set it to crate::cache::Never
if the
workload isn’t suitable for caching. Read moresource§impl<S> Write for Handle<S>
impl<S> Write for Handle<S>
source§fn write_stream(
&self,
kind: Kind,
size: u64,
from: &mut dyn Read,
) -> Result<ObjectId, Error>
fn write_stream( &self, kind: Kind, size: u64, from: &mut dyn Read, ) -> Result<ObjectId, Error>
write
, but takes an input stream.
This is commonly used for writing blobs directly without reading them to memory first.Auto Trait Implementations§
impl<S> !Freeze for Handle<S>
impl<S> !RefUnwindSafe for Handle<S>
impl<S> Send for Handle<S>where
S: Send,
impl<S> !Sync for Handle<S>
impl<S> Unpin for Handle<S>where
S: Unpin,
impl<S> UnwindSafe for Handle<S>where
S: UnwindSafe,
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> FindExt for T
impl<T> FindExt for T
source§fn find<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<(Data<'a>, Option<Location>), Error>
fn find<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<(Data<'a>, Option<Location>), Error>
try_find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error.source§fn find_commit<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<(CommitRef<'a>, Option<Location>), Error>
fn find_commit<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<(CommitRef<'a>, Option<Location>), Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.source§fn find_tree<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<(TreeRef<'a>, Option<Location>), Error>
fn find_tree<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<(TreeRef<'a>, Option<Location>), Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.source§fn find_tag<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<(TagRef<'a>, Option<Location>), Error>
fn find_tag<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<(TagRef<'a>, Option<Location>), Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.source§fn find_blob<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<(BlobRef<'a>, Option<Location>), Error>
fn find_blob<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<(BlobRef<'a>, Option<Location>), Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.source§fn find_commit_iter<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<(CommitRefIter<'a>, Option<Location>), Error>
fn find_commit_iter<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<(CommitRefIter<'a>, Option<Location>), Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.source§impl<T> FindExt for T
impl<T> FindExt for T
source§fn find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Data<'a>, Error>
fn find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Data<'a>, Error>
try_find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error.source§fn find_commit<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<CommitRef<'a>, Error>
fn find_commit<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<CommitRef<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.source§fn find_tree<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<TreeRef<'a>, Error>
fn find_tree<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<TreeRef<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.source§fn find_tag<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<TagRef<'a>, Error>
fn find_tag<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<TagRef<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.source§fn find_blob<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<BlobRef<'a>, Error>
fn find_blob<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<BlobRef<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired object type.source§fn find_commit_iter<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<CommitRefIter<'a>, Error>
fn find_commit_iter<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<CommitRefIter<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.source§fn find_tree_iter<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<TreeRefIter<'a>, Error>
fn find_tree_iter<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<TreeRefIter<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.source§fn find_tag_iter<'a>(
&self,
id: &oid,
buffer: &'a mut Vec<u8>,
) -> Result<TagRefIter<'a>, Error>
fn find_tag_iter<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<TagRefIter<'a>, Error>
find(…)
, but flattens the Result<Option<_>>
into a single Result
making a non-existing object an error
while returning the desired iterator type.