repo: clarify that some repo functions load the repo at head (#111)

This commit is contained in:
Martin von Zweigbergk 2022-03-20 22:13:24 -07:00 committed by Martin von Zweigbergk
parent 749ea62c08
commit ec84de7779
6 changed files with 19 additions and 19 deletions

View File

@ -191,7 +191,7 @@ impl ReadonlyRepo {
})
}
pub fn load(user_settings: &UserSettings, repo_path: PathBuf) -> Arc<ReadonlyRepo> {
pub fn load_at_head(user_settings: &UserSettings, repo_path: PathBuf) -> Arc<ReadonlyRepo> {
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<ReadonlyRepo> {
pub fn reload_at_head(&self) -> Arc<ReadonlyRepo> {
self.loader().load_at_head().resolve()
}

View File

@ -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);
}

View File

@ -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

View File

@ -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);

View File

@ -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()]);
}

View File

@ -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()],