From 6bae5eaf9d53e31a1c229922b53b4817aaa61c79 Mon Sep 17 00:00:00 2001 From: Matt Kulukundis Date: Fri, 26 Jul 2024 13:21:21 -0400 Subject: [PATCH] copy-tracking: create a MaterializedTreeDiffEntry type --- cli/src/diff_util.rs | 34 ++++++++++++++++++----- lib/src/conflicts.rs | 37 ++++++++++++++++---------- lib/src/default_index/revset_engine.rs | 11 ++++++-- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index 4c2d81fdbb..b52cde1c4a 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -22,7 +22,9 @@ use futures::StreamExt; use itertools::Itertools; use jj_lib::backend::{BackendError, CopyRecords, TreeValue}; use jj_lib::commit::Commit; -use jj_lib::conflicts::{materialized_diff_stream, MaterializedTreeValue}; +use jj_lib::conflicts::{ + materialized_diff_stream, MaterializedTreeDiffEntry, MaterializedTreeValue, +}; use jj_lib::diff::{Diff, DiffHunk}; use jj_lib::files::DiffLine; use jj_lib::matchers::Matcher; @@ -567,7 +569,12 @@ pub fn show_color_words_diff( ) -> Result<(), DiffRenderError> { let mut diff_stream = materialized_diff_stream(store, tree_diff); async { - while let Some((path, diff)) = diff_stream.next().await { + while let Some(MaterializedTreeDiffEntry { + source: _, // TODO handle copy tracking + target: path, + value: diff, + }) = diff_stream.next().await + { let ui_path = path_converter.format_file_path(&path); let (left_value, right_value) = diff?; @@ -714,7 +721,12 @@ pub fn show_file_by_file_diff( let right_wc_dir = temp_dir.path().join("right"); let mut diff_stream = materialized_diff_stream(store, tree_diff); async { - while let Some((path, diff)) = diff_stream.next().await { + while let Some(MaterializedTreeDiffEntry { + source: _, // TODO handle copy tracking + target: path, + value: diff, + }) = diff_stream.next().await + { let ui_path = path_converter.format_file_path(&path); let (left_value, right_value) = diff?; @@ -1032,10 +1044,15 @@ pub fn show_git_diff( ) -> Result<(), DiffRenderError> { let mut diff_stream = materialized_diff_stream(store, tree_diff); async { - while let Some((path, diff)) = diff_stream.next().await { + while let Some(MaterializedTreeDiffEntry { + source: _, // TODO handle copy tracking + target: path, + value: diff, + }) = diff_stream.next().await + { let path_string = path.as_internal_file_string(); let (left_value, right_value) = diff?; - let left_part = git_diff_part(&path, left_value)?; + let left_part = git_digf_part(&path, left_value)?; let right_part = git_diff_part(&path, right_value)?; formatter.with_label("file_header", |formatter| { writeln!(formatter, "diff --git a/{path_string} b/{path_string}")?; @@ -1179,7 +1196,12 @@ pub fn show_diff_stat( let mut diff_stream = materialized_diff_stream(store, tree_diff); async { - while let Some((repo_path, diff)) = diff_stream.next().await { + while let Some(MaterializedTreeDiffEntry { + source: _, // TODO handle copy tracking + target: repo_path, + value: diff, + }) = diff_stream.next().await + { let (left, right) = diff?; let path = path_converter.format_file_path(&repo_path); let left_content = diff_content(&repo_path, left)?; diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index 44484daf6b..9cb50d6789 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -325,29 +325,38 @@ fn diff_size(hunks: &[DiffHunk]) -> usize { .sum() } +pub struct MaterializedTreeDiffEntry { + pub source: RepoPathBuf, + pub target: RepoPathBuf, + pub value: BackendResult<(MaterializedTreeValue, MaterializedTreeValue)>, +} + pub fn materialized_diff_stream<'a>( store: &'a Store, tree_diff: TreeDiffStream<'a>, -) -> impl Stream< - Item = ( - RepoPathBuf, - BackendResult<(MaterializedTreeValue, MaterializedTreeValue)>, - ), -> + 'a { +) -> impl Stream + 'a { tree_diff .map( |TreeDiffEntry { - source: _, // TODO handle copy tracking - target: path, - value: diff, + source, + target, + value, }| async { - match diff { - Err(err) => (path, Err(err)), + match value { + Err(err) => MaterializedTreeDiffEntry { + source, + target, + value: Err(err), + }, Ok((before, after)) => { - let before_future = materialize_tree_value(store, &path, before); - let after_future = materialize_tree_value(store, &path, after); + let before_future = materialize_tree_value(store, &source, before); + let after_future = materialize_tree_value(store, &target, after); let values = try_join!(before_future, after_future); - (path, values) + MaterializedTreeDiffEntry { + source, + target, + value: values, + } } } }, diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index cc1bbc4161..6eebdc0e2e 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -30,7 +30,9 @@ use super::rev_walk::{EagerRevWalk, PeekableRevWalk, RevWalk, RevWalkBuilder}; use super::revset_graph_iterator::RevsetGraphWalk; use crate::backend::{BackendError, BackendResult, ChangeId, CommitId, MillisSinceEpoch}; use crate::commit::Commit; -use crate::conflicts::{materialized_diff_stream, MaterializedTreeValue}; +use crate::conflicts::{ + materialized_diff_stream, MaterializedTreeDiffEntry, MaterializedTreeValue, +}; use crate::default_index::{AsCompositeIndex, CompositeIndex, IndexPosition}; use crate::graph::GraphEdge; use crate::matchers::{Matcher, Visit}; @@ -1175,7 +1177,12 @@ fn matches_diff_from_parent( // pairs can be compared one by one. #4062 let mut diff_stream = materialized_diff_stream(store, tree_diff); async { - while let Some((path, diff)) = diff_stream.next().await { + while let Some(MaterializedTreeDiffEntry { + source: _, // TODO handle copy tracking + target: path, + value: diff, + }) = diff_stream.next().await + { let (left_value, right_value) = diff?; let left_content = to_file_content(&path, left_value)?; let right_content = to_file_content(&path, right_value)?;