From 06df609482961a463e0bf2121595a0135f67cc85 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Tue, 16 Mar 2021 22:20:42 -0700 Subject: [PATCH] transaction: delete check_out() and set_checkout() helpers --- lib/src/transaction.rs | 13 +------------ lib/src/working_copy.rs | 5 +++-- src/commands.rs | 9 +++++---- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/lib/src/transaction.rs b/lib/src/transaction.rs index ffbf73613..f2eb7188f 100644 --- a/lib/src/transaction.rs +++ b/lib/src/transaction.rs @@ -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) diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index 704bf07c0..fb1e7eeac 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -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(), ¤t_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); diff --git a/src/commands.rs b/src/commands.rs index 67567c846..157dc821f 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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(