transaction: delete check_out() and set_checkout() helpers

This commit is contained in:
Martin von Zweigbergk 2021-03-16 22:20:42 -07:00
parent 808d0af66d
commit 06df609482
3 changed files with 9 additions and 18 deletions

View file

@ -19,8 +19,7 @@ use crate::op_heads_store::OpHeadsStore;
use crate::op_store::{OperationId, OperationMetadata};
use crate::operation::Operation;
use crate::repo::{MutableRepo, ReadonlyRepo, RepoRef};
use crate::settings::UserSettings;
use crate::store::{CommitId, Timestamp};
use crate::store::Timestamp;
use crate::store_wrapper::StoreWrapper;
use crate::{op_store, store};
@ -65,16 +64,6 @@ impl<'r> Transaction<'r> {
mut_repo.write_commit(commit)
}
pub fn check_out(&mut self, settings: &UserSettings, commit: &Commit) -> Commit {
let mut_repo = Arc::get_mut(self.repo.as_mut().unwrap()).unwrap();
mut_repo.check_out(settings, commit)
}
pub fn set_checkout(&mut self, id: CommitId) {
let mut_repo = Arc::get_mut(self.repo.as_mut().unwrap()).unwrap();
mut_repo.set_checkout(id);
}
pub fn add_head(&mut self, head: &Commit) {
let mut_repo = Arc::get_mut(self.repo.as_mut().unwrap()).unwrap();
mut_repo.add_head(head)

View file

@ -744,10 +744,11 @@ impl WorkingCopy {
let new_tree_id = self.tree_state().as_mut().unwrap().write_tree().clone();
if &new_tree_id != current_commit.tree().id() {
let mut tx = repo.start_transaction("commit working copy");
let mut_repo = tx.mut_repo();
let commit = CommitBuilder::for_rewrite_from(settings, repo.store(), &current_commit)
.set_tree(new_tree_id)
.write_to_transaction(&mut tx);
tx.set_checkout(commit.id().clone());
.write_to_repo(mut_repo);
mut_repo.set_checkout(commit.id().clone());
let operation = tx.commit();
repo.reload_at(&operation);

View file

@ -636,7 +636,7 @@ fn cmd_checkout(
let wc = owned_wc.lock().unwrap();
wc.commit(ui.settings(), mut_repo);
let mut tx = repo.start_transaction(&format!("check out commit {}", new_commit.id().hex()));
tx.check_out(ui.settings(), &new_commit);
tx.mut_repo().check_out(ui.settings(), &new_commit);
tx.commit();
let stats = update_working_copy(ui, Arc::get_mut(&mut repo).unwrap(), &wc)?;
match stats {
@ -1343,9 +1343,10 @@ fn cmd_new(
parent.tree().id().clone(),
);
let mut tx = repo.start_transaction("new empty commit");
let new_commit = commit_builder.write_to_transaction(&mut tx);
if tx.mut_repo().view().checkout() == parent.id() {
tx.check_out(ui.settings(), &new_commit);
let mut_repo = tx.mut_repo();
let new_commit = commit_builder.write_to_repo(mut_repo);
if mut_repo.view().checkout() == parent.id() {
mut_repo.check_out(ui.settings(), &new_commit);
}
tx.commit();
update_working_copy(