RepoLoader: stop returning Result since the functions cannot currently fail

This commit is contained in:
Martin von Zweigbergk 2021-05-19 13:30:28 -07:00
parent 6809a88d42
commit 525a5116a2
11 changed files with 31 additions and 35 deletions

View file

@ -187,7 +187,7 @@ fn merge_op_heads(
mut op_heads: Vec<Operation>,
) -> Result<UnpublishedOperation, OpHeadResolutionError> {
op_heads.sort_by_key(|op| op.store_operation().metadata.end_time.timestamp.clone());
let base_repo = repo_loader.load_at(&op_heads[0]).unwrap();
let base_repo = repo_loader.load_at(&op_heads[0]);
let mut tx = base_repo.start_transaction("resolve concurrent operations");
let merged_repo = tx.mut_repo();
let neighbors_fn = |op: &Operation| op.parents();
@ -199,8 +199,8 @@ fn merge_op_heads(
&|op: &Operation| op.id().clone(),
)
.unwrap();
let base_repo = repo_loader.load_at(&ancestor_op).unwrap();
let other_repo = repo_loader.load_at(&other_op_head).unwrap();
let base_repo = repo_loader.load_at(&ancestor_op);
let other_repo = repo_loader.load_at(&other_op_head);
merged_repo.merge(&base_repo, &other_repo);
}
let op_parent_ids = op_heads.iter().map(|op| op.id().clone()).collect();

View file

@ -254,7 +254,7 @@ impl ReadonlyRepo {
user_settings: &UserSettings,
wc_path: PathBuf,
) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
RepoLoader::init(user_settings, wc_path)?.load_at_head()
Ok(RepoLoader::init(user_settings, wc_path)?.load_at_head())
}
pub fn loader(&self) -> RepoLoader {
@ -365,11 +365,11 @@ impl ReadonlyRepo {
Transaction::new(mut_repo, description)
}
pub fn reload(&self) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
pub fn reload(&self) -> Arc<ReadonlyRepo> {
self.loader().load_at_head()
}
pub fn reload_at(&self, operation: &Operation) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
pub fn reload_at(&self, operation: &Operation) -> Arc<ReadonlyRepo> {
self.loader().load_at(operation)
}
}
@ -437,13 +437,13 @@ impl RepoLoader {
&self.op_heads_store
}
pub fn load_at_head(&self) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
pub fn load_at_head(&self) -> Arc<ReadonlyRepo> {
let op = self.op_heads_store.get_single_op_head(&self).unwrap();
let view = ReadonlyView::new(op.view().take_store_view());
self._finish_load(op, view)
}
pub fn load_at(&self, op: &Operation) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
pub fn load_at(&self, op: &Operation) -> Arc<ReadonlyRepo> {
let view = ReadonlyView::new(op.view().take_store_view());
self._finish_load(op.clone(), view)
}
@ -473,11 +473,7 @@ impl RepoLoader {
Arc::new(repo)
}
fn _finish_load(
&self,
operation: Operation,
view: ReadonlyView,
) -> Result<Arc<ReadonlyRepo>, RepoLoadError> {
fn _finish_load(&self, operation: Operation, view: ReadonlyView) -> Arc<ReadonlyRepo> {
let working_copy = WorkingCopy::load(
self.store.clone(),
self.wc_path.clone(),
@ -497,7 +493,7 @@ impl RepoLoader {
view,
evolution: Mutex::new(None),
};
Ok(Arc::new(repo))
Arc::new(repo)
}
}

View file

@ -778,7 +778,7 @@ impl WorkingCopy {
// Reload the repo so the new commit is visible in the index and view
// TODO: This is not enough. The new commit is not necessarily still in the
// view when we reload.
repo = repo.reload().unwrap();
repo = repo.reload();
}
_ => {}
}

View file

@ -145,7 +145,7 @@ fn test_bad_locking_interrupted(use_git: bool) {
let initial = testutils::create_random_commit(&settings, &repo)
.set_parents(vec![repo.store().root_commit_id().clone()])
.write_to_new_transaction(&repo, "test");
let repo = repo.reload().unwrap();
let repo = repo.reload();
// Simulate a crash that resulted in the old op-head left in place. We simulate
// it somewhat hackily by copying the .jj/op_heads/ directory before the

View file

@ -79,7 +79,7 @@ fn test_rewrite(use_git: bool) {
CommitBuilder::for_new_commit(&settings, &store, initial_tree.id().clone())
.set_parents(vec![store.root_commit_id().clone()])
.write_to_new_transaction(&repo, "test");
let repo = repo.reload().unwrap();
let repo = repo.reload();
let rewritten_tree = testutils::create_tree(
&repo,

View file

@ -60,7 +60,7 @@ fn test_commit_parallel(use_git: bool) {
for thread in threads {
thread.join().ok().unwrap();
}
let repo = repo.reload().unwrap();
let repo = repo.reload();
// 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);

View file

@ -228,7 +228,7 @@ fn test_import_refs_merge() {
tx2.commit();
// Reload the repo, causing the operations to be merged.
let repo = repo.reload().unwrap();
let repo = repo.reload();
let view = repo.view();
let git_refs = view.git_refs();
@ -369,7 +369,7 @@ fn set_up_push_repos(settings: &UserSettings, temp_dir: &TempDir) -> PushTestSet
let new_commit = testutils::create_random_commit(&settings, &jj_repo)
.set_parents(vec![initial_commit_id])
.write_to_new_transaction(&jj_repo, "test");
let jj_repo = jj_repo.reload().unwrap();
let jj_repo = jj_repo.reload();
PushTestSetup {
source_repo_dir,
jj_repo,
@ -412,7 +412,7 @@ fn test_push_commit_not_fast_forward() {
let mut setup = set_up_push_repos(&settings, &temp_dir);
let new_commit = testutils::create_random_commit(&settings, &setup.jj_repo)
.write_to_new_transaction(&setup.jj_repo, "test");
setup.jj_repo = setup.jj_repo.reload().unwrap();
setup.jj_repo = setup.jj_repo.reload();
let result = git::push_commit(
&setup.jj_repo.store().git_repo().unwrap(),
&new_commit,

View file

@ -302,7 +302,7 @@ fn test_index_commits_incremental(use_git: bool) {
let root_commit = repo.store().root_commit();
let commit_a =
child_commit(&settings, &repo, &root_commit).write_to_new_transaction(&repo, "test");
repo = repo.reload().unwrap();
repo = repo.reload();
let index = repo.index();
// There should be the root commit and the working copy commit, plus
@ -349,7 +349,7 @@ fn test_index_commits_incremental_empty_transaction(use_git: bool) {
let root_commit = repo.store().root_commit();
let commit_a =
child_commit(&settings, &repo, &root_commit).write_to_new_transaction(&repo, "test");
repo = repo.reload().unwrap();
repo = repo.reload();
let index = repo.index();
// There should be the root commit and the working copy commit, plus
@ -393,7 +393,7 @@ fn test_index_commits_incremental_already_indexed(use_git: bool) {
let root_commit = repo.store().root_commit();
let commit_a =
child_commit(&settings, &repo, &root_commit).write_to_new_transaction(&repo, "test");
repo = repo.reload().unwrap();
repo = repo.reload();
assert!(repo.index().has_id(commit_a.id()));
assert_eq!(repo.index().num_commits(), 2 + 1);

View file

@ -58,12 +58,12 @@ fn test_load_at_operation(use_git: bool) {
// If we load the repo at head, we should not see the commit since it was
// removed
let loader = RepoLoader::init(&settings, repo.working_copy_path().clone()).unwrap();
let head_repo = loader.load_at_head().unwrap();
let head_repo = loader.load_at_head();
assert!(!head_repo.view().heads().contains(commit.id()));
// If we load the repo at the previous operation, we should see the commit since
// it has not been removed yet
let loader = RepoLoader::init(&settings, repo.working_copy_path().clone()).unwrap();
let old_repo = loader.load_at(&repo.operation()).unwrap();
let old_repo = loader.load_at(&repo.operation());
assert!(old_repo.view().heads().contains(commit.id()));
}

View file

@ -66,7 +66,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().unwrap();
let repo = repo.reload();
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();
@ -76,7 +76,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().unwrap();
let _repo = repo.reload();
assert_eq!(list_dir(&op_heads_dir), vec![op_id2.hex()]);
}
@ -112,7 +112,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().unwrap();
let repo = repo.reload();
let merged_op_id = repo.op_id().clone();
assert_ne!(merged_op_id, op_id0);
assert_ne!(merged_op_id, op_id1);
@ -136,7 +136,7 @@ fn test_isolation(use_git: bool) {
let initial = testutils::create_random_commit(&settings, &repo)
.set_parents(vec![repo.store().root_commit_id().clone()])
.write_to_new_transaction(&repo, "test");
let repo = repo.reload().unwrap();
let repo = repo.reload();
let mut tx1 = repo.start_transaction("transaction 1");
let mut_repo1 = tx1.mut_repo();
@ -184,7 +184,7 @@ fn test_isolation(use_git: bool) {
tx2.commit();
assert_heads(repo.as_repo_ref(), vec![&wc_id, initial.id()]);
// After reload, the base repo sees both rewrites.
let repo = repo.reload().unwrap();
let repo = repo.reload();
assert_heads(
repo.as_repo_ref(),
vec![&wc_id, initial.id(), rewrite1.id(), rewrite2.id()],

View file

@ -123,9 +123,9 @@ fn get_repo(ui: &Ui, matches: &ArgMatches) -> Result<Arc<ReadonlyRepo>, CommandE
let loader = RepoLoader::init(ui.settings(), wc_path)?;
if let Some(op_str) = matches.value_of("at_op") {
let op = resolve_single_op_from_store(loader.op_store(), op_str)?;
Ok(loader.load_at(&op)?)
Ok(loader.load_at(&op))
} else {
Ok(loader.load_at_head()?)
Ok(loader.load_at_head())
}
}
@ -2199,8 +2199,8 @@ fn cmd_op_undo(
}
let mut tx = repo_command.start_transaction(&format!("undo operation {}", bad_op.id().hex()));
let bad_repo = repo.loader().load_at(&bad_op)?;
let parent_repo = repo.loader().load_at(&parent_ops[0])?;
let bad_repo = repo.loader().load_at(&bad_op);
let parent_repo = repo.loader().load_at(&parent_ops[0]);
tx.mut_repo().merge(&bad_repo, &parent_repo);
repo_command.finish_transaction(ui, tx)?;