gix_odb::store

Struct 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 + Sync + Send>>

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, Box<dyn Error + Sync + Send>>

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, Box<dyn Error + Sync + Send>>

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 u8)

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

Source§

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

Source§

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

Source§

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,