diff --git a/cli/src/commands/backout.rs b/cli/src/commands/backout.rs index 1538b848e..ba74d8546 100644 --- a/cli/src/commands/backout.rs +++ b/cli/src/commands/backout.rs @@ -13,7 +13,7 @@ // limitations under the License. use jj_lib::object_id::ObjectId; -use jj_lib::rewrite::back_out_commit; +use jj_lib::rewrite::merge_commit_trees; use tracing::instrument; use crate::cli_util::{CommandHelper, RevisionArg}; @@ -47,12 +47,18 @@ pub(crate) fn cmd_backout( parents.push(destination); } let mut tx = workspace_command.start_transaction(); - back_out_commit( - command.settings(), - tx.mut_repo(), - &commit_to_back_out, - &parents, - )?; + let old_base_tree = commit_to_back_out.parent_tree(tx.mut_repo())?; + let new_base_tree = merge_commit_trees(tx.mut_repo(), &parents)?; + let old_tree = commit_to_back_out.tree()?; + let new_tree = new_base_tree.merge(&old_tree, &old_base_tree)?; + let new_parent_ids = parents.iter().map(|commit| commit.id().clone()).collect(); + tx.mut_repo() + .new_commit(command.settings(), new_parent_ids, new_tree.id()) + .set_description(format!( + "backout of commit {}", + &commit_to_back_out.id().hex() + )) + .write()?; tx.finish( ui, format!("back out commit {}", commit_to_back_out.id().hex()), diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 5c48c4ec6..dd700e075 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -28,7 +28,6 @@ use crate::commit_builder::CommitBuilder; use crate::index::Index; use crate::matchers::{Matcher, Visit}; use crate::merged_tree::{MergedTree, MergedTreeBuilder}; -use crate::object_id::ObjectId; use crate::repo::{MutableRepo, Repo}; use crate::repo_path::RepoPath; use crate::settings::UserSettings; @@ -320,27 +319,6 @@ pub fn rebase_to_dest_parent( } } -pub fn back_out_commit( - settings: &UserSettings, - mut_repo: &mut MutableRepo, - old_commit: &Commit, - new_parents: &[Commit], -) -> BackendResult { - let old_base_tree = old_commit.parent_tree(mut_repo)?; - let new_base_tree = merge_commit_trees(mut_repo, new_parents)?; - let old_tree = old_commit.tree()?; - let new_tree = new_base_tree.merge(&old_tree, &old_base_tree)?; - let new_parent_ids = new_parents - .iter() - .map(|commit| commit.id().clone()) - .collect(); - // TODO: i18n the description based on repo language - mut_repo - .new_commit(settings, new_parent_ids, new_tree.id()) - .set_description(format!("backout of commit {}", &old_commit.id().hex())) - .write() -} - #[derive(Clone, Copy, Default, PartialEq, Eq, Debug)] pub enum EmptyBehaviour { /// Always keep empty commits