History

Use a separate path mapping to enable clone-avoidance (#301)

Sebastian Thiel committed 4 years ago

Commit e525b5e1 parent 645ed503 files · +27 −3Browse files

Unified · Split

3 files
  1. git-worktree/src/fs/cache/state.rs +2 −1
  2. git-worktree/src/index/mod.rs +22 −2
  3. git-worktree/tests/worktree/fs/cache.rs +3 −0
git-worktree/src/fs/cache/state.rs+2−1
@@ -111,6 +111,7 @@ impl State { · 110 unmodified lines
111 pub(crate) fn build_attribute_list(111 pub(crate) fn build_attribute_list(
112 &self,112 &self,
113 index: &git_index::State,113 index: &git_index::State,
114 paths: &git_index::PathStorage,
114 case: git_glob::pattern::Case,115 case: git_glob::pattern::Case,
115 ) -> Vec<PathIdMapping> {116 ) -> Vec<PathIdMapping> {
116 let a1_backing;117 let a1_backing;
@@ -137,7 +138,7 @@ impl State { · 20 unmodified lines
137 .entries()138 .entries()
138 .iter()139 .iter()
139 .filter_map(move |entry| {140 .filter_map(move |entry| {
140 let path = entry.path(index);141 let path = entry.path_in(paths);
141 142
142 // Stage 0 means there is no merge going on, stage 2 means it's 'our' side of the merge, but then143 // Stage 0 means there is no merge going on, stage 2 means it's 'our' side of the merge, but then
143 // there won't be a stage 0.144 // there won't be a stage 0.
git-worktree/src/index/mod.rs+22−2
@@ -21,6 +21,26 @@ pub fn checkout<Find, E>( · 20 unmodified lines
21 should_interrupt: &AtomicBool,21 should_interrupt: &AtomicBool,
22 options: checkout::Options,22 options: checkout::Options,
23) -> Result<checkout::Outcome, checkout::Error<E>>23) -> Result<checkout::Outcome, checkout::Error<E>>
24where
25 Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Result<git_object::BlobRef<'a>, E> + Send + Clone,
26 E: std::error::Error + Send + Sync + 'static,
27{
28 let paths = index.take_path_backing();
29 let res = checkout_inner(index, &paths, dir, find, files, bytes, should_interrupt, options);
30 index.return_path_backing(paths);
31 res
32}
33#[allow(clippy::too_many_arguments)]
34fn checkout_inner<Find, E>(
35 index: &mut git_index::State,
36 paths: &git_index::PathStorage,
37 dir: impl Into<std::path::PathBuf>,
38 find: Find,
39 files: &mut impl Progress,
40 bytes: &mut impl Progress,
41 should_interrupt: &AtomicBool,
42 options: checkout::Options,
43) -> Result<checkout::Outcome, checkout::Error<E>>
24where44where
25 Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Result<git_object::BlobRef<'a>, E> + Send + Clone,45 Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Result<git_object::BlobRef<'a>, E> + Send + Clone,
26 E: std::error::Error + Send + Sync + 'static,46 E: std::error::Error + Send + Sync + 'static,
@@ -33,7 +53,7 @@ where · 6 unmodified lines
33 git_glob::pattern::Case::Sensitive53 git_glob::pattern::Case::Sensitive
34 };54 };
35 let state = fs::cache::State::for_checkout(options.overwrite_existing, options.attribute_globals.clone().into());55 let state = fs::cache::State::for_checkout(options.overwrite_existing, options.attribute_globals.clone().into());
36 let attribute_files = state.build_attribute_list(index, case);56 let attribute_files = state.build_attribute_list(index, paths, case);
37 let mut ctx = chunk::Context {57 let mut ctx = chunk::Context {
38 buf: Vec::new(),58 buf: Vec::new(),
39 path_cache: fs::Cache::new(59 path_cache: fs::Cache::new(
@@ -54,7 +74,7 @@ where · 14 unmodified lines
54 None,74 None,
55 );75 );
56 76
57 let entries_with_paths = interrupt::Iter::new(index.entries_mut_with_paths(), should_interrupt);77 let entries_with_paths = interrupt::Iter::new(index.entries_mut_with_paths_in(paths), should_interrupt);
58 let chunk::Outcome {78 let chunk::Outcome {
59 mut collisions,79 mut collisions,
60 mut errors,80 mut errors,
git-worktree/tests/worktree/fs/cache.rs+3−0
@@ -12,6 +12,7 @@ mod create_directory { · 11 unmodified lines
12 fs::cache::State::for_checkout(false, Default::default()),12 fs::cache::State::for_checkout(false, Default::default()),
13 Default::default(),13 Default::default(),
14 Vec::new(),14 Vec::new(),
15 Default::default(),
15 );16 );
16 assert_eq!(cache.num_mkdir_calls(), 0);17 assert_eq!(cache.num_mkdir_calls(), 0);
17 18
@@ -92,6 +93,7 @@ mod create_directory { · 74 unmodified lines
92 fs::cache::State::for_checkout(false, Default::default()),93 fs::cache::State::for_checkout(false, Default::default()),
93 Default::default(),94 Default::default(),
94 Vec::new(),95 Vec::new(),
96 Default::default(),
95 );97 );
96 (cache, dir)98 (cache, dir)
97 }99 }
@@ -154,6 +156,7 @@ mod ignore_and_attributes { · 56 unmodified lines
154 ),156 ),
155 Default::default(),157 Default::default(),
156 buf,158 buf,
159 Default::default(), // TODO: get the index, use it to ask state to get the attributes files LUT
157 );160 );
158 161
159 for (relative_path, source_and_line) in (IgnoreExpectations {162 for (relative_path, source_and_line) in (IgnoreExpectations {