Struct gix_odb::store::Handle

source ·
pub struct Handle<S>
where S: Deref<Target = Store> + Clone,
{ 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>
where S: Deref<Target = Store> + Clone,

source

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.

source

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.

source

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 is Some(…), the traversal will continue to obtain all candidates, which takes more time as there is no early abort.
source§

impl<S> Handle<S>
where S: Deref<Target = Store> + Clone,

source

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>
where S: Deref<Target = Store> + Clone,

source

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.

source

pub fn store_ref(&self) -> &S::Target

Return a shared reference to the contained store.

source

pub fn store(&self) -> S

Return an owned store with shared ownership.

source

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.

source

pub fn refresh_mode(&mut self) -> RefreshMode

Return the current refresh mode.

source§

impl Handle<Rc<Store>>

source

pub fn into_arc(self) -> Result<Handle<Arc<Store>>>

Convert a ref counted store into one that is ref-counted and thread-safe, by creating a new Store.

source§

impl Handle<Arc<Store>>

source

pub fn into_arc(self) -> Result<Handle<Arc<Store>>>

Convert a ref counted store into one that is ref-counted and thread-safe, by creating a new Store

Trait Implementations§

source§

impl<S> Clone for Handle<S>
where S: Deref<Target = Store> + Clone,

source§

fn clone(&self) -> Self

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<S> Drop for Handle<S>
where S: Deref<Target = Store> + Clone,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<S> Exists for Handle<S>
where S: Deref<Target = Store> + Clone, Self: Find,

source§

fn exists(&self, id: &oid) -> bool

Returns true if the object exists in the database.
source§

impl<S> Find for Handle<S>
where S: Deref<Target = Store> + Clone,

source§

fn contains(&self, id: &oid) -> bool

Returns true if the object exists in the database.
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>

Like 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 more
source§

fn location_by_oid(&self, id: &oid, buf: &mut Vec<u8>) -> Option<Location>

Find the packs location where an object with id can be found in the database, or None if there is no pack holding the object. Read more
source§

fn pack_offsets_and_oid(&self, pack_id: u32) -> Option<Vec<(u64, ObjectId)>>

Obtain a vector of all offsets, in index order, along with their object id.
source§

fn entry_by_location(&self, location: &Location) -> Option<Entry>

Return the find::Entry for location if it is backed by a pack. Read more
source§

fn try_find<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<Option<(Data<'a>, Option<Location>)>, Box<dyn Error + Send + Sync>>

Find an object matching 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 more
source§

impl<S> Find for Handle<S>
where S: Deref<Target = Store> + Clone, Self: Find,

source§

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

Find an object matching id in the database while placing its raw, possibly encoded data into buffer. Read more
source§

impl<S> Header for Handle<S>
where S: Deref<Target = Store> + Clone,

source§

fn try_header(&self, id: &oid) -> Result<Option<Header>, Error>

Find the header of the object matching id in the database. Read more
source§

impl<S> Header for Handle<S>
where S: Deref<Target = Store> + Clone,

source§

fn try_header(&self, id: &oid) -> Result<Option<Header>, Error>

Try to read the header of the object associated with id or return None if it could not be found.
source§

impl<S> Write for Handle<S>
where S: Deref<Target = Store> + Clone,

source§

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

As write, but takes an input stream. This is commonly used for writing blobs directly without reading them to memory first.
source§

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

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

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

As write, but takes an object kind along with its encoded bytes.

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> 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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> FindExt for T
where T: Find + ?Sized,

source§

fn find<'a>( &self, id: &oid, buffer: &'a mut Vec<u8>, ) -> Result<(Data<'a>, Option<Location>), Error>

Like 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>

Like 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>

Like 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>

Like 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>

Like 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>

Like 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>, Option<Location>), Error>

Like 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>, Option<Location>), Error>

Like 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
where T: Find + ?Sized,

source§

fn find<'a>(&self, id: &oid, buffer: &'a mut Vec<u8>) -> Result<Data<'a>, Error>

Like 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>

Like 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>

Like 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>

Like 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>

Like 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>

Like 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>

Like 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>

Like 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> HeaderExt for T
where T: Header,

source§

fn header(&self, id: impl AsRef<oid>) -> Result<Header, Error>

Like try_header(…), but flattens the Result<Option<_>> into a single Result making a non-existing object an error.
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> ToOwned for T
where 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 T
where U: Into<T>,

§

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>,

§

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.
source§

impl<T> FindObjectOrHeader for T
where T: Find + Header,