diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index e97df297bd..4b2e0318b4 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -295,8 +295,8 @@ impl MergedTree { ))) } else { Box::pin(TreeDiffStreamImpl::new( - self.trees.clone(), - other.trees.clone(), + &self.trees, + &other.trees, matcher, concurrency, )) @@ -922,8 +922,8 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> { /// Creates a iterator over the differences between two trees. Generally /// prefer `MergedTree::diff_stream()` of calling this directly. pub fn new( - trees1: Merge, - trees2: Merge, + trees1: &Merge, + trees2: &Merge, matcher: &'matcher dyn Matcher, max_concurrent_reads: usize, ) -> Self { @@ -936,7 +936,7 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> { max_concurrent_reads, max_queued_items: 10000, }; - stream.add_dir_diff_items(RepoPathBuf::root(), Ok((trees1, trees2))); + stream.add_dir_diff_items(RepoPath::root(), trees1, trees2); stream } @@ -968,20 +968,8 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> { } } - fn add_dir_diff_items( - &mut self, - dir: RepoPathBuf, - tree_diff: BackendResult<(Merge, Merge)>, - ) { - let (trees1, trees2) = match tree_diff { - Ok(trees) => trees, - Err(err) => { - self.items.insert(DiffStreamKey::normal(dir), Err(err)); - return; - } - }; - - for (basename, before, after) in merged_tree_entry_diff(&trees1, &trees2) { + fn add_dir_diff_items(&mut self, dir: &RepoPath, trees1: &Merge, trees2: &Merge) { + for (basename, before, after) in merged_tree_entry_diff(trees1, trees2) { let path = dir.join(basename); let tree_before = before.is_tree(); let tree_after = after.is_tree(); @@ -1049,7 +1037,14 @@ impl<'matcher> TreeDiffStreamImpl<'matcher> { Ok((Merge::absent(), after)), ); } - self.add_dir_diff_items(key.path, tree_diff); + match tree_diff { + Ok((trees1, trees2)) => { + self.add_dir_diff_items(&key.path, &trees1, &trees2); + } + Err(err) => { + self.items.insert(DiffStreamKey::normal(key.path), Err(err)); + } + } } else { pending_index += 1; } diff --git a/lib/tests/test_merged_tree.rs b/lib/tests/test_merged_tree.rs index 8cc6908087..8ccd96e4a4 100644 --- a/lib/tests/test_merged_tree.rs +++ b/lib/tests/test_merged_tree.rs @@ -63,15 +63,11 @@ fn diff_stream_equals_iter(tree1: &MergedTree, tree2: &MergedTree, matcher: &dyn .map(|diff| (diff.path, diff.values.unwrap())) .collect(); let max_concurrent_reads = 10; - let stream_diff: Vec<_> = TreeDiffStreamImpl::new( - trees1.clone(), - trees2.clone(), - matcher, - max_concurrent_reads, - ) - .map(|diff| (diff.path, diff.values.unwrap())) - .collect() - .block_on(); + let stream_diff: Vec<_> = + TreeDiffStreamImpl::new(trees1, trees2, matcher, max_concurrent_reads) + .map(|diff| (diff.path, diff.values.unwrap())) + .collect() + .block_on(); assert_eq!(stream_diff, iter_diff); }