diff --git a/src/cli_util.rs b/src/cli_util.rs index 49effcf70..ea5ff9de1 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -878,74 +878,6 @@ impl WorkspaceCommandHelper { Ok(()) } - pub fn run_mergetool( - &self, - ui: &mut Ui, - tree: &Tree, - repo_path: &RepoPath, - ) -> Result { - Ok(crate::merge_tools::run_mergetool( - ui, - tree, - repo_path, - &self.settings, - )?) - } - - pub fn edit_diff( - &self, - ui: &mut Ui, - left_tree: &Tree, - right_tree: &Tree, - instructions: &str, - ) -> Result { - Ok(crate::merge_tools::edit_diff( - ui, - left_tree, - right_tree, - instructions, - self.base_ignores(), - &self.settings, - )?) - } - - pub fn select_diff( - &self, - ui: &mut Ui, - left_tree: &Tree, - right_tree: &Tree, - instructions: &str, - interactive: bool, - matcher: &dyn Matcher, - ) -> Result { - if interactive { - Ok(crate::merge_tools::edit_diff( - ui, - left_tree, - right_tree, - instructions, - self.base_ignores(), - &self.settings, - )?) - } else if matcher.visit(&RepoPath::root()) == Visit::AllRecursively { - // Optimization for a common case - Ok(right_tree.id().clone()) - } else { - let mut tree_builder = self.repo().store().tree_builder(left_tree.id().clone()); - for (repo_path, diff) in left_tree.diff(right_tree, matcher) { - match diff.into_options().1 { - Some(value) => { - tree_builder.set(repo_path, value); - } - None => { - tree_builder.remove(repo_path); - } - } - } - Ok(tree_builder.write_tree()) - } - } - pub fn start_transaction<'a>( &'a mut self, description: &str, @@ -1042,6 +974,76 @@ impl WorkspaceCommandTransaction<'_> { self.tx.mut_repo().edit(workspace_id, commit) } + pub fn run_mergetool( + &self, + ui: &mut Ui, + tree: &Tree, + repo_path: &RepoPath, + ) -> Result { + let settings = &self.helper.settings; + Ok(crate::merge_tools::run_mergetool( + ui, tree, repo_path, settings, + )?) + } + + pub fn edit_diff( + &self, + ui: &mut Ui, + left_tree: &Tree, + right_tree: &Tree, + instructions: &str, + ) -> Result { + let base_ignores = self.helper.base_ignores(); + let settings = &self.helper.settings; + Ok(crate::merge_tools::edit_diff( + ui, + left_tree, + right_tree, + instructions, + base_ignores, + settings, + )?) + } + + pub fn select_diff( + &self, + ui: &mut Ui, + left_tree: &Tree, + right_tree: &Tree, + instructions: &str, + interactive: bool, + matcher: &dyn Matcher, + ) -> Result { + if interactive { + let base_ignores = self.helper.base_ignores(); + let settings = &self.helper.settings; + Ok(crate::merge_tools::edit_diff( + ui, + left_tree, + right_tree, + instructions, + base_ignores, + settings, + )?) + } else if matcher.visit(&RepoPath::root()) == Visit::AllRecursively { + // Optimization for a common case + Ok(right_tree.id().clone()) + } else { + let mut tree_builder = self.repo().store().tree_builder(left_tree.id().clone()); + for (repo_path, diff) in left_tree.diff(right_tree, matcher) { + match diff.into_options().1 { + Some(value) => { + tree_builder.set(repo_path, value); + } + None => { + tree_builder.remove(repo_path); + } + } + } + Ok(tree_builder.write_tree()) + } + } + pub fn write_commit_summary( &self, formatter: &mut dyn Formatter, diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d4352c8fb..d5e6c617a 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2040,7 +2040,7 @@ from the source will be moved into the destination. tx.base_workspace_helper() .format_commit_summary(&destination) ); - let new_parent_tree_id = tx.base_workspace_helper().select_diff( + let new_parent_tree_id = tx.select_diff( ui, &parent_tree, &source_tree, @@ -2127,7 +2127,7 @@ from the source will be moved into the parent. tx.base_workspace_helper().format_commit_summary(&commit), tx.base_workspace_helper().format_commit_summary(parent) ); - let new_parent_tree_id = tx.base_workspace_helper().select_diff( + let new_parent_tree_id = tx.select_diff( ui, &parent.tree(), &commit.tree(), @@ -2202,12 +2202,7 @@ aborted. tx.base_workspace_helper().format_commit_summary(parent), tx.base_workspace_helper().format_commit_summary(&commit) ); - new_parent_tree_id = tx.base_workspace_helper().edit_diff( - ui, - &parent_base_tree, - &parent.tree(), - &instructions, - )?; + new_parent_tree_id = tx.edit_diff(ui, &parent_base_tree, &parent.tree(), &instructions)?; if &new_parent_tree_id == parent_base_tree.id() { return Err(user_error("No changes selected")); } @@ -2278,9 +2273,7 @@ fn cmd_resolve( "Resolve conflicts in commit {}", commit.id().hex() )); - let new_tree_id = tx - .base_workspace_helper() - .run_mergetool(ui, &commit.tree(), repo_path)?; + let new_tree_id = tx.run_mergetool(ui, &commit.tree(), repo_path)?; let new_commit = tx .mut_repo() .rewrite_commit(command.settings(), &commit) @@ -2489,12 +2482,7 @@ don't make any changes, then the operation will be aborted.", .format_commit_summary(&target_commit), ); let base_tree = merge_commit_trees(tx.base_repo().as_repo_ref(), base_commits.as_slice()); - let tree_id = tx.base_workspace_helper().edit_diff( - ui, - &base_tree, - &target_commit.tree(), - &instructions, - )?; + let tree_id = tx.edit_diff(ui, &base_tree, &target_commit.tree(), &instructions)?; if &tree_id == target_commit.tree_id() { ui.write("Nothing changed.\n")?; } else { @@ -2581,7 +2569,7 @@ don't make any changes, then the operation will be aborted. ", tx.base_workspace_helper().format_commit_summary(&commit) ); - let tree_id = tx.base_workspace_helper().select_diff( + let tree_id = tx.select_diff( ui, &base_tree, &commit.tree(),