diff: move materialized_diff_stream() to jj_lib::conflicts module

New diff_contains() revset function will use this helper.
This commit is contained in:
Yuya Nishihara 2024-07-08 20:04:34 +09:00
parent 0c8f881fcd
commit a9af8d21f8
2 changed files with 31 additions and 30 deletions

View file

@ -18,11 +18,11 @@ use std::ops::Range;
use std::path::{Path, PathBuf};
use std::{io, mem};
use futures::{try_join, Stream, StreamExt};
use futures::StreamExt;
use itertools::Itertools;
use jj_lib::backend::{BackendError, BackendResult, TreeValue};
use jj_lib::backend::{BackendError, TreeValue};
use jj_lib::commit::Commit;
use jj_lib::conflicts::{materialize_tree_value, MaterializedTreeValue};
use jj_lib::conflicts::{materialized_diff_stream, MaterializedTreeValue};
use jj_lib::diff::{Diff, DiffHunk};
use jj_lib::files::DiffLine;
use jj_lib::matchers::Matcher;
@ -30,7 +30,7 @@ use jj_lib::merge::MergedTreeValue;
use jj_lib::merged_tree::{MergedTree, TreeDiffStream};
use jj_lib::object_id::ObjectId;
use jj_lib::repo::Repo;
use jj_lib::repo_path::{RepoPath, RepoPathBuf, RepoPathUiConverter};
use jj_lib::repo_path::{RepoPath, RepoPathUiConverter};
use jj_lib::settings::{ConfigResultExt as _, UserSettings};
use jj_lib::store::Store;
use jj_lib::{diff, files};
@ -995,30 +995,6 @@ fn show_unified_diff_hunks(
Ok(())
}
fn materialized_diff_stream<'a>(
store: &'a Store,
tree_diff: TreeDiffStream<'a>,
) -> impl Stream<
Item = (
RepoPathBuf,
BackendResult<(MaterializedTreeValue, MaterializedTreeValue)>,
),
> + 'a {
tree_diff
.map(|(path, diff)| async {
match diff {
Err(err) => (path, Err(err)),
Ok((before, after)) => {
let before_future = materialize_tree_value(store, &path, before);
let after_future = materialize_tree_value(store, &path, after);
let values = try_join!(before_future, after_future);
(path, values)
}
}
})
.buffered((store.concurrency() / 2).max(1))
}
pub fn show_git_diff(
formatter: &mut dyn Formatter,
store: &Store,

View file

@ -17,7 +17,7 @@
use std::io::{Read, Write};
use std::iter::zip;
use futures::{StreamExt, TryStreamExt};
use futures::{try_join, Stream, StreamExt, TryStreamExt};
use itertools::Itertools;
use regex::bytes::Regex;
@ -26,7 +26,8 @@ use crate::diff::{Diff, DiffHunk};
use crate::files;
use crate::files::{ContentHunk, MergeResult};
use crate::merge::{Merge, MergeBuilder, MergedTreeValue};
use crate::repo_path::RepoPath;
use crate::merged_tree::TreeDiffStream;
use crate::repo_path::{RepoPath, RepoPathBuf};
use crate::store::Store;
const CONFLICT_START_LINE: &[u8] = b"<<<<<<<";
@ -326,6 +327,30 @@ fn diff_size(hunks: &[DiffHunk]) -> usize {
.sum()
}
pub fn materialized_diff_stream<'a>(
store: &'a Store,
tree_diff: TreeDiffStream<'a>,
) -> impl Stream<
Item = (
RepoPathBuf,
BackendResult<(MaterializedTreeValue, MaterializedTreeValue)>,
),
> + 'a {
tree_diff
.map(|(path, diff)| async {
match diff {
Err(err) => (path, Err(err)),
Ok((before, after)) => {
let before_future = materialize_tree_value(store, &path, before);
let after_future = materialize_tree_value(store, &path, after);
let values = try_join!(before_future, after_future);
(path, values)
}
}
})
.buffered((store.concurrency() / 2).max(1))
}
/// Parses conflict markers from a slice. Returns None if there were no valid
/// conflict markers. The caller has to provide the expected number of merge
/// sides (adds). Conflict markers that are otherwise valid will be considered