From ec84de77795d36004f9cf2b6048d56651256654f Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sun, 20 Mar 2022 22:13:24 -0700 Subject: [PATCH] repo: clarify that some repo functions load the repo at head (#111) --- lib/src/repo.rs | 4 ++-- lib/tests/test_bad_locking.rs | 4 ++-- lib/tests/test_commit_concurrent.rs | 6 +++--- lib/tests/test_index.rs | 6 +++--- lib/tests/test_operations.rs | 8 ++++---- lib/tests/test_view.rs | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/src/repo.rs b/lib/src/repo.rs index fcb36d87f..61af83a79 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -191,7 +191,7 @@ impl ReadonlyRepo { }) } - pub fn load(user_settings: &UserSettings, repo_path: PathBuf) -> Arc { + pub fn load_at_head(user_settings: &UserSettings, repo_path: PathBuf) -> Arc { RepoLoader::init(user_settings, repo_path) .load_at_head() .resolve() @@ -278,7 +278,7 @@ impl ReadonlyRepo { Transaction::new(mut_repo, description) } - pub fn reload(&self) -> Arc { + pub fn reload_at_head(&self) -> Arc { self.loader().load_at_head().resolve() } diff --git a/lib/tests/test_bad_locking.rs b/lib/tests/test_bad_locking.rs index 35d6b3b31..ab4de258f 100644 --- a/lib/tests/test_bad_locking.rs +++ b/lib/tests/test_bad_locking.rs @@ -171,10 +171,10 @@ fn test_bad_locking_interrupted(use_git: bool) { copy_directory(&backup_path, &op_heads_dir); // Reload the repo and check that only the new head is present. - let reloaded_repo = ReadonlyRepo::load(&settings, repo.repo_path().clone()); + let reloaded_repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path().clone()); assert_eq!(reloaded_repo.op_id(), &op_id); // Reload once more to make sure that the .jj/op_heads/ directory was updated // correctly. - let reloaded_repo = ReadonlyRepo::load(&settings, repo.repo_path().clone()); + let reloaded_repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path().clone()); assert_eq!(reloaded_repo.op_id(), &op_id); } diff --git a/lib/tests/test_commit_concurrent.rs b/lib/tests/test_commit_concurrent.rs index 7b0c04386..31521c33b 100644 --- a/lib/tests/test_commit_concurrent.rs +++ b/lib/tests/test_commit_concurrent.rs @@ -61,7 +61,7 @@ fn test_commit_parallel(use_git: bool) { for thread in threads { thread.join().ok().unwrap(); } - let repo = repo.reload(); + let repo = repo.reload_at_head(); // One commit per thread plus the commit from the initial checkout on top of the // root commit assert_eq!(repo.view().heads().len(), num_threads + 1); @@ -84,7 +84,7 @@ fn test_commit_parallel_instances(use_git: bool) { let mut threads = vec![]; for _ in 0..num_threads { let settings = settings.clone(); - let repo = ReadonlyRepo::load(&settings, repo.repo_path().clone()); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path().clone()); let handle = thread::spawn(move || { let mut tx = repo.start_transaction("test"); testutils::create_random_commit(&settings, &repo).write_to_repo(tx.mut_repo()); @@ -97,7 +97,7 @@ fn test_commit_parallel_instances(use_git: bool) { } // One commit per thread plus the commit from the initial checkout on top of the // root commit - let repo = ReadonlyRepo::load(&settings, repo.repo_path().clone()); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path().clone()); assert_eq!(repo.view().heads().len(), num_threads + 1); // One addition operation for initializing the repo, one for checking out the diff --git a/lib/tests/test_index.rs b/lib/tests/test_index.rs index c4201095f..51fabb758 100644 --- a/lib/tests/test_index.rs +++ b/lib/tests/test_index.rs @@ -257,7 +257,7 @@ fn test_index_commits_previous_operations(use_git: bool) { std::fs::remove_dir_all(&index_operations_dir).unwrap(); std::fs::create_dir(&index_operations_dir).unwrap(); - let repo = ReadonlyRepo::load(&settings, repo.repo_path().clone()); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path().clone()); let index = repo.index(); // There should be the root commit, plus 3 more assert_eq!(index.num_commits(), 1 + 3); @@ -302,7 +302,7 @@ fn test_index_commits_incremental(use_git: bool) { let commit_c = child_commit(&settings, &repo, &commit_b).write_to_repo(tx.mut_repo()); tx.commit(); - let repo = ReadonlyRepo::load(&settings, repo.repo_path().clone()); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path().clone()); let index = repo.index(); // There should be the root commit, plus 3 more assert_eq!(index.num_commits(), 1 + 3); @@ -345,7 +345,7 @@ fn test_index_commits_incremental_empty_transaction(use_git: bool) { repo.start_transaction("test").commit(); - let repo = ReadonlyRepo::load(&settings, repo.repo_path().clone()); + let repo = ReadonlyRepo::load_at_head(&settings, repo.repo_path().clone()); let index = repo.index(); // There should be the root commit, plus 1 more assert_eq!(index.num_commits(), 1 + 1); diff --git a/lib/tests/test_operations.rs b/lib/tests/test_operations.rs index 51a491d9b..614dfb59e 100644 --- a/lib/tests/test_operations.rs +++ b/lib/tests/test_operations.rs @@ -68,7 +68,7 @@ fn test_consecutive_operations(use_git: bool) { assert_ne!(op_id1, op_id0); assert_eq!(list_dir(&op_heads_dir), vec![op_id1.hex()]); - let repo = repo.reload(); + let repo = repo.reload_at_head(); let mut tx2 = repo.start_transaction("transaction 2"); testutils::create_random_commit(&settings, &repo).write_to_repo(tx2.mut_repo()); let op_id2 = tx2.commit().operation().id().clone(); @@ -78,7 +78,7 @@ fn test_consecutive_operations(use_git: bool) { // Reloading the repo makes no difference (there are no conflicting operations // to resolve). - let _repo = repo.reload(); + let _repo = repo.reload_at_head(); assert_eq!(list_dir(&op_heads_dir), vec![op_id2.hex()]); } @@ -115,7 +115,7 @@ fn test_concurrent_operations(use_git: bool) { assert_eq!(actual_heads_on_disk, expected_heads_on_disk); // Reloading the repo causes the operations to be merged - let repo = repo.reload(); + let repo = repo.reload_at_head(); let merged_op_id = repo.op_id().clone(); assert_ne!(merged_op_id, op_id0); assert_ne!(merged_op_id, op_id1); @@ -175,6 +175,6 @@ fn test_isolation(use_git: bool) { tx2.commit(); assert_heads(repo.as_repo_ref(), vec![initial.id()]); // After reload, the base repo sees both rewrites. - let repo = repo.reload(); + let repo = repo.reload_at_head(); assert_heads(repo.as_repo_ref(), vec![rewrite1.id(), rewrite2.id()]); } diff --git a/lib/tests/test_view.rs b/lib/tests/test_view.rs index 411ab1403..16f42f967 100644 --- a/lib/tests/test_view.rs +++ b/lib/tests/test_view.rs @@ -121,7 +121,7 @@ fn test_merge_views_heads() { tx2.mut_repo().add_public_head(&public_head_add_tx2); tx2.commit(); - let repo = repo.reload(); + let repo = repo.reload_at_head(); let expected_heads = hashset! { head_unchanged.id().clone(), @@ -215,7 +215,7 @@ fn test_merge_views_checkout() { std::thread::sleep(std::time::Duration::from_millis(1)); tx2.commit(); - let repo = repo.reload(); + let repo = repo.reload_at_head(); // We currently arbitrarily pick the first transaction's checkout (first by // transaction end time). @@ -302,7 +302,7 @@ fn test_merge_views_branches() { ); tx2.commit(); - let repo = repo.reload(); + let repo = repo.reload_at_head(); let expected_main_branch = BranchTarget { local_target: Some(RefTarget::Conflict { removes: vec![main_branch_local_tx0.id().clone()], @@ -360,7 +360,7 @@ fn test_merge_views_tags() { .set_tag("v1.0".to_string(), RefTarget::Normal(v1_tx2.id().clone())); tx2.commit(); - let repo = repo.reload(); + let repo = repo.reload_at_head(); let expected_v1 = RefTarget::Conflict { removes: vec![v1_tx0.id().clone()], adds: vec![v1_tx1.id().clone(), v1_tx2.id().clone()], @@ -422,7 +422,7 @@ fn test_merge_views_git_refs() { ); tx2.commit(); - let repo = repo.reload(); + let repo = repo.reload_at_head(); let expected_main_branch = RefTarget::Conflict { removes: vec![main_branch_tx0.id().clone()], adds: vec![main_branch_tx1.id().clone(), main_branch_tx2.id().clone()],