From d9ce70c176abee7e82013f89f61b5625b6f489d5 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 28 Aug 2023 07:55:48 -0700 Subject: [PATCH] tests: make `create_tree()` return `MergedTree` I think most tests want a `MergedTree`, so this makes `create_tree()` return that. I kept the old function as `create_single_tree()`. That's now only used in `test_merge_trees` and `test_merged_tree`. I also consistently imported the functions now, something I've considered doing for a long time. --- lib/tests/test_commit_builder.rs | 16 +-- lib/tests/test_diff_summary.rs | 64 +++++------ lib/tests/test_merge_trees.rs | 27 +++-- lib/tests/test_merged_tree.rs | 133 +++++++++++----------- lib/tests/test_revset.rs | 37 +++--- lib/tests/test_rewrite.rs | 19 ++-- lib/tests/test_working_copy.rs | 46 +++----- lib/tests/test_working_copy_concurrent.rs | 14 +-- lib/tests/test_working_copy_sparse.rs | 12 +- lib/testutils/src/lib.rs | 6 +- 10 files changed, 176 insertions(+), 198 deletions(-) diff --git a/lib/tests/test_commit_builder.rs b/lib/tests/test_commit_builder.rs index 7d95917a9..2a11a2479 100644 --- a/lib/tests/test_commit_builder.rs +++ b/lib/tests/test_commit_builder.rs @@ -14,12 +14,12 @@ use jj_lib::backend::{ChangeId, MergedTreeId, MillisSinceEpoch, ObjectId, Signature, Timestamp}; use jj_lib::matchers::EverythingMatcher; -use jj_lib::merged_tree::{DiffSummary, MergedTree}; +use jj_lib::merged_tree::DiffSummary; use jj_lib::repo::Repo; use jj_lib::repo_path::RepoPath; use jj_lib::settings::UserSettings; use test_case::test_case; -use testutils::{assert_rebased, CommitGraphBuilder, TestRepo}; +use testutils::{assert_rebased, create_tree, CommitGraphBuilder, TestRepo}; #[test_case(false ; "local backend")] #[test_case(true ; "git backend")] @@ -31,13 +31,13 @@ fn test_initial(use_git: bool) { let root_file_path = RepoPath::from_internal_string("file"); let dir_file_path = RepoPath::from_internal_string("dir/file"); - let tree = MergedTree::Legacy(testutils::create_tree( + let tree = create_tree( repo, &[ (&root_file_path, "file contents"), (&dir_file_path, "dir/file contents"), ], - )); + ); let mut tx = repo.start_transaction(&settings, "test"); let author_signature = Signature { @@ -102,7 +102,7 @@ fn test_rewrite(use_git: bool) { let root_file_path = RepoPath::from_internal_string("file"); let dir_file_path = RepoPath::from_internal_string("dir/file"); - let initial_tree = testutils::create_tree( + let initial_tree = create_tree( repo, &[ (&root_file_path, "file contents"), @@ -116,19 +116,19 @@ fn test_rewrite(use_git: bool) { .new_commit( &settings, vec![store.root_commit_id().clone()], - initial_tree.legacy_id(), + initial_tree.id(), ) .write() .unwrap(); let repo = tx.commit(); - let rewritten_tree = MergedTree::Legacy(testutils::create_tree( + let rewritten_tree = create_tree( &repo, &[ (&root_file_path, "file contents"), (&dir_file_path, "updated dir/file contents"), ], - )); + ); let config = config::Config::builder() .set_override("user.name", "Rewrite User") diff --git a/lib/tests/test_diff_summary.rs b/lib/tests/test_diff_summary.rs index d988563c0..79ae6c45f 100644 --- a/lib/tests/test_diff_summary.rs +++ b/lib/tests/test_diff_summary.rs @@ -13,10 +13,10 @@ // limitations under the License. use jj_lib::matchers::{EverythingMatcher, FilesMatcher}; -use jj_lib::merged_tree::{DiffSummary, MergedTree}; +use jj_lib::merged_tree::DiffSummary; use jj_lib::repo_path::RepoPath; use test_case::test_case; -use testutils::TestRepo; +use testutils::{create_tree, TestRepo}; #[test_case(false ; "local backend")] #[test_case(true ; "git backend")] @@ -29,7 +29,7 @@ fn test_types(use_git: bool) { let added_path = RepoPath::from_internal_string("added"); let removed_path = RepoPath::from_internal_string("removed"); - let tree1 = testutils::create_tree( + let tree1 = create_tree( repo, &[ (&clean_path, "clean"), @@ -38,7 +38,7 @@ fn test_types(use_git: bool) { ], ); - let tree2 = testutils::create_tree( + let tree2 = create_tree( repo, &[ (&clean_path, "clean"), @@ -48,7 +48,7 @@ fn test_types(use_git: bool) { ); assert_eq!( - MergedTree::Legacy(tree1).diff_summary(&MergedTree::Legacy(tree2), &EverythingMatcher), + tree1.diff_summary(&tree2, &EverythingMatcher), DiffSummary { modified: vec![modified_path], added: vec![added_path], @@ -66,12 +66,11 @@ fn test_tree_file_transition(use_git: bool) { let dir_file_path = RepoPath::from_internal_string("dir/file"); let dir_path = RepoPath::from_internal_string("dir"); - let tree1 = testutils::create_tree(repo, &[(&dir_file_path, "contents")]); - let tree2 = testutils::create_tree(repo, &[(&dir_path, "contents")]); + let tree1 = create_tree(repo, &[(&dir_file_path, "contents")]); + let tree2 = create_tree(repo, &[(&dir_path, "contents")]); assert_eq!( - MergedTree::Legacy(tree1.clone()) - .diff_summary(&MergedTree::Legacy(tree2.clone()), &EverythingMatcher), + tree1.diff_summary(&tree2, &EverythingMatcher), DiffSummary { modified: vec![], added: vec![dir_path.clone()], @@ -79,7 +78,7 @@ fn test_tree_file_transition(use_git: bool) { } ); assert_eq!( - MergedTree::Legacy(tree2).diff_summary(&MergedTree::Legacy(tree1), &EverythingMatcher), + tree2.diff_summary(&tree1, &EverythingMatcher), DiffSummary { modified: vec![], added: vec![dir_file_path], @@ -104,7 +103,7 @@ fn test_sorting(use_git: bool) { let s_b_path = RepoPath::from_internal_string("s/b"); let z_path = RepoPath::from_internal_string("z"); - let tree1 = testutils::create_tree( + let tree1 = create_tree( repo, &[ (&a_path, "before"), @@ -113,7 +112,7 @@ fn test_sorting(use_git: bool) { ], ); - let tree2 = testutils::create_tree( + let tree2 = create_tree( repo, &[ (&a_path, "after"), @@ -129,8 +128,7 @@ fn test_sorting(use_git: bool) { ); assert_eq!( - MergedTree::Legacy(tree1.clone()) - .diff_summary(&MergedTree::Legacy(tree2.clone()), &EverythingMatcher), + tree1.diff_summary(&tree2, &EverythingMatcher), DiffSummary { modified: vec![a_path.clone(), f_a_path.clone(), f_f_a_path.clone()], added: vec![ @@ -145,7 +143,7 @@ fn test_sorting(use_git: bool) { } ); assert_eq!( - MergedTree::Legacy(tree2).diff_summary(&MergedTree::Legacy(tree1), &EverythingMatcher), + tree2.diff_summary(&tree1, &EverythingMatcher), DiffSummary { modified: vec![a_path, f_a_path, f_f_a_path], added: vec![], @@ -163,13 +161,12 @@ fn test_matcher_dir_file_transition(use_git: bool) { let a_path = RepoPath::from_internal_string("a"); let a_a_path = RepoPath::from_internal_string("a/a"); - let tree1 = testutils::create_tree(repo, &[(&a_path, "before")]); - let tree2 = testutils::create_tree(repo, &[(&a_a_path, "after")]); + let tree1 = create_tree(repo, &[(&a_path, "before")]); + let tree2 = create_tree(repo, &[(&a_a_path, "after")]); let matcher = FilesMatcher::new(&[a_path.clone()]); assert_eq!( - MergedTree::Legacy(tree1.clone()) - .diff_summary(&MergedTree::Legacy(tree2.clone()), &matcher), + tree1.diff_summary(&tree2, &matcher), DiffSummary { modified: vec![], added: vec![], @@ -177,8 +174,7 @@ fn test_matcher_dir_file_transition(use_git: bool) { } ); assert_eq!( - MergedTree::Legacy(tree2.clone()) - .diff_summary(&MergedTree::Legacy(tree1.clone()), &matcher), + tree2.diff_summary(&tree1, &matcher), DiffSummary { modified: vec![], added: vec![a_path.clone()], @@ -188,8 +184,7 @@ fn test_matcher_dir_file_transition(use_git: bool) { let matcher = FilesMatcher::new(&[a_a_path.clone()]); assert_eq!( - MergedTree::Legacy(tree1.clone()) - .diff_summary(&MergedTree::Legacy(tree2.clone()), &matcher), + tree1.diff_summary(&tree2, &matcher), DiffSummary { modified: vec![], added: vec![a_a_path.clone()], @@ -197,8 +192,7 @@ fn test_matcher_dir_file_transition(use_git: bool) { } ); assert_eq!( - MergedTree::Legacy(tree2.clone()) - .diff_summary(&MergedTree::Legacy(tree1.clone()), &matcher), + tree2.diff_summary(&tree1, &matcher), DiffSummary { modified: vec![], added: vec![], @@ -208,8 +202,7 @@ fn test_matcher_dir_file_transition(use_git: bool) { let matcher = FilesMatcher::new(&[a_path.clone(), a_a_path.clone()]); assert_eq!( - MergedTree::Legacy(tree1.clone()) - .diff_summary(&MergedTree::Legacy(tree2.clone()), &matcher), + tree1.diff_summary(&tree2, &matcher), DiffSummary { modified: vec![], added: vec![a_a_path.clone()], @@ -217,7 +210,7 @@ fn test_matcher_dir_file_transition(use_git: bool) { } ); assert_eq!( - MergedTree::Legacy(tree2).diff_summary(&MergedTree::Legacy(tree1), &matcher), + tree2.diff_summary(&tree1, &matcher), DiffSummary { modified: vec![], added: vec![a_path], @@ -237,12 +230,12 @@ fn test_matcher_normal_cases(use_git: bool) { let dir2_b_path = RepoPath::from_internal_string("dir2/b"); let z_path = RepoPath::from_internal_string("z"); - let tree1 = testutils::create_tree(repo, &[(&a_path, "before"), (&dir1_a_path, "before")]); + 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 = testutils::create_tree( + let tree2 = create_tree( repo, &[ (&a_path, "after"), @@ -254,8 +247,7 @@ fn test_matcher_normal_cases(use_git: bool) { let matcher = FilesMatcher::new(&[a_path.clone(), z_path.clone()]); assert_eq!( - MergedTree::Legacy(tree1.clone()) - .diff_summary(&MergedTree::Legacy(tree2.clone()), &matcher), + tree1.diff_summary(&tree2, &matcher), DiffSummary { modified: vec![a_path.clone()], added: vec![z_path.clone()], @@ -263,8 +255,7 @@ fn test_matcher_normal_cases(use_git: bool) { } ); assert_eq!( - MergedTree::Legacy(tree2.clone()) - .diff_summary(&MergedTree::Legacy(tree1.clone()), &matcher), + tree2.diff_summary(&tree1, &matcher), DiffSummary { modified: vec![a_path], added: vec![], @@ -274,8 +265,7 @@ fn test_matcher_normal_cases(use_git: bool) { let matcher = FilesMatcher::new(&[dir1_a_path.clone(), dir2_b_path.clone()]); assert_eq!( - MergedTree::Legacy(tree1.clone()) - .diff_summary(&MergedTree::Legacy(tree2.clone()), &matcher), + tree1.diff_summary(&tree2, &matcher), DiffSummary { modified: vec![dir1_a_path.clone()], added: vec![dir2_b_path.clone()], @@ -283,7 +273,7 @@ fn test_matcher_normal_cases(use_git: bool) { } ); assert_eq!( - MergedTree::Legacy(tree2).diff_summary(&MergedTree::Legacy(tree1), &matcher), + tree2.diff_summary(&tree1, &matcher), DiffSummary { modified: vec![dir1_a_path], added: vec![], diff --git a/lib/tests/test_merge_trees.rs b/lib/tests/test_merge_trees.rs index 7aff9d411..0f2e64f7b 100644 --- a/lib/tests/test_merge_trees.rs +++ b/lib/tests/test_merge_trees.rs @@ -13,13 +13,13 @@ // limitations under the License. use itertools::Itertools; -use jj_lib::backend::{MergedTreeId, TreeValue}; +use jj_lib::backend::TreeValue; use jj_lib::repo::Repo; use jj_lib::repo_path::{RepoPath, RepoPathComponent}; use jj_lib::rewrite::rebase_commit; use jj_lib::tree::{merge_trees, Tree}; use test_case::test_case; -use testutils::TestRepo; +use testutils::{create_single_tree, create_tree, TestRepo}; #[test_case(false ; "local backend")] #[test_case(true ; "git backend")] @@ -475,8 +475,7 @@ fn test_simplify_conflict(use_git: bool) { let component = RepoPathComponent::from("file"); let path = RepoPath::from_internal_string("file"); - let write_tree = - |contents: &str| -> Tree { testutils::create_tree(repo, &[(&path, contents)]) }; + let write_tree = |contents: &str| -> Tree { create_single_tree(repo, &[(&path, contents)]) }; let base_tree = write_tree("base contents"); let branch_tree = write_tree("branch contents"); @@ -571,32 +570,32 @@ fn test_simplify_conflict_after_resolving_parent(use_git: bool) { // a conflict since it changed an unrelated line. let path = RepoPath::from_internal_string("dir/file"); let mut tx = repo.start_transaction(&settings, "test"); - let tree_a = testutils::create_tree(repo, &[(&path, "abc\ndef\nghi\n")]); + let tree_a = create_tree(repo, &[(&path, "abc\ndef\nghi\n")]); let commit_a = tx .mut_repo() .new_commit( &settings, vec![repo.store().root_commit_id().clone()], - tree_a.legacy_id(), + tree_a.id(), ) .write() .unwrap(); - let tree_b = testutils::create_tree(repo, &[(&path, "Abc\ndef\nghi\n")]); + let tree_b = create_tree(repo, &[(&path, "Abc\ndef\nghi\n")]); let commit_b = tx .mut_repo() - .new_commit(&settings, vec![commit_a.id().clone()], tree_b.legacy_id()) + .new_commit(&settings, vec![commit_a.id().clone()], tree_b.id()) .write() .unwrap(); - let tree_c = testutils::create_tree(repo, &[(&path, "Abc\ndef\nGhi\n")]); + let tree_c = create_tree(repo, &[(&path, "Abc\ndef\nGhi\n")]); let commit_c = tx .mut_repo() - .new_commit(&settings, vec![commit_b.id().clone()], tree_c.legacy_id()) + .new_commit(&settings, vec![commit_b.id().clone()], tree_c.id()) .write() .unwrap(); - let tree_d = testutils::create_tree(repo, &[(&path, "abC\ndef\nghi\n")]); + let tree_d = create_tree(repo, &[(&path, "abC\ndef\nghi\n")]); let commit_d = tx .mut_repo() - .new_commit(&settings, vec![commit_a.id().clone()], tree_d.legacy_id()) + .new_commit(&settings, vec![commit_a.id().clone()], tree_d.id()) .write() .unwrap(); @@ -611,11 +610,11 @@ fn test_simplify_conflict_after_resolving_parent(use_git: bool) { assert!(!tree_c2.path_value(&path).is_resolved()); // Create the resolved B and rebase C on top. - let tree_b3 = testutils::create_tree(repo, &[(&path, "AbC\ndef\nghi\n")]); + let tree_b3 = create_tree(repo, &[(&path, "AbC\ndef\nghi\n")]); let commit_b3 = tx .mut_repo() .rewrite_commit(&settings, &commit_b2) - .set_tree_id(MergedTreeId::Legacy(tree_b3.id().clone())) + .set_tree_id(tree_b3.id()) .write() .unwrap(); let commit_c3 = rebase_commit(&settings, tx.mut_repo(), &commit_c2, &[commit_b3]).unwrap(); diff --git a/lib/tests/test_merged_tree.rs b/lib/tests/test_merged_tree.rs index 9fb31ce04..20fd9e7c0 100644 --- a/lib/tests/test_merged_tree.rs +++ b/lib/tests/test_merged_tree.rs @@ -21,7 +21,7 @@ use jj_lib::repo::Repo; use jj_lib::repo_path::{RepoPath, RepoPathComponent, RepoPathJoin}; use jj_lib::tree::merge_trees; use pretty_assertions::assert_eq; -use testutils::{create_tree, write_file, write_normal_file, TestRepo}; +use testutils::{create_single_tree, write_file, write_normal_file, TestRepo}; fn file_value(file_id: &FileId) -> TreeValue { TreeValue::File { @@ -221,7 +221,7 @@ fn test_path_value_and_entries() { let modify_delete_path = RepoPath::from_internal_string("dir2/modify_delete"); let file_dir_conflict_path = RepoPath::from_internal_string("file_dir"); let file_dir_conflict_sub_path = RepoPath::from_internal_string("file_dir/file"); - let tree1 = create_tree( + let tree1 = create_single_tree( repo, &[ (&resolved_file_path, "unchanged"), @@ -230,7 +230,7 @@ fn test_path_value_and_entries() { (&file_dir_conflict_path, "1"), ], ); - let tree2 = create_tree( + let tree2 = create_single_tree( repo, &[ (&resolved_file_path, "unchanged"), @@ -239,7 +239,7 @@ fn test_path_value_and_entries() { (&file_dir_conflict_path, "2"), ], ); - let tree3 = create_tree( + let tree3 = create_single_tree( repo, &[ (&resolved_file_path, "unchanged"), @@ -347,7 +347,7 @@ fn test_resolve_success() { let emptied_dir_path = RepoPath::from_internal_string("to-become-empty"); let emptied_dir_file1_path = emptied_dir_path.join(&RepoPathComponent::from("file1")); let emptied_dir_file2_path = emptied_dir_path.join(&RepoPathComponent::from("file2")); - let base1 = create_tree( + let base1 = create_single_tree( repo, &[ (&unchanged_path, "unchanged"), @@ -357,7 +357,7 @@ fn test_resolve_success() { (&emptied_dir_file2_path, "base1"), ], ); - let side1 = create_tree( + let side1 = create_single_tree( repo, &[ (&unchanged_path, "unchanged"), @@ -367,7 +367,7 @@ fn test_resolve_success() { (&emptied_dir_file2_path, "base1"), ], ); - let side2 = create_tree( + let side2 = create_single_tree( repo, &[ (&unchanged_path, "unchanged"), @@ -377,7 +377,7 @@ fn test_resolve_success() { (&emptied_dir_file1_path, "base1"), ], ); - let expected = create_tree( + let expected = create_single_tree( repo, &[ (&unchanged_path, "unchanged"), @@ -408,9 +408,9 @@ fn test_resolve_root_becomes_empty() { let path1 = RepoPath::from_internal_string("dir1/file"); let path2 = RepoPath::from_internal_string("dir2/file"); - let base1 = create_tree(repo, &[(&path1, "base1"), (&path2, "base1")]); - let side1 = create_tree(repo, &[(&path2, "base1")]); - let side2 = create_tree(repo, &[(&path1, "base1")]); + let base1 = create_single_tree(repo, &[(&path1, "base1"), (&path2, "base1")]); + let side1 = create_single_tree(repo, &[(&path2, "base1")]); + let side2 = create_single_tree(repo, &[(&path1, "base1")]); let tree = MergedTree::new(Merge::new(vec![base1], vec![side1, side2])); let resolved = tree.resolve().unwrap(); @@ -426,12 +426,15 @@ fn test_resolve_with_conflict() { // cannot) let trivial_path = RepoPath::from_internal_string("dir1/trivial"); let conflict_path = RepoPath::from_internal_string("dir2/file_conflict"); - let base1 = create_tree(repo, &[(&trivial_path, "base1"), (&conflict_path, "base1")]); - let side1 = create_tree(repo, &[(&trivial_path, "side1"), (&conflict_path, "side1")]); - let side2 = create_tree(repo, &[(&trivial_path, "base1"), (&conflict_path, "side2")]); - let expected_base1 = create_tree(repo, &[(&trivial_path, "side1"), (&conflict_path, "base1")]); - let expected_side1 = create_tree(repo, &[(&trivial_path, "side1"), (&conflict_path, "side1")]); - let expected_side2 = create_tree(repo, &[(&trivial_path, "side1"), (&conflict_path, "side2")]); + let base1 = create_single_tree(repo, &[(&trivial_path, "base1"), (&conflict_path, "base1")]); + let side1 = create_single_tree(repo, &[(&trivial_path, "side1"), (&conflict_path, "side1")]); + let side2 = create_single_tree(repo, &[(&trivial_path, "base1"), (&conflict_path, "side2")]); + let expected_base1 = + create_single_tree(repo, &[(&trivial_path, "side1"), (&conflict_path, "base1")]); + let expected_side1 = + create_single_tree(repo, &[(&trivial_path, "side1"), (&conflict_path, "side1")]); + let expected_side2 = + create_single_tree(repo, &[(&trivial_path, "side1"), (&conflict_path, "side2")]); let tree = MergedTree::new(Merge::new(vec![base1], vec![side1, side2])); let resolved_tree = tree.resolve().unwrap(); @@ -456,7 +459,7 @@ fn test_conflict_iterator() { let dir_file_path = RepoPath::from_internal_string("dir/subdir/dir_file"); let added_dir_path = RepoPath::from_internal_string("dir/new_dir"); let modify_delete_dir_path = RepoPath::from_internal_string("dir/modify_delete_dir"); - let base1 = create_tree( + let base1 = create_single_tree( repo, &[ (&unchanged_path, "unchanged"), @@ -474,7 +477,7 @@ fn test_conflict_iterator() { ), ], ); - let side1 = create_tree( + let side1 = create_single_tree( repo, &[ (&unchanged_path, "unchanged"), @@ -495,7 +498,7 @@ fn test_conflict_iterator() { ), ], ); - let side2 = create_tree( + let side2 = create_single_tree( repo, &[ (&unchanged_path, "unchanged"), @@ -564,23 +567,23 @@ fn test_conflict_iterator_higher_arity() { let two_sided_path = RepoPath::from_internal_string("dir/2-sided"); let three_sided_path = RepoPath::from_internal_string("dir/3-sided"); - let base1 = create_tree( + let base1 = create_single_tree( repo, &[(&two_sided_path, "base1"), (&three_sided_path, "base1")], ); - let base2 = create_tree( + let base2 = create_single_tree( repo, &[(&two_sided_path, "base2"), (&three_sided_path, "base2")], ); - let side1 = create_tree( + let side1 = create_single_tree( repo, &[(&two_sided_path, "side1"), (&three_sided_path, "side1")], ); - let side2 = create_tree( + let side2 = create_single_tree( repo, &[(&two_sided_path, "base1"), (&three_sided_path, "side2")], ); - let side3 = create_tree( + let side3 = create_single_tree( repo, &[(&two_sided_path, "side3"), (&three_sided_path, "side3")], ); @@ -643,7 +646,7 @@ fn test_diff_resolved() { let modified_path = RepoPath::from_internal_string("dir2/file"); let removed_path = RepoPath::from_internal_string("dir3/file"); let added_path = RepoPath::from_internal_string("dir4/file"); - let before = create_tree( + let before = create_single_tree( repo, &[ (&clean_path, "clean"), @@ -651,7 +654,7 @@ fn test_diff_resolved() { (&removed_path, "before"), ], ); - let after = create_tree( + let after = create_single_tree( repo, &[ (&clean_path, "clean"), @@ -706,7 +709,7 @@ fn test_diff_conflicted() { let path2 = RepoPath::from_internal_string("dir2/file"); let path3 = RepoPath::from_internal_string("dir4/file"); let path4 = RepoPath::from_internal_string("dir6/file"); - let left_base = create_tree( + let left_base = create_single_tree( repo, &[ (&path1, "clean-base"), @@ -714,7 +717,7 @@ fn test_diff_conflicted() { (&path3, "left"), ], ); - let left_side1 = create_tree( + let left_side1 = create_single_tree( repo, &[ (&path1, "clean-side1"), @@ -722,7 +725,7 @@ fn test_diff_conflicted() { (&path3, "left"), ], ); - let left_side2 = create_tree( + let left_side2 = create_single_tree( repo, &[ (&path1, "clean-side2"), @@ -730,7 +733,7 @@ fn test_diff_conflicted() { (&path3, "left"), ], ); - let right_base = create_tree( + let right_base = create_single_tree( repo, &[ (&path1, "clean-base"), @@ -739,7 +742,7 @@ fn test_diff_conflicted() { (&path4, "right-base"), ], ); - let right_side1 = create_tree( + let right_side1 = create_single_tree( repo, &[ (&path1, "clean-side1"), @@ -748,7 +751,7 @@ fn test_diff_conflicted() { (&path4, "right-side1"), ], ); - let right_side2 = create_tree( + let right_side2 = create_single_tree( repo, &[ (&path1, "clean-side2"), @@ -816,7 +819,7 @@ fn test_diff_dir_file() { let path5 = RepoPath::from_internal_string("path5"); let path6 = RepoPath::from_internal_string("path6"); let file = RepoPathComponent::from("file"); - let left_base = create_tree( + let left_base = create_single_tree( repo, &[ (&path1, "left"), @@ -827,7 +830,7 @@ fn test_diff_dir_file() { (&path6.join(&file), "left"), ], ); - let left_side1 = create_tree( + let left_side1 = create_single_tree( repo, &[ (&path1, "left"), @@ -838,7 +841,7 @@ fn test_diff_dir_file() { (&path6.join(&file), "left"), ], ); - let left_side2 = create_tree( + let left_side2 = create_single_tree( repo, &[ (&path1, "left"), @@ -849,7 +852,7 @@ fn test_diff_dir_file() { (&path6.join(&file), "left"), ], ); - let right_base = create_tree( + let right_base = create_single_tree( repo, &[ (&path1.join(&file), "right"), @@ -860,7 +863,7 @@ fn test_diff_dir_file() { // path6 is absent ], ); - let right_side1 = create_tree( + let right_side1 = create_single_tree( repo, &[ (&path1.join(&file), "right"), @@ -871,7 +874,7 @@ fn test_diff_dir_file() { (&path6, "right"), ], ); - let right_side2 = create_tree( + let right_side2 = create_single_tree( repo, &[ (&path1.join(&file), "right"), @@ -1037,10 +1040,10 @@ fn test_merge_simple() { let path1 = RepoPath::from_internal_string("dir1/file"); let path2 = RepoPath::from_internal_string("dir2/file"); - let base1 = testutils::create_tree(repo, &[(&path1, "base"), (&path2, "base")]); - let side1 = testutils::create_tree(repo, &[(&path1, "side1"), (&path2, "base")]); - let side2 = testutils::create_tree(repo, &[(&path1, "base"), (&path2, "side2")]); - let expected = testutils::create_tree(repo, &[(&path1, "side1"), (&path2, "side2")]); + let base1 = create_single_tree(repo, &[(&path1, "base"), (&path2, "base")]); + let side1 = create_single_tree(repo, &[(&path1, "side1"), (&path2, "base")]); + let side2 = create_single_tree(repo, &[(&path1, "base"), (&path2, "side2")]); + let expected = create_single_tree(repo, &[(&path1, "side1"), (&path2, "side2")]); let base1_merged = MergedTree::new(Merge::resolved(base1)); let side1_merged = MergedTree::new(Merge::resolved(side1)); let side2_merged = MergedTree::new(Merge::resolved(side2)); @@ -1059,12 +1062,12 @@ fn test_merge_partial_resolution() { // path1 can be resolved, path2 cannot let path1 = RepoPath::from_internal_string("dir1/file"); let path2 = RepoPath::from_internal_string("dir2/file"); - let base1 = testutils::create_tree(repo, &[(&path1, "base"), (&path2, "base")]); - let side1 = testutils::create_tree(repo, &[(&path1, "side1"), (&path2, "side1")]); - let side2 = testutils::create_tree(repo, &[(&path1, "base"), (&path2, "side2")]); - let expected_base1 = testutils::create_tree(repo, &[(&path1, "side1"), (&path2, "base")]); - let expected_side1 = testutils::create_tree(repo, &[(&path1, "side1"), (&path2, "side1")]); - let expected_side2 = testutils::create_tree(repo, &[(&path1, "side1"), (&path2, "side2")]); + let base1 = create_single_tree(repo, &[(&path1, "base"), (&path2, "base")]); + let side1 = create_single_tree(repo, &[(&path1, "side1"), (&path2, "side1")]); + let side2 = create_single_tree(repo, &[(&path1, "base"), (&path2, "side2")]); + let expected_base1 = create_single_tree(repo, &[(&path1, "side1"), (&path2, "base")]); + let expected_side1 = create_single_tree(repo, &[(&path1, "side1"), (&path2, "side1")]); + let expected_side2 = create_single_tree(repo, &[(&path1, "side1"), (&path2, "side2")]); let base1_merged = MergedTree::new(Merge::resolved(base1)); let side1_merged = MergedTree::new(Merge::resolved(side1)); let side2_merged = MergedTree::new(Merge::resolved(side2)); @@ -1089,9 +1092,9 @@ fn test_merge_with_empty_legacy_tree() { .store() .get_tree(&RepoPath::root(), repo.store().empty_tree_id()) .unwrap(); - let side1 = testutils::create_tree(repo, &[(&path1, "side1")]); - let side2 = testutils::create_tree(repo, &[(&path2, "side2")]); - let expected = testutils::create_tree(repo, &[(&path1, "side1"), (&path2, "side2")]); + let side1 = create_single_tree(repo, &[(&path1, "side1")]); + let side2 = create_single_tree(repo, &[(&path2, "side2")]); + let expected = create_single_tree(repo, &[(&path1, "side1"), (&path2, "side2")]); let base1_merged = MergedTree::legacy(base1); let side1_merged = MergedTree::new(Merge::resolved(side1)); let side2_merged = MergedTree::new(Merge::resolved(side2)); @@ -1109,11 +1112,11 @@ fn test_merge_simplify_only() { let repo = &test_repo.repo; let path = RepoPath::from_internal_string("dir1/file"); - let tree1 = testutils::create_tree(repo, &[(&path, "1")]); - let tree2 = testutils::create_tree(repo, &[(&path, "2")]); - let tree3 = testutils::create_tree(repo, &[(&path, "3")]); - let tree4 = testutils::create_tree(repo, &[(&path, "4")]); - let tree5 = testutils::create_tree(repo, &[(&path, "5")]); + let tree1 = create_single_tree(repo, &[(&path, "1")]); + let tree2 = create_single_tree(repo, &[(&path, "2")]); + let tree3 = create_single_tree(repo, &[(&path, "3")]); + let tree4 = create_single_tree(repo, &[(&path, "4")]); + let tree5 = create_single_tree(repo, &[(&path, "5")]); let expected = tree5.clone(); let base1_merged = MergedTree::new(Merge::new( vec![tree1.clone()], @@ -1144,14 +1147,14 @@ fn test_merge_simplify_result() { // The conflict in path1 cannot be resolved, but the conflict in path2 can. let path1 = RepoPath::from_internal_string("dir1/file"); let path2 = RepoPath::from_internal_string("dir2/file"); - let tree1 = testutils::create_tree(repo, &[(&path1, "1"), (&path2, "1")]); - let tree2 = testutils::create_tree(repo, &[(&path1, "2"), (&path2, "2")]); - let tree3 = testutils::create_tree(repo, &[(&path1, "3"), (&path2, "3")]); - let tree4 = testutils::create_tree(repo, &[(&path1, "4"), (&path2, "2")]); - let tree5 = testutils::create_tree(repo, &[(&path1, "4"), (&path2, "1")]); - let expected_base1 = testutils::create_tree(repo, &[(&path1, "1"), (&path2, "3")]); - let expected_side1 = testutils::create_tree(repo, &[(&path1, "2"), (&path2, "3")]); - let expected_side2 = testutils::create_tree(repo, &[(&path1, "3"), (&path2, "3")]); + let tree1 = create_single_tree(repo, &[(&path1, "1"), (&path2, "1")]); + let tree2 = create_single_tree(repo, &[(&path1, "2"), (&path2, "2")]); + let tree3 = create_single_tree(repo, &[(&path1, "3"), (&path2, "3")]); + let tree4 = create_single_tree(repo, &[(&path1, "4"), (&path2, "2")]); + let tree5 = create_single_tree(repo, &[(&path1, "4"), (&path2, "1")]); + let expected_base1 = create_single_tree(repo, &[(&path1, "1"), (&path2, "3")]); + let expected_side1 = create_single_tree(repo, &[(&path1, "2"), (&path2, "3")]); + let expected_side2 = create_single_tree(repo, &[(&path1, "3"), (&path2, "3")]); let side1_merged = MergedTree::new(Merge::new( vec![tree1.clone()], vec![tree2.clone(), tree3.clone()], diff --git a/lib/tests/test_revset.rs b/lib/tests/test_revset.rs index e240bc807..7c7855fda 100644 --- a/lib/tests/test_revset.rs +++ b/lib/tests/test_revset.rs @@ -38,11 +38,11 @@ use jj_lib::revset::{ }; use jj_lib::revset_graph::{ReverseRevsetGraphIterator, RevsetGraphEdge}; use jj_lib::settings::GitSettings; -use jj_lib::tree::merge_trees; use jj_lib::workspace::Workspace; use test_case::test_case; use testutils::{ - create_random_commit, write_random_commit, CommitGraphBuilder, TestRepo, TestWorkspace, + create_random_commit, create_tree, write_random_commit, CommitGraphBuilder, TestRepo, + TestWorkspace, }; fn resolve_symbol(repo: &dyn Repo, symbol: &str) -> Result, RevsetResolutionError> { @@ -2511,7 +2511,7 @@ fn test_evaluate_expression_file(use_git: bool) { let added_clean_clean = RepoPath::from_internal_string("added_clean_clean"); let added_modified_clean = RepoPath::from_internal_string("added_modified_clean"); let added_modified_removed = RepoPath::from_internal_string("added_modified_removed"); - let tree1 = testutils::create_tree( + let tree1 = create_tree( repo, &[ (&added_clean_clean, "1"), @@ -2519,7 +2519,7 @@ fn test_evaluate_expression_file(use_git: bool) { (&added_modified_removed, "1"), ], ); - let tree2 = testutils::create_tree( + let tree2 = create_tree( repo, &[ (&added_clean_clean, "1"), @@ -2527,7 +2527,7 @@ fn test_evaluate_expression_file(use_git: bool) { (&added_modified_removed, "2"), ], ); - let tree3 = testutils::create_tree( + let tree3 = create_tree( repo, &[ (&added_clean_clean, "1"), @@ -2539,20 +2539,20 @@ fn test_evaluate_expression_file(use_git: bool) { .new_commit( &settings, vec![repo.store().root_commit_id().clone()], - tree1.legacy_id(), + tree1.id(), ) .write() .unwrap(); let commit2 = mut_repo - .new_commit(&settings, vec![commit1.id().clone()], tree2.legacy_id()) + .new_commit(&settings, vec![commit1.id().clone()], tree2.id()) .write() .unwrap(); let commit3 = mut_repo - .new_commit(&settings, vec![commit2.id().clone()], tree3.legacy_id()) + .new_commit(&settings, vec![commit2.id().clone()], tree3.id()) .write() .unwrap(); let commit4 = mut_repo - .new_commit(&settings, vec![commit3.id().clone()], tree3.legacy_id()) + .new_commit(&settings, vec![commit3.id().clone()], tree3.id()) .write() .unwrap(); @@ -2622,10 +2622,10 @@ fn test_evaluate_expression_conflict(use_git: bool) { // Create a few trees, including one with a conflict in `file1` let file_path1 = RepoPath::from_internal_string("file1"); let file_path2 = RepoPath::from_internal_string("file2"); - let tree1 = testutils::create_tree(repo, &[(&file_path1, "1"), (&file_path2, "1")]); - let tree2 = testutils::create_tree(repo, &[(&file_path1, "2"), (&file_path2, "2")]); - let tree3 = testutils::create_tree(repo, &[(&file_path1, "3"), (&file_path2, "1")]); - let tree4 = merge_trees(&tree2, &tree1, &tree3).unwrap(); + let tree1 = create_tree(repo, &[(&file_path1, "1"), (&file_path2, "1")]); + let tree2 = create_tree(repo, &[(&file_path1, "2"), (&file_path2, "2")]); + let tree3 = create_tree(repo, &[(&file_path1, "3"), (&file_path2, "1")]); + let tree4 = tree2.merge(&tree1, &tree3).unwrap(); let mut create_commit = |parent_ids, tree_id| { mut_repo @@ -2633,13 +2633,10 @@ fn test_evaluate_expression_conflict(use_git: bool) { .write() .unwrap() }; - let commit1 = create_commit( - vec![repo.store().root_commit_id().clone()], - MergedTreeId::Legacy(tree1.id().clone()), - ); - let commit2 = create_commit(vec![commit1.id().clone()], tree2.legacy_id()); - let commit3 = create_commit(vec![commit2.id().clone()], tree3.legacy_id()); - let commit4 = create_commit(vec![commit3.id().clone()], tree4.legacy_id()); + let commit1 = create_commit(vec![repo.store().root_commit_id().clone()], tree1.id()); + let commit2 = create_commit(vec![commit1.id().clone()], tree2.id()); + let commit3 = create_commit(vec![commit2.id().clone()], tree3.id()); + let commit4 = create_commit(vec![commit3.id().clone()], tree4.id()); // Only commit4 has a conflict assert_eq!( diff --git a/lib/tests/test_rewrite.rs b/lib/tests/test_rewrite.rs index 8e0537fb3..fb5a331ed 100644 --- a/lib/tests/test_rewrite.rs +++ b/lib/tests/test_rewrite.rs @@ -20,7 +20,8 @@ use jj_lib::rewrite::DescendantRebaser; use maplit::{hashmap, hashset}; use test_case::test_case; use testutils::{ - assert_rebased, create_random_commit, write_random_commit, CommitGraphBuilder, TestRepo, + assert_rebased, create_random_commit, create_tree, write_random_commit, CommitGraphBuilder, + TestRepo, }; #[test_case(false ; "local backend")] @@ -856,35 +857,35 @@ fn test_rebase_descendants_contents(use_git: bool) { // A let mut tx = repo.start_transaction(&settings, "test"); let path1 = RepoPath::from_internal_string("file1"); - let tree1 = testutils::create_tree(repo, &[(&path1, "content")]); + let tree1 = create_tree(repo, &[(&path1, "content")]); let commit_a = tx .mut_repo() .new_commit( &settings, vec![repo.store().root_commit_id().clone()], - tree1.legacy_id(), + tree1.id(), ) .write() .unwrap(); let path2 = RepoPath::from_internal_string("file2"); - let tree2 = testutils::create_tree(repo, &[(&path2, "content")]); + let tree2 = create_tree(repo, &[(&path2, "content")]); let commit_b = tx .mut_repo() - .new_commit(&settings, vec![commit_a.id().clone()], tree2.legacy_id()) + .new_commit(&settings, vec![commit_a.id().clone()], tree2.id()) .write() .unwrap(); let path3 = RepoPath::from_internal_string("file3"); - let tree3 = testutils::create_tree(repo, &[(&path3, "content")]); + let tree3 = create_tree(repo, &[(&path3, "content")]); let commit_c = tx .mut_repo() - .new_commit(&settings, vec![commit_b.id().clone()], tree3.legacy_id()) + .new_commit(&settings, vec![commit_b.id().clone()], tree3.id()) .write() .unwrap(); let path4 = RepoPath::from_internal_string("file4"); - let tree4 = testutils::create_tree(repo, &[(&path4, "content")]); + let tree4 = create_tree(repo, &[(&path4, "content")]); let commit_d = tx .mut_repo() - .new_commit(&settings, vec![commit_a.id().clone()], tree4.legacy_id()) + .new_commit(&settings, vec![commit_a.id().clone()], tree4.id()) .write() .unwrap(); diff --git a/lib/tests/test_working_copy.rs b/lib/tests/test_working_copy.rs index 23210f95e..6428c33e6 100644 --- a/lib/tests/test_working_copy.rs +++ b/lib/tests/test_working_copy.rs @@ -33,7 +33,6 @@ use jj_lib::op_store::{OperationId, WorkspaceId}; use jj_lib::repo::{ReadonlyRepo, Repo}; use jj_lib::repo_path::{RepoPath, RepoPathComponent, RepoPathJoin}; use jj_lib::settings::UserSettings; -use jj_lib::tree::merge_trees; use jj_lib::tree_builder::TreeBuilder; use jj_lib::working_copy::{LockedWorkingCopy, SnapshotError, SnapshotOptions, WorkingCopy}; use test_case::test_case; @@ -283,12 +282,11 @@ fn test_conflict_subdirectory() { let empty_tree = create_tree(repo, &[]); let tree1 = create_tree(repo, &[(&path, "0")]); let tree2 = create_tree(repo, &[(&path, "1")]); - let merged_tree = merge_trees(&tree1, &empty_tree, &tree2).unwrap(); + let merged_tree = tree1.merge(&empty_tree, &tree2).unwrap(); let repo = &test_workspace.repo; let wc = test_workspace.workspace.working_copy_mut(); - wc.check_out(repo.op_id().clone(), None, &MergedTree::legacy(tree1)) - .unwrap(); - wc.check_out(repo.op_id().clone(), None, &MergedTree::legacy(merged_tree)) + wc.check_out(repo.op_id().clone(), None, &tree1).unwrap(); + wc.check_out(repo.op_id().clone(), None, &merged_tree) .unwrap(); } @@ -349,14 +347,11 @@ fn test_reset() { let ignored_path = RepoPath::from_internal_string("ignored"); let gitignore_path = RepoPath::from_internal_string(".gitignore"); - let tree_without_file = MergedTree::legacy(testutils::create_tree( - repo, - &[(&gitignore_path, "ignored\n")], - )); - let tree_with_file = MergedTree::legacy(testutils::create_tree( + let tree_without_file = create_tree(repo, &[(&gitignore_path, "ignored\n")]); + let tree_with_file = create_tree( repo, &[(&gitignore_path, "ignored\n"), (&ignored_path, "code")], - )); + ); let wc = test_workspace.workspace.working_copy_mut(); wc.check_out(repo.op_id().clone(), None, &tree_with_file) @@ -403,13 +398,12 @@ fn test_checkout_discard() { let file2_path = RepoPath::from_internal_string("file2"); let store = repo.store(); - let tree1 = testutils::create_tree(&repo, &[(&file1_path, "contents")]); - let tree2 = testutils::create_tree(&repo, &[(&file2_path, "contents")]); + let tree1 = create_tree(&repo, &[(&file1_path, "contents")]); + let tree2 = create_tree(&repo, &[(&file2_path, "contents")]); let wc = test_workspace.workspace.working_copy_mut(); let state_path = wc.state_path().to_path_buf(); - wc.check_out(repo.op_id().clone(), None, &MergedTree::legacy(tree1)) - .unwrap(); + wc.check_out(repo.op_id().clone(), None, &tree1).unwrap(); // Test the setup: the file should exist on disk and in the tree state. assert!(file1_path.to_fs_path(&workspace_root).is_file()); @@ -417,7 +411,7 @@ fn test_checkout_discard() { // Start a checkout let mut locked_wc = wc.start_mutation().unwrap(); - locked_wc.check_out(&MergedTree::legacy(tree2)).unwrap(); + locked_wc.check_out(&tree2).unwrap(); // The change should be reflected in the working copy but not saved assert!(!file1_path.to_fs_path(&workspace_root).is_file()); assert!(file2_path.to_fs_path(&workspace_root).is_file()); @@ -601,10 +595,7 @@ fn test_gitignores_in_ignored_dir(use_git: bool) { let nested_gitignore_path = RepoPath::from_internal_string("ignored/.gitignore"); let ignored_path = RepoPath::from_internal_string("ignored/file"); - let tree1 = MergedTree::legacy(create_tree( - &test_workspace.repo, - &[(&gitignore_path, "ignored\n")], - )); + let tree1 = create_tree(&test_workspace.repo, &[(&gitignore_path, "ignored\n")]); let wc = test_workspace.workspace.working_copy_mut(); wc.check_out(op_id.clone(), None, &tree1).unwrap(); @@ -618,13 +609,13 @@ fn test_gitignores_in_ignored_dir(use_git: bool) { ); // The nested .gitignore is ignored even if it's tracked - let tree2 = MergedTree::resolved(create_tree( + let tree2 = create_tree( &test_workspace.repo, &[ (&gitignore_path, "ignored\n"), (&nested_gitignore_path, "!file\n"), ], - )); + ); let wc = test_workspace.workspace.working_copy_mut(); let mut locked_wc = wc.start_mutation().unwrap(); locked_wc.reset(&tree2).unwrap(); @@ -661,9 +652,7 @@ fn test_gitignores_checkout_never_overwrites_ignored(use_git: bool) { // "contents". The exiting contents ("garbage") shouldn't be replaced in the // working copy. let wc = test_workspace.workspace.working_copy_mut(); - assert!(wc - .check_out(repo.op_id().clone(), None, &MergedTree::legacy(tree)) - .is_err()); + assert!(wc.check_out(repo.op_id().clone(), None, &tree).is_err()); // Check that the old contents are in the working copy let path = workspace_root.join("modified"); @@ -698,8 +687,7 @@ fn test_gitignores_ignored_directory_already_tracked(use_git: bool) { // Check out the tree with the files in `ignored/` let wc = test_workspace.workspace.working_copy_mut(); - wc.check_out(repo.op_id().clone(), None, &MergedTree::legacy(tree)) - .unwrap(); + wc.check_out(repo.op_id().clone(), None, &tree).unwrap(); // Make some changes inside the ignored directory and check that they are // detected when we snapshot. The files that are still there should not be @@ -707,14 +695,14 @@ fn test_gitignores_ignored_directory_already_tracked(use_git: bool) { std::fs::write(modified_path.to_fs_path(&workspace_root), "modified").unwrap(); std::fs::remove_file(deleted_path.to_fs_path(&workspace_root)).unwrap(); let new_tree = test_workspace.snapshot().unwrap(); - let expected_tree = MergedTree::Legacy(create_tree( + let expected_tree = create_tree( &repo, &[ (&gitignore_path, "/ignored/\n"), (&unchanged_path, "contents"), (&modified_path, "modified"), ], - )); + ); assert_eq!( new_tree.entries().collect_vec(), expected_tree.entries().collect_vec() diff --git a/lib/tests/test_working_copy_concurrent.rs b/lib/tests/test_working_copy_concurrent.rs index 42a12c107..23c4b936a 100644 --- a/lib/tests/test_working_copy_concurrent.rs +++ b/lib/tests/test_working_copy_concurrent.rs @@ -16,13 +16,11 @@ use std::cmp::max; use std::thread; use assert_matches::assert_matches; -use jj_lib::backend::MergedTreeId; -use jj_lib::merged_tree::MergedTree; use jj_lib::repo::{Repo, StoreFactories}; use jj_lib::repo_path::RepoPath; use jj_lib::working_copy::{CheckoutError, SnapshotOptions}; use jj_lib::workspace::Workspace; -use testutils::{write_working_copy_file, TestWorkspace}; +use testutils::{create_tree, write_working_copy_file, TestWorkspace}; #[test] fn test_concurrent_checkout() { @@ -82,20 +80,20 @@ fn test_checkout_parallel() { let mut tree_ids = vec![]; for i in 0..num_threads { let path = RepoPath::from_internal_string(format!("file{i}").as_str()); - let tree = testutils::create_tree(repo, &[(&path, "contents")]); - tree_ids.push(MergedTreeId::Legacy(tree.id().clone())); + let tree = create_tree(repo, &[(&path, "contents")]); + tree_ids.push(tree.id()); } // Create another tree just so we can test the update stats reliably from the // first update - let tree = testutils::create_tree( + let tree = create_tree( repo, &[(&RepoPath::from_internal_string("other file"), "contents")], ); test_workspace .workspace .working_copy_mut() - .check_out(repo.op_id().clone(), None, &MergedTree::legacy(tree)) + .check_out(repo.op_id().clone(), None, &tree) .unwrap(); thread::scope(|s| { @@ -146,7 +144,7 @@ fn test_racy_checkout() { let workspace_root = test_workspace.workspace.workspace_root().clone(); let path = RepoPath::from_internal_string("file"); - let tree = MergedTree::legacy(testutils::create_tree(repo, &[(&path, "1")])); + let tree = create_tree(repo, &[(&path, "1")]); let mut num_matches = 0; for _ in 0..100 { diff --git a/lib/tests/test_working_copy_sparse.rs b/lib/tests/test_working_copy_sparse.rs index a8799d8a9..99903cd53 100644 --- a/lib/tests/test_working_copy_sparse.rs +++ b/lib/tests/test_working_copy_sparse.rs @@ -14,11 +14,10 @@ use itertools::Itertools; use jj_lib::matchers::EverythingMatcher; -use jj_lib::merged_tree::MergedTree; use jj_lib::repo::Repo; use jj_lib::repo_path::RepoPath; use jj_lib::working_copy::{CheckoutStats, WorkingCopy}; -use testutils::TestWorkspace; +use testutils::{create_tree, TestWorkspace}; #[test] fn test_sparse_checkout() { @@ -37,7 +36,7 @@ fn test_sparse_checkout() { let dir2_path = RepoPath::from_internal_string("dir2"); let dir2_file1_path = RepoPath::from_internal_string("dir2/file1"); - let tree = testutils::create_tree( + let tree = create_tree( repo, &[ (&root_file1_path, "contents"), @@ -50,8 +49,7 @@ fn test_sparse_checkout() { ); let wc = test_workspace.workspace.working_copy_mut(); - wc.check_out(repo.op_id().clone(), None, &MergedTree::legacy(tree)) - .unwrap(); + wc.check_out(repo.op_id().clone(), None, &tree).unwrap(); // Set sparse patterns to only dir1/ let mut locked_wc = wc.start_mutation().unwrap(); @@ -142,14 +140,14 @@ fn test_sparse_commit() { let dir2_path = RepoPath::from_internal_string("dir2"); let dir2_file1_path = RepoPath::from_internal_string("dir2/file1"); - let tree = MergedTree::resolved(testutils::create_tree( + let tree = create_tree( repo, &[ (&root_file1_path, "contents"), (&dir1_file1_path, "contents"), (&dir2_file1_path, "contents"), ], - )); + ); let wc = test_workspace.workspace.working_copy_mut(); wc.check_out(repo.op_id().clone(), None, &tree).unwrap(); diff --git a/lib/testutils/src/lib.rs b/lib/testutils/src/lib.rs index f189272e7..6bce78491 100644 --- a/lib/testutils/src/lib.rs +++ b/lib/testutils/src/lib.rs @@ -247,7 +247,7 @@ pub fn write_symlink(tree_builder: &mut TreeBuilder, path: &RepoPath, target: &s tree_builder.set(path.clone(), TreeValue::Symlink(id)); } -pub fn create_tree(repo: &Arc, path_contents: &[(&RepoPath, &str)]) -> Tree { +pub fn create_single_tree(repo: &Arc, path_contents: &[(&RepoPath, &str)]) -> Tree { let store = repo.store(); let mut tree_builder = store.tree_builder(store.empty_tree_id().clone()); for (path, contents) in path_contents { @@ -257,6 +257,10 @@ pub fn create_tree(repo: &Arc, path_contents: &[(&RepoPath, &str)] store.get_tree(&RepoPath::root(), &id).unwrap() } +pub fn create_tree(repo: &Arc, path_contents: &[(&RepoPath, &str)]) -> MergedTree { + MergedTree::legacy(create_single_tree(repo, path_contents)) +} + #[must_use] pub fn create_random_tree(repo: &Arc) -> MergedTreeId { let mut tree_builder = repo