From e123eb21b9b5465cd64d0e6ff9a2ec928554e6e2 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Fri, 26 Jul 2024 12:49:27 -0400 Subject: [PATCH] copy-tracking: add `source` field to `TreeDiffEntry` - add the field and make it compile, but don't use it yet --- cli/src/commands/fix.rs | 1 + cli/src/diff_util.rs | 2 ++ cli/src/merge_tools/builtin.rs | 1 + lib/src/conflicts.rs | 1 + lib/src/local_working_copy.rs | 2 ++ lib/src/merged_tree.rs | 12 +++++++++++- lib/src/rewrite.rs | 1 + 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cli/src/commands/fix.rs b/cli/src/commands/fix.rs index b2c38a12fd..113b7b08f4 100644 --- a/cli/src/commands/fix.rs +++ b/cli/src/commands/fix.rs @@ -175,6 +175,7 @@ pub(crate) fn cmd_fix( let mut diff_stream = parent_tree.diff_stream(&tree, &matcher); async { while let Some(TreeDiffEntry { + source: _, // TODO handle copy tracking target: repo_path, value: diff, }) = diff_stream.next().await diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index 5e2d6244d6..4c2d81fdbb 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -1111,6 +1111,7 @@ pub fn show_diff_summary( ) -> io::Result<()> { async { while let Some(TreeDiffEntry { + source: _, // TODO handle copy tracking target: repo_path, value: diff, }) = tree_diff.next().await @@ -1246,6 +1247,7 @@ pub fn show_types( ) -> io::Result<()> { async { while let Some(TreeDiffEntry { + source: _, // TODO handle copy tracking target: repo_path, value: diff, }) = tree_diff.next().await diff --git a/cli/src/merge_tools/builtin.rs b/cli/src/merge_tools/builtin.rs index f9197da2e3..70dc011084 100644 --- a/cli/src/merge_tools/builtin.rs +++ b/cli/src/merge_tools/builtin.rs @@ -498,6 +498,7 @@ pub fn edit_diff_builtin( .diff_stream(right_tree, matcher) .map( |TreeDiffEntry { + source: _, // TODO handle copy tracking target: path, value: diff, }| diff.map(|_| path), diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index 2611a25a79..44484daf6b 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -337,6 +337,7 @@ pub fn materialized_diff_stream<'a>( tree_diff .map( |TreeDiffEntry { + source: _, // TODO handle copy tracking target: path, value: diff, }| async { diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index a69fa209c5..d818315662 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -1355,6 +1355,7 @@ impl TreeState { .diff_stream(new_tree, matcher) .map( |TreeDiffEntry { + source: _, // TODO handle copy tracking target: path, value: diff, }| async { @@ -1454,6 +1455,7 @@ impl TreeState { let mut deleted_files = HashSet::new(); let mut diff_stream = old_tree.diff_stream(new_tree, matcher.as_ref()); while let Some(TreeDiffEntry { + source: _, // TODO handle copy tracking target: path, value: diff, }) = diff_stream.next().await diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index 481d609cd8..8643453f1c 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -323,7 +323,8 @@ impl MergedTree { /// A single entry in a tree diff. pub struct TreeDiffEntry { - // pub source: RepoPathBuf, + /// The source path. + pub source: RepoPathBuf, /// The target path. pub target: RepoPathBuf, /// The resolved tree values if available. @@ -712,6 +713,7 @@ impl Iterator for TreeDiffIterator<'_> { TreeDiffItem::File(..) => { if let TreeDiffItem::File(path, before, after) = self.stack.pop().unwrap() { return Some(TreeDiffEntry { + source: path.clone(), target: path, value: Ok((before, after)), }); @@ -731,12 +733,14 @@ impl Iterator for TreeDiffIterator<'_> { (Ok(before_tree), Ok(after_tree)) => (before_tree, after_tree), (Err(before_err), _) => { return Some(TreeDiffEntry { + source: path.clone(), target: path, value: Err(before_err), }) } (_, Err(after_err)) => { return Some(TreeDiffEntry { + source: path.clone(), target: path, value: Err(after_err), }) @@ -752,6 +756,7 @@ impl Iterator for TreeDiffIterator<'_> { if !tree_before && tree_after { if before.is_present() { return Some(TreeDiffEntry { + source: path.clone(), target: path, value: Ok((before, Merge::absent())), }); @@ -765,6 +770,7 @@ impl Iterator for TreeDiffIterator<'_> { } } else if !tree_before && !tree_after { return Some(TreeDiffEntry { + source: path.clone(), target: path, value: Ok((before, after)), }); @@ -999,10 +1005,12 @@ impl Stream for TreeDiffStreamImpl<'_> { let (key, result) = entry.remove_entry(); Poll::Ready(Some(match result { Err(err) => TreeDiffEntry { + source: key.path.clone(), target: key.path, value: Err(err), }, Ok((before, after)) => TreeDiffEntry { + source: key.path.clone(), target: key.path, value: Ok((before, after)), }, @@ -1013,10 +1021,12 @@ impl Stream for TreeDiffStreamImpl<'_> { let (key, result) = entry.remove_entry(); Poll::Ready(Some(match result { Err(err) => TreeDiffEntry { + source: key.path.clone(), target: key.path, value: Err(err), }, Ok((before, after)) => TreeDiffEntry { + source: key.path.clone(), target: key.path, value: Ok((before, after)), }, diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index ea1c36b565..7ccc59a04c 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -89,6 +89,7 @@ pub fn restore_tree( async { let mut diff_stream = source.diff_stream(destination, matcher); while let Some(TreeDiffEntry { + source: _, // TODO handle copy tracking target: repo_path, value: diff, }) = diff_stream.next().await