Skip to content

Commit

Permalink
copy-tracking: create a MaterializedTreeDiffEntry type
Browse files Browse the repository at this point in the history
  • Loading branch information
fowles committed Aug 11, 2024
1 parent e123eb2 commit 6bae5ea
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 22 deletions.
34 changes: 28 additions & 6 deletions cli/src/diff_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -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}")?;
Expand Down Expand Up @@ -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)?;
Expand Down
37 changes: 23 additions & 14 deletions lib/src/conflicts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = MaterializedTreeDiffEntry> + '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,
}
}
}
},
Expand Down
11 changes: 9 additions & 2 deletions lib/src/default_index/revset_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)?;
Expand Down

0 comments on commit 6bae5ea

Please sign in to comment.