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

merged_tree: remove .diff_summary()

There are no non-test callers since 452fecb7c4 "cli: colorize diff summary
and sort by path."
This commit is contained in:
Yuya Nishihara 2024-08-05 17:33:14 +09:00
parent d435a8a793
commit d061c3782f
3 changed files with 0 additions and 316 deletions

View file

@ -66,17 +66,6 @@ impl MergedTreeVal<'_> {
}
}
/// Summary of the changes between two trees.
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct DiffSummary {
/// Modified files
pub modified: Vec<RepoPathBuf>,
/// Added files
pub added: Vec<RepoPathBuf>,
/// Removed files
pub removed: Vec<RepoPathBuf>,
}
impl MergedTree {
/// Creates a new `MergedTree` representing a single tree without conflicts.
pub fn resolved(tree: Tree) -> Self {
@ -354,36 +343,6 @@ impl MergedTree {
}
}
/// Collects lists of modified, added, and removed files between this tree
/// and another tree.
pub fn diff_summary(
&self,
other: &MergedTree,
matcher: &dyn Matcher,
) -> BackendResult<DiffSummary> {
let mut modified = vec![];
let mut added = vec![];
let mut removed = vec![];
for (file, diff) in self.diff(other, matcher) {
let (before, after) = diff?;
if before.is_absent() {
added.push(file);
} else if after.is_absent() {
removed.push(file);
} else {
modified.push(file);
}
}
modified.sort();
added.sort();
removed.sort();
Ok(DiffSummary {
modified,
added,
removed,
})
}
/// Merges this tree with `other`, using `base` as base.
pub fn merge(&self, base: &MergedTree, other: &MergedTree) -> BackendResult<MergedTree> {
// Convert legacy trees to merged trees and unwrap to `Merge<Tree>`

View file

@ -11,7 +11,6 @@ mod test_commit_builder;
mod test_commit_concurrent;
mod test_conflicts;
mod test_default_revset_graph_iterator;
mod test_diff_summary;
mod test_git;
mod test_git_backend;
mod test_gpg;

View file

@ -1,274 +0,0 @@
// Copyright 2020 The Jujutsu Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use jj_lib::matchers::{EverythingMatcher, FilesMatcher};
use jj_lib::merged_tree::DiffSummary;
use jj_lib::repo_path::{RepoPath, RepoPathBuf};
use testutils::{create_tree, TestRepo};
fn to_owned_path_vec(paths: &[&RepoPath]) -> Vec<RepoPathBuf> {
paths.iter().map(|&path| path.to_owned()).collect()
}
#[test]
fn test_types() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let clean_path = RepoPath::from_internal_string("clean");
let modified_path = RepoPath::from_internal_string("modified");
let added_path = RepoPath::from_internal_string("added");
let removed_path = RepoPath::from_internal_string("removed");
let tree1 = create_tree(
repo,
&[
(clean_path, "clean"),
(modified_path, "contents before"),
(removed_path, "removed contents"),
],
);
let tree2 = create_tree(
repo,
&[
(clean_path, "clean"),
(modified_path, "contents after"),
(added_path, "added contents"),
],
);
assert_eq!(
tree1.diff_summary(&tree2, &EverythingMatcher).unwrap(),
DiffSummary {
modified: to_owned_path_vec(&[modified_path]),
added: to_owned_path_vec(&[added_path]),
removed: to_owned_path_vec(&[removed_path]),
}
);
}
#[test]
fn test_tree_file_transition() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let dir_file_path = RepoPath::from_internal_string("dir/file");
let dir_path = RepoPath::from_internal_string("dir");
let tree1 = create_tree(repo, &[(dir_file_path, "contents")]);
let tree2 = create_tree(repo, &[(dir_path, "contents")]);
assert_eq!(
tree1.diff_summary(&tree2, &EverythingMatcher).unwrap(),
DiffSummary {
modified: vec![],
added: to_owned_path_vec(&[dir_path]),
removed: to_owned_path_vec(&[dir_file_path]),
}
);
assert_eq!(
tree2.diff_summary(&tree1, &EverythingMatcher).unwrap(),
DiffSummary {
modified: vec![],
added: to_owned_path_vec(&[dir_file_path]),
removed: to_owned_path_vec(&[dir_path]),
}
);
}
#[test]
fn test_sorting() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let a_path = RepoPath::from_internal_string("a");
let b_path = RepoPath::from_internal_string("b");
let f_a_path = RepoPath::from_internal_string("f/a");
let f_b_path = RepoPath::from_internal_string("f/b");
let f_f_a_path = RepoPath::from_internal_string("f/f/a");
let f_f_b_path = RepoPath::from_internal_string("f/f/b");
let n_path = RepoPath::from_internal_string("n");
let s_b_path = RepoPath::from_internal_string("s/b");
let z_path = RepoPath::from_internal_string("z");
let tree1 = create_tree(
repo,
&[
(a_path, "before"),
(f_a_path, "before"),
(f_f_a_path, "before"),
],
);
let tree2 = create_tree(
repo,
&[
(a_path, "after"),
(b_path, "after"),
(f_a_path, "after"),
(f_b_path, "after"),
(f_f_a_path, "after"),
(f_f_b_path, "after"),
(n_path, "after"),
(s_b_path, "after"),
(z_path, "after"),
],
);
assert_eq!(
tree1.diff_summary(&tree2, &EverythingMatcher).unwrap(),
DiffSummary {
modified: to_owned_path_vec(&[a_path, f_a_path, f_f_a_path]),
added: to_owned_path_vec(&[b_path, f_b_path, f_f_b_path, n_path, s_b_path, z_path]),
removed: vec![],
}
);
assert_eq!(
tree2.diff_summary(&tree1, &EverythingMatcher).unwrap(),
DiffSummary {
modified: to_owned_path_vec(&[a_path, f_a_path, f_f_a_path]),
added: vec![],
removed: to_owned_path_vec(&[b_path, f_b_path, f_f_b_path, n_path, s_b_path, z_path]),
}
);
}
#[test]
fn test_matcher_dir_file_transition() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let a_path = RepoPath::from_internal_string("a");
let a_a_path = RepoPath::from_internal_string("a/a");
let tree1 = create_tree(repo, &[(a_path, "before")]);
let tree2 = create_tree(repo, &[(a_a_path, "after")]);
let matcher = FilesMatcher::new([&a_path]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher).unwrap(),
DiffSummary {
modified: vec![],
added: vec![],
removed: to_owned_path_vec(&[a_path]),
}
);
assert_eq!(
tree2.diff_summary(&tree1, &matcher).unwrap(),
DiffSummary {
modified: vec![],
added: to_owned_path_vec(&[a_path]),
removed: vec![],
}
);
let matcher = FilesMatcher::new([a_a_path]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher).unwrap(),
DiffSummary {
modified: vec![],
added: to_owned_path_vec(&[a_a_path]),
removed: vec![],
}
);
assert_eq!(
tree2.diff_summary(&tree1, &matcher).unwrap(),
DiffSummary {
modified: vec![],
added: vec![],
removed: to_owned_path_vec(&[a_a_path]),
}
);
let matcher = FilesMatcher::new([a_path, a_a_path]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher).unwrap(),
DiffSummary {
modified: vec![],
added: to_owned_path_vec(&[a_a_path]),
removed: to_owned_path_vec(&[a_path]),
}
);
assert_eq!(
tree2.diff_summary(&tree1, &matcher).unwrap(),
DiffSummary {
modified: vec![],
added: to_owned_path_vec(&[a_path]),
removed: to_owned_path_vec(&[a_a_path]),
}
);
}
#[test]
fn test_matcher_normal_cases() {
let test_repo = TestRepo::init();
let repo = &test_repo.repo;
let a_path = RepoPath::from_internal_string("a");
let dir1_a_path = RepoPath::from_internal_string("dir1/a");
let dir2_b_path = RepoPath::from_internal_string("dir2/b");
let z_path = RepoPath::from_internal_string("z");
let tree1 = create_tree(repo, &[(a_path, "before"), (dir1_a_path, "before")]);
// File "a" gets modified
// File "dir1/a" gets modified
// File "dir2/b" gets created
// File "z" gets created
let tree2 = create_tree(
repo,
&[
(a_path, "after"),
(dir1_a_path, "after"),
(dir2_b_path, "after"),
(z_path, "after"),
],
);
let matcher = FilesMatcher::new([a_path, z_path]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher).unwrap(),
DiffSummary {
modified: to_owned_path_vec(&[a_path]),
added: to_owned_path_vec(&[z_path]),
removed: vec![],
}
);
assert_eq!(
tree2.diff_summary(&tree1, &matcher).unwrap(),
DiffSummary {
modified: to_owned_path_vec(&[a_path]),
added: vec![],
removed: to_owned_path_vec(&[z_path]),
}
);
let matcher = FilesMatcher::new([dir1_a_path, dir2_b_path]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher).unwrap(),
DiffSummary {
modified: to_owned_path_vec(&[dir1_a_path]),
added: to_owned_path_vec(&[dir2_b_path]),
removed: vec![],
}
);
assert_eq!(
tree2.diff_summary(&tree1, &matcher).unwrap(),
DiffSummary {
modified: to_owned_path_vec(&[dir1_a_path]),
added: vec![],
removed: to_owned_path_vec(&[dir2_b_path]),
}
);
}