Struct git_repository::worktree::fs::Cache
source · 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
impl Cache
pub fn set_case(&mut self, case: Case)
pub fn num_mkdir_calls(&self) -> usize
pub fn reset_mkdir_calls(&mut self)
pub fn unlink_on_collision(&mut self, value: bool)
source§impl Cache
impl Cache
sourcepub fn new(
worktree_root: impl Into<PathBuf>,
state: State,
case: Case,
buf: Vec<u8, Global>,
attribute_files_in_index: Vec<(BString, ObjectId), Global>
) -> Cache
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.
sourcepub 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,
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.