mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-20 03:20:08 +00:00
copy-tracking: create a MaterializedTreeDiffEntry type
This commit is contained in:
parent
e123eb21b9
commit
6bae5eaf9d
3 changed files with 60 additions and 22 deletions
|
@ -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)?;
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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)?;
|
||||
|
|
Loading…
Reference in a new issue