ok/jj
1
0
Fork 0
forked from mirrors/jj

merged_tree: rename diff entry field from "value" to "values"

It seems a slightly better, and aligns with the local variable name in
materialized_diff_stream().
This commit is contained in:
Yuya Nishihara 2024-08-22 20:51:10 +09:00
parent 10cbb513fa
commit 43bf195314
11 changed files with 47 additions and 47 deletions

View file

@ -193,10 +193,10 @@ pub(crate) fn cmd_fix(
async {
while let Some(TreeDiffEntry {
path: repo_path,
value: diff,
values,
}) = diff_stream.next().await
{
let (_before, after) = diff?;
let (_before, after) = values?;
// Deleted files have no file content to fix, and they have no terms in `after`,
// so we don't add any tool inputs for them. Conflicted files produce one tool
// input for each side of the conflict.

View file

@ -775,12 +775,12 @@ pub fn show_color_words_diff(
while let Some(MaterializedTreeDiffEntry {
source: left_path,
target: right_path,
value: diff,
values,
}) = diff_stream.next().await
{
let left_ui_path = path_converter.format_file_path(&left_path);
let right_ui_path = path_converter.format_file_path(&right_path);
let (left_value, right_value) = diff?;
let (left_value, right_value) = values?;
match (&left_value, &right_value) {
(MaterializedTreeValue::AccessDenied(source), _) => {
@ -935,10 +935,10 @@ pub fn show_file_by_file_diff(
while let Some(MaterializedTreeDiffEntry {
source: left_path,
target: right_path,
value: diff,
values,
}) = diff_stream.next().await
{
let (left_value, right_value) = diff?;
let (left_value, right_value) = values?;
let left_ui_path = path_converter.format_file_path(&left_path);
let right_ui_path = path_converter.format_file_path(&right_path);
@ -1279,12 +1279,12 @@ pub fn show_git_diff(
while let Some(MaterializedTreeDiffEntry {
source: left_path,
target: right_path,
value: diff,
values,
}) = diff_stream.next().await
{
let left_path_string = left_path.as_internal_file_string();
let right_path_string = right_path.as_internal_file_string();
let (left_value, right_value) = diff?;
let (left_value, right_value) = values?;
let left_part = git_diff_part(&left_path, left_value)?;
let right_part = git_diff_part(&right_path, right_value)?;
@ -1383,10 +1383,10 @@ pub fn show_diff_summary(
while let Some(CopiesTreeDiffEntry {
source: before_path,
target: after_path,
value: diff,
values,
}) = tree_diff.next().await
{
let (before, after) = diff?;
let (before, after) = values?;
if before_path != after_path {
let path = path_converter.format_copied_path(&before_path, &after_path);
if to_tree.path_value(&before_path).unwrap().is_absent() {
@ -1462,10 +1462,10 @@ pub fn show_diff_stat(
while let Some(MaterializedTreeDiffEntry {
source: left_path,
target: right_path,
value: diff,
values,
}) = diff_stream.next().await
{
let (left, right) = diff?;
let (left, right) = values?;
let left_content = diff_content(&left_path, left)?;
let right_content = diff_content(&right_path, right)?;
@ -1551,10 +1551,10 @@ pub fn show_types(
while let Some(CopiesTreeDiffEntry {
source,
target,
value: diff,
values,
}) = tree_diff.next().await
{
let (before, after) = diff?;
let (before, after) = values?;
writeln!(
formatter.labeled("modified"),
"{}{} {}",

View file

@ -510,7 +510,7 @@ pub fn edit_diff_builtin(
// TODO: handle copy tracking
let changed_files: Vec<_> = left_tree
.diff_stream(right_tree, matcher)
.map(|TreeDiffEntry { path, value: diff }| diff.map(|_| path))
.map(|TreeDiffEntry { path, values }| values.map(|_| path))
.try_collect()
.block_on()?;
let files = make_diff_files(&store, left_tree, right_tree, &changed_files)?;

View file

@ -345,7 +345,7 @@ fn diff_size(hunks: &[DiffHunk]) -> usize {
pub struct MaterializedTreeDiffEntry {
pub source: RepoPathBuf,
pub target: RepoPathBuf,
pub value: BackendResult<(MaterializedTreeValue, MaterializedTreeValue)>,
pub values: BackendResult<(MaterializedTreeValue, MaterializedTreeValue)>,
}
pub fn materialized_diff_stream<'a>(
@ -357,13 +357,13 @@ pub fn materialized_diff_stream<'a>(
|CopiesTreeDiffEntry {
source,
target,
value,
values,
}| async {
match value {
match values {
Err(err) => MaterializedTreeDiffEntry {
source,
target,
value: Err(err),
values: Err(err),
},
Ok((before, after)) => {
let before_future = materialize_tree_value(store, &source, before);
@ -372,7 +372,7 @@ pub fn materialized_diff_stream<'a>(
MaterializedTreeDiffEntry {
source,
target,
value: values,
values,
}
}
}

View file

@ -97,7 +97,7 @@ pub struct CopiesTreeDiffEntry {
/// The target path.
pub target: RepoPathBuf,
/// The resolved tree values if available.
pub value: BackendResult<(MergedTreeValue, MergedTreeValue)>,
pub values: BackendResult<(MergedTreeValue, MergedTreeValue)>,
}
/// Wraps a `TreeDiffStream`, adding support for copies and renames.
@ -130,7 +130,7 @@ impl Stream for CopiesTreeDiffStream<'_> {
let Some(CopyRecord { source, .. }) = self.copy_records.for_target(&diff_entry.path)
else {
let target_deleted =
matches!(&diff_entry.value, Ok((_, target_value)) if target_value.is_absent());
matches!(&diff_entry.values, Ok((_, target_value)) if target_value.is_absent());
if target_deleted && self.copy_records.has_source(&diff_entry.path) {
// Skip the "delete" entry when there is a rename.
continue;
@ -138,14 +138,14 @@ impl Stream for CopiesTreeDiffStream<'_> {
return Poll::Ready(Some(CopiesTreeDiffEntry {
source: diff_entry.path.clone(),
target: diff_entry.path,
value: diff_entry.value,
values: diff_entry.values,
}));
};
return Poll::Ready(Some(CopiesTreeDiffEntry {
source: source.clone(),
target: diff_entry.path,
value: diff_entry.value.and_then(|(_, target_value)| {
values: diff_entry.values.and_then(|(_, target_value)| {
self.source_tree
.path_value(source)
.map(|source_value| (source_value, target_value))

View file

@ -1170,7 +1170,7 @@ fn has_diff_from_parent(
let mut tree_diff = from_tree.diff_stream(&to_tree, matcher);
async {
while let Some(entry) = tree_diff.next().await {
let (from_value, to_value) = entry.value?;
let (from_value, to_value) = entry.values?;
let from_value = resolve_file_values(store, &entry.path, from_value)?;
if from_value == to_value {
continue;
@ -1197,7 +1197,7 @@ fn matches_diff_from_parent(
let mut tree_diff = from_tree.diff_stream(&to_tree, files_matcher);
async {
while let Some(entry) = tree_diff.next().await {
let (left_value, right_value) = entry.value?;
let (left_value, right_value) = entry.values?;
let left_value = resolve_file_values(store, &entry.path, left_value)?;
if left_value == right_value {
continue;

View file

@ -1388,8 +1388,8 @@ impl TreeState {
let mut diff_stream = Box::pin(
old_tree
.diff_stream(new_tree, matcher)
.map(|TreeDiffEntry { path, value: diff }| async {
match diff {
.map(|TreeDiffEntry { path, values }| async {
match values {
Ok((before, after)) => {
let result = materialize_tree_value(&self.store, &path, after).await;
(path, result.map(|value| (before.is_present(), value)))
@ -1482,8 +1482,8 @@ impl TreeState {
let mut changed_file_states = Vec::new();
let mut deleted_files = HashSet::new();
let mut diff_stream = old_tree.diff_stream(new_tree, matcher.as_ref());
while let Some(TreeDiffEntry { path, value: diff }) = diff_stream.next().await {
let (_before, after) = diff?;
while let Some(TreeDiffEntry { path, values }) = diff_stream.next().await {
let (_before, after) = values?;
if after.is_absent() {
deleted_files.insert(path);
} else {

View file

@ -342,7 +342,7 @@ pub struct TreeDiffEntry {
/// The path.
pub path: RepoPathBuf,
/// The resolved tree values if available.
pub value: BackendResult<(MergedTreeValue, MergedTreeValue)>,
pub values: BackendResult<(MergedTreeValue, MergedTreeValue)>,
}
/// Type alias for the result from `MergedTree::diff_stream()`. We use a
@ -778,7 +778,7 @@ impl Iterator for TreeDiffIterator<'_> {
if let TreeDiffItem::File(path, before, after) = self.stack.pop().unwrap() {
return Some(TreeDiffEntry {
path,
value: Ok((before, after)),
values: Ok((before, after)),
});
} else {
unreachable!();
@ -797,13 +797,13 @@ impl Iterator for TreeDiffIterator<'_> {
(Err(before_err), _) => {
return Some(TreeDiffEntry {
path,
value: Err(before_err),
values: Err(before_err),
})
}
(_, Err(after_err)) => {
return Some(TreeDiffEntry {
path,
value: Err(after_err),
values: Err(after_err),
})
}
};
@ -818,7 +818,7 @@ impl Iterator for TreeDiffIterator<'_> {
if before.is_present() {
return Some(TreeDiffEntry {
path,
value: Ok((before, Merge::absent())),
values: Ok((before, Merge::absent())),
});
}
} else if tree_before && !tree_after {
@ -831,7 +831,7 @@ impl Iterator for TreeDiffIterator<'_> {
} else if !tree_before && !tree_after {
return Some(TreeDiffEntry {
path,
value: Ok((before, after)),
values: Ok((before, after)),
});
}
}
@ -1063,11 +1063,11 @@ impl Stream for TreeDiffStreamImpl<'_> {
Poll::Ready(Some(match result {
Err(err) => TreeDiffEntry {
path: key.path,
value: Err(err),
values: Err(err),
},
Ok((before, after)) => TreeDiffEntry {
path: key.path,
value: Ok((before, after)),
values: Ok((before, after)),
},
}))
}
@ -1077,11 +1077,11 @@ impl Stream for TreeDiffStreamImpl<'_> {
Poll::Ready(Some(match result {
Err(err) => TreeDiffEntry {
path: key.path,
value: Err(err),
values: Err(err),
},
Ok((before, after)) => TreeDiffEntry {
path: key.path,
value: Ok((before, after)),
values: Ok((before, after)),
},
}))
}

View file

@ -106,10 +106,10 @@ pub fn restore_tree(
let mut diff_stream = source.diff_stream(destination, matcher);
while let Some(TreeDiffEntry {
path: repo_path,
value: diff,
values,
}) = diff_stream.next().await
{
let (source_value, _destination_value) = diff?;
let (source_value, _destination_value) = values?;
tree_builder.set_or_remove(repo_path, source_value);
}
Ok::<(), BackendError>(())

View file

@ -36,7 +36,7 @@ fn diff_paths(from_tree: &MergedTree, to_tree: &MergedTree) -> Vec<RepoPathBuf>
from_tree
.diff_stream(to_tree, &EverythingMatcher)
.map(|diff| {
let _ = diff.value.unwrap();
let _ = diff.values.unwrap();
diff.path
})
.collect()

View file

@ -51,17 +51,17 @@ fn file_value(file_id: &FileId) -> TreeValue {
}
fn diff_entry_tuple(diff: TreeDiffEntry) -> (RepoPathBuf, (MergedTreeValue, MergedTreeValue)) {
(diff.path, diff.value.unwrap())
(diff.path, diff.values.unwrap())
}
fn diff_stream_equals_iter(tree1: &MergedTree, tree2: &MergedTree, matcher: &dyn Matcher) {
let iter_diff: Vec<_> = TreeDiffIterator::new(tree1.as_merge(), tree2.as_merge(), matcher)
.map(|diff| (diff.path, diff.value.unwrap()))
.map(|diff| (diff.path, diff.values.unwrap()))
.collect();
let max_concurrent_reads = 10;
let stream_diff: Vec<_> =
TreeDiffStreamImpl::new(tree1.clone(), tree2.clone(), matcher, max_concurrent_reads)
.map(|diff| (diff.path, diff.value.unwrap()))
.map(|diff| (diff.path, diff.values.unwrap()))
.collect()
.block_on();
assert_eq!(stream_diff, iter_diff);
@ -867,7 +867,7 @@ fn test_diff_copy_tracing() {
let diff: Vec<_> = before_merged
.diff_stream_with_copies(&after_merged, &EverythingMatcher, &copy_records)
.map(|diff| (diff.source, diff.target, diff.value.unwrap()))
.map(|diff| (diff.source, diff.target, diff.values.unwrap()))
.collect()
.block_on();
assert_eq!(diff.len(), 3);