From 43bf19531458ce82d8bded33f575b053615fdf90 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 22 Aug 2024 20:51:10 +0900 Subject: [PATCH] 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(). --- cli/src/commands/fix.rs | 4 ++-- cli/src/diff_util.rs | 24 ++++++++++++------------ cli/src/merge_tools/builtin.rs | 2 +- lib/src/conflicts.rs | 10 +++++----- lib/src/copies.rs | 8 ++++---- lib/src/default_index/revset_engine.rs | 4 ++-- lib/src/local_working_copy.rs | 8 ++++---- lib/src/merged_tree.rs | 20 ++++++++++---------- lib/src/rewrite.rs | 4 ++-- lib/tests/test_commit_builder.rs | 2 +- lib/tests/test_merged_tree.rs | 8 ++++---- 11 files changed, 47 insertions(+), 47 deletions(-) diff --git a/cli/src/commands/fix.rs b/cli/src/commands/fix.rs index 19113b0d2..1df34caf1 100644 --- a/cli/src/commands/fix.rs +++ b/cli/src/commands/fix.rs @@ -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. diff --git a/cli/src/diff_util.rs b/cli/src/diff_util.rs index 46c03228c..1ff7f2a1d 100644 --- a/cli/src/diff_util.rs +++ b/cli/src/diff_util.rs @@ -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"), "{}{} {}", diff --git a/cli/src/merge_tools/builtin.rs b/cli/src/merge_tools/builtin.rs index c7be2993f..a2dbdc1ef 100644 --- a/cli/src/merge_tools/builtin.rs +++ b/cli/src/merge_tools/builtin.rs @@ -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)?; diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index f0399dbb9..3805b8fd4 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -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, } } } diff --git a/lib/src/copies.rs b/lib/src/copies.rs index db51edf1f..78160a2e3 100644 --- a/lib/src/copies.rs +++ b/lib/src/copies.rs @@ -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)) diff --git a/lib/src/default_index/revset_engine.rs b/lib/src/default_index/revset_engine.rs index 824a13223..36bc7e220 100644 --- a/lib/src/default_index/revset_engine.rs +++ b/lib/src/default_index/revset_engine.rs @@ -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; diff --git a/lib/src/local_working_copy.rs b/lib/src/local_working_copy.rs index 930eb0f3e..6efc258a7 100644 --- a/lib/src/local_working_copy.rs +++ b/lib/src/local_working_copy.rs @@ -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 { diff --git a/lib/src/merged_tree.rs b/lib/src/merged_tree.rs index bdc730ebd..09c2f4b36 100644 --- a/lib/src/merged_tree.rs +++ b/lib/src/merged_tree.rs @@ -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)), }, })) } diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 94c165dde..2a8164a3d 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -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>(()) diff --git a/lib/tests/test_commit_builder.rs b/lib/tests/test_commit_builder.rs index c3bdf6345..d33e06150 100644 --- a/lib/tests/test_commit_builder.rs +++ b/lib/tests/test_commit_builder.rs @@ -36,7 +36,7 @@ fn diff_paths(from_tree: &MergedTree, to_tree: &MergedTree) -> Vec from_tree .diff_stream(to_tree, &EverythingMatcher) .map(|diff| { - let _ = diff.value.unwrap(); + let _ = diff.values.unwrap(); diff.path }) .collect() diff --git a/lib/tests/test_merged_tree.rs b/lib/tests/test_merged_tree.rs index c3efb2dc6..0af49791e 100644 --- a/lib/tests/test_merged_tree.rs +++ b/lib/tests/test_merged_tree.rs @@ -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, ©_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);