History

provide a platform for multiple queries at a dir cache level (#301)

This allows to perform work only once while allowing subsequent queries to the cached information, like `is_excluded()` or `attributes()`.

Sebastian Thiel committed 4 years ago

Commit 48be3821 parent dc12f883 files · +29 −20Browse files

Showing the changes to git-worktree/src (2 of 3 files). Show all

Unified · Split

2 files
  1. git-worktree/src/fs/cache.rs +21 −4
  2. git-worktree/src/index/entry.rs +1 −1
git-worktree/src/fs/cache.rs+21−4
@@ -11,6 +11,23 @@ pub enum Mode { · 10 unmodified lines
11 ProvideAttributesAndIgnore,11 ProvideAttributesAndIgnore,
12}12}
13 13
14pub struct Platform<'a> {
15 parent: &'a Cache,
16}
17
18impl<'a> Platform<'a> {
19 /// The full path to `relative` will be returned for use on the file system.
20 pub fn leading_dir(&self) -> &'a Path {
21 self.parent.stack.current()
22 }
23}
24
25impl<'a> std::fmt::Debug for Platform<'a> {
26 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27 std::fmt::Debug::fmt(&self.leading_dir(), f)
28 }
29}
30
14impl Cache {31impl Cache {
15 /// Create a new instance with `root` being the base for all future paths we handle, assuming it to be valid which includes32 /// Create a new instance with `root` being the base for all future paths we handle, assuming it to be valid which includes
16 /// symbolic links to be included in it as well.33 /// symbolic links to be included in it as well.
@@ -28,12 +45,12 @@ impl Cache { · 11 unmodified lines
28 /// Append the `relative` path to the root directory the cache contains and efficiently create leading directories45 /// Append the `relative` path to the root directory the cache contains and efficiently create leading directories
29 /// unless `mode` indicates `relative` points to a directory itself in which case the entire resulting path is created as directory.46 /// unless `mode` indicates `relative` points to a directory itself in which case the entire resulting path is created as directory.
30 ///47 ///
31 /// The full path to `relative` will be returned for use on the file system.48 /// Provide access to cached information for that `relative` entry via the platform returned.
32 pub fn append_relative_path_assure_leading_dir(49 pub fn at_entry(
33 &mut self,50 &mut self,
34 relative: impl AsRef<Path>,51 relative: impl AsRef<Path>,
35 mode: git_index::entry::Mode,52 mode: git_index::entry::Mode,
36 ) -> std::io::Result<&Path> {53 ) -> std::io::Result<Platform<'_>> {
37 #[cfg(debug_assertions)]54 #[cfg(debug_assertions)]
38 let mkdir_calls = &mut self.test_mkdir_calls;55 let mkdir_calls = &mut self.test_mkdir_calls;
39 let unlink_on_collision = self.unlink_on_collision;56 let unlink_on_collision = self.unlink_on_collision;
@@ -51,7 +68,7 @@ impl Cache { · 11 unmodified lines
51 },68 },
52 |_| {},69 |_| {},
53 )?;70 )?;
54 Ok(self.stack.current())71 Ok(Platform { parent: self })
55 }72 }
56}73}
57 74
git-worktree/src/index/entry.rs+1−1
@@ -37,7 +37,7 @@ where · 36 unmodified lines
37 git_features::path::from_byte_slice(entry_path).map_err(|_| index::checkout::Error::IllformedUtf8 {37 git_features::path::from_byte_slice(entry_path).map_err(|_| index::checkout::Error::IllformedUtf8 {
38 path: entry_path.to_owned(),38 path: entry_path.to_owned(),
39 })?;39 })?;
40 let dest = path_cache.append_relative_path_assure_leading_dir(dest_relative, entry.mode)?;40 let dest = path_cache.at_entry(dest_relative, entry.mode)?.leading_dir();
41 41
42 let object_size = match entry.mode {42 let object_size = match entry.mode {
43 git_index::entry::Mode::FILE | git_index::entry::Mode::FILE_EXECUTABLE => {43 git_index::entry::Mode::FILE | git_index::entry::Mode::FILE_EXECUTABLE => {