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

matchers: simplify FilesMatcher::new() to take slice of paths

This commit is contained in:
Yuya Nishihara 2022-12-28 16:34:24 +09:00
parent c7eaee3d86
commit 996ac22921
3 changed files with 11 additions and 12 deletions

View file

@ -101,9 +101,9 @@ pub struct FilesMatcher {
}
impl FilesMatcher {
pub fn new(files: HashSet<RepoPath>) -> Self {
pub fn new(files: &[RepoPath]) -> Self {
let mut dirs = Dirs::new();
for f in &files {
for f in files {
dirs.add_file(f);
}
FilesMatcher { dirs }
@ -385,7 +385,7 @@ mod tests {
#[test]
fn test_filesmatcher_empty() {
let m = FilesMatcher::new(hashset! {});
let m = FilesMatcher::new(&[]);
assert!(!m.matches(&RepoPath::from_internal_string("file")));
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
assert_eq!(m.visit(&RepoPath::root()), Visit::Nothing);
@ -393,12 +393,12 @@ mod tests {
#[test]
fn test_filesmatcher_nonempty() {
let m = FilesMatcher::new(hashset! {
let m = FilesMatcher::new(&[
RepoPath::from_internal_string("dir1/subdir1/file1"),
RepoPath::from_internal_string("dir1/subdir1/file2"),
RepoPath::from_internal_string("dir1/subdir2/file3"),
RepoPath::from_internal_string("file4"),
});
]);
assert!(!m.matches(&RepoPath::from_internal_string("dir1")));
assert!(!m.matches(&RepoPath::from_internal_string("dir1/subdir1")));

View file

@ -15,7 +15,6 @@
use jujutsu_lib::matchers::{EverythingMatcher, FilesMatcher};
use jujutsu_lib::repo_path::RepoPath;
use jujutsu_lib::tree::DiffSummary;
use maplit::hashset;
use test_case::test_case;
use testutils::TestRepo;
@ -165,7 +164,7 @@ fn test_matcher_dir_file_transition(use_git: bool) {
let tree1 = testutils::create_tree(repo, &[(&a_path, "before")]);
let tree2 = testutils::create_tree(repo, &[(&a_a_path, "after")]);
let matcher = FilesMatcher::new(hashset! {a_path.clone()});
let matcher = FilesMatcher::new(&[a_path.clone()]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher),
DiffSummary {
@ -183,7 +182,7 @@ fn test_matcher_dir_file_transition(use_git: bool) {
}
);
let matcher = FilesMatcher::new(hashset! {a_a_path.clone()});
let matcher = FilesMatcher::new(&[a_a_path.clone()]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher),
DiffSummary {
@ -201,7 +200,7 @@ fn test_matcher_dir_file_transition(use_git: bool) {
}
);
let matcher = FilesMatcher::new(hashset! {a_path.clone(), a_a_path.clone()});
let matcher = FilesMatcher::new(&[a_path.clone(), a_a_path.clone()]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher),
DiffSummary {
@ -246,7 +245,7 @@ fn test_matcher_normal_cases(use_git: bool) {
],
);
let matcher = FilesMatcher::new(hashset! {a_path.clone(), z_path.clone()});
let matcher = FilesMatcher::new(&[a_path.clone(), z_path.clone()]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher),
DiffSummary {
@ -264,7 +263,7 @@ fn test_matcher_normal_cases(use_git: bool) {
}
);
let matcher = FilesMatcher::new(hashset! {dir1_a_path.clone(), dir2_b_path.clone()});
let matcher = FilesMatcher::new(&[dir1_a_path.clone(), dir2_b_path.clone()]);
assert_eq!(
tree1.diff_summary(&tree2, &matcher),
DiffSummary {

View file

@ -1950,7 +1950,7 @@ fn test_filter_by_diff(use_git: bool) {
// matcher API:
let resolve = |file_path: &RepoPath| -> Vec<CommitId> {
let repo_ref = mut_repo.as_repo_ref();
let matcher = FilesMatcher::new([file_path.clone()].into());
let matcher = FilesMatcher::new(&[file_path.clone()]);
let candidates = RevsetExpression::all().evaluate(repo_ref, None).unwrap();
let commit_ids = revset::filter_by_diff(repo_ref, &matcher as &dyn Matcher, candidates)
.iter()