mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 14:57:14 +00:00
backout: inline rewrite::back_out_commit
This commit is contained in:
parent
456356aacb
commit
82bab36c0e
2 changed files with 13 additions and 29 deletions
|
@ -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()),
|
||||
|
|
|
@ -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<Commit> {
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue