pub struct Cache { /* private fields */ }
Expand description

A cache for efficiently executing operations on directories and files which are encountered in sorted order. That way, these operations can be re-used for subsequent invocations in the same directory.

This cache can be configured to create directories efficiently, read git-ignore files and git-attribute files, in any combination.

A cache for directory creation to reduce the amount of stat calls when creating directories safely, that is without following symlinks that might be on the way.

As a special case, it offers a ‘prefix’ which (by itself) is assumed to exist and may contain symlinks. Everything past that prefix boundary must not contain a symlink. We do this by allowing any input path.

Another added benefit is its ability to store the path of full path of the entry to which leading directories are to be created to avoid allocating memory.

For this to work, it remembers the last ‘good’ path to a directory and assumes that all components of it are still valid, too. As directories are created, the cache will be adjusted to reflect the latest seen directory.

The caching is only useful if consecutive calls to create a directory are using a sorted list of entries.

Implementations§

source§

impl Cache

source

pub fn set_case(&mut self, case: Case)

Available on debug-assertions enabled only.
source

pub fn num_mkdir_calls(&self) -> usize

Available on debug-assertions enabled only.
source

pub fn reset_mkdir_calls(&mut self)

Available on debug-assertions enabled only.
Available on debug-assertions enabled only.
source§

impl Cache

source

pub fn new( worktree_root: impl Into<PathBuf>, state: State, case: Case, buf: Vec<u8, Global>, attribute_files_in_index: Vec<(BString, ObjectId), Global> ) -> Cache

Create a new instance with worktree_root being the base for all future paths we handle, assuming it to be valid which includes symbolic links to be included in it as well. The case configures attribute and exclusion query case sensitivity.

source

pub fn at_path<Find, E>( &mut self, relative: impl AsRef<Path>, is_dir: Option<bool>, find: Find ) -> Result<Platform<'_>, Error>where Find: for<'a> FnMut(&oid, &'a mut Vec<u8, Global>) -> Result<BlobRef<'a>, E>, E: Error + Send + Sync + 'static,

Append the relative path to the root directory the cache contains and efficiently create leading directories unless is_dir is known (Some(…)) then relative points to a directory itself in which case the entire resulting path is created as directory. If it’s not known it is assumed to be a file.

Provide access to cached information for that relative entry via the platform returned.

source

pub fn at_entry<'r, Find, E>( &mut self, relative: impl Into<&'r BStr>, is_dir: Option<bool>, find: Find ) -> Result<Platform<'_>, Error>where Find: for<'a> FnMut(&oid, &'a mut Vec<u8, Global>) -> Result<BlobRef<'a>, E>, E: Error + Send + Sync + 'static,

Panics on illformed UTF8 in relative

source

pub fn base(&self) -> &Path

Return the base path against which all entries or paths should be relative to when querying.

Note that this path may not be canonicalized.

Trait Implementations§

source§

impl Clone for Cache

source§

fn clone(&self) -> Cache

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

Auto Trait Implementations§

§

impl RefUnwindSafe for Cache

§

impl Send for Cache

§

impl Sync for Cache

§

impl Unpin for Cache

§

impl UnwindSafe for Cache

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.