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

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

Unified · Split

2 files
  1. git-worktree/src/fs/cache/state.rs +2 −1
  2. git-worktree/src/index/mod.rs +22 −2
git-worktree/src/fs/cache/state.rs+2−1
@@ -111,6 +111,7 @@ impl State { · 110 unmodified lines
111111 pub(crate) fn build_attribute_list(
112112 &self,
113113 index: &git_index::State,
114+ paths: &git_index::PathStorage,
114115 case: git_glob::pattern::Case,
115116 ) -> Vec<PathIdMapping> {
116117 let a1_backing;
@@ -137,7 +138,7 @@ impl State { · 20 unmodified lines
137138 .entries()
138139 .iter()
139140 .filter_map(move |entry| {
140− let path = entry.path(index);
141+ let path = entry.path_in(paths);
141142
142143 // Stage 0 means there is no merge going on, stage 2 means it's 'our' side of the merge, but then
143144 // 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
2121 should_interrupt: &AtomicBool,
2222 options: checkout::Options,
2323 ) -> Result<checkout::Outcome, checkout::Error<E>>
24+where
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)]
34+fn 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>>
2444 where
2545 Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Result<git_object::BlobRef<'a>, E> + Send + Clone,
2646 E: std::error::Error + Send + Sync + 'static,
@@ -33,7 +53,7 @@ where · 6 unmodified lines
3353 git_glob::pattern::Case::Sensitive
3454 };
3555 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);
3757 let mut ctx = chunk::Context {
3858 buf: Vec::new(),
3959 path_cache: fs::Cache::new(
@@ -54,7 +74,7 @@ where · 14 unmodified lines
5474 None,
5575 );
5676
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);
5878 let chunk::Outcome {
5979 mut collisions,
6080 mut errors,