diff --git a/cli/src/commands/interdiff.rs b/cli/src/commands/interdiff.rs index bb3e44a36..74f0403dd 100644 --- a/cli/src/commands/interdiff.rs +++ b/cli/src/commands/interdiff.rs @@ -13,9 +13,9 @@ // limitations under the License. use clap::ArgGroup; +use jj_lib::rewrite::rebase_to_dest_parent; use tracing::instrument; -use super::rebase_to_dest_parent; use crate::cli_util::{CommandError, CommandHelper, RevisionArg}; use crate::diff_util::{self, DiffFormatArgs}; use crate::ui::Ui; @@ -51,7 +51,7 @@ pub(crate) fn cmd_interdiff( let from = workspace_command.resolve_single_rev(args.from.as_deref().unwrap_or("@"), ui)?; let to = workspace_command.resolve_single_rev(args.to.as_deref().unwrap_or("@"), ui)?; - let from_tree = rebase_to_dest_parent(&workspace_command, &from, &to)?; + let from_tree = rebase_to_dest_parent(workspace_command.repo().as_ref(), &from, &to)?; let to_tree = to.tree()?; let matcher = workspace_command.matcher_from_values(&args.paths)?; let diff_formats = diff_util::diff_formats_for(command.settings(), &args.format)?; diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 9880ca78c..899e46cd3 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -63,9 +63,7 @@ use clap::{Command, CommandFactory, FromArgMatches, Subcommand}; use itertools::Itertools; use jj_lib::commit::Commit; use jj_lib::matchers::EverythingMatcher; -use jj_lib::merged_tree::MergedTree; use jj_lib::repo::ReadonlyRepo; -use jj_lib::rewrite::merge_commit_trees; use jj_lib::settings::UserSettings; use tracing::instrument; @@ -147,24 +145,6 @@ enum Commands { Workspace(workspace::WorkspaceCommands), } -fn rebase_to_dest_parent( - workspace_command: &WorkspaceCommandHelper, - source: &Commit, - destination: &Commit, -) -> Result { - if source.parent_ids() == destination.parent_ids() { - Ok(source.tree()?) - } else { - let destination_parent_tree = - merge_commit_trees(workspace_command.repo().as_ref(), &destination.parents())?; - let source_parent_tree = - merge_commit_trees(workspace_command.repo().as_ref(), &source.parents())?; - let source_tree = source.tree()?; - let rebased_tree = destination_parent_tree.merge(&source_parent_tree, &source_tree)?; - Ok(rebased_tree) - } -} - fn edit_description( repo: &ReadonlyRepo, description: &str, diff --git a/cli/src/commands/obslog.rs b/cli/src/commands/obslog.rs index b294c77fd..29e52f99e 100644 --- a/cli/src/commands/obslog.rs +++ b/cli/src/commands/obslog.rs @@ -15,9 +15,9 @@ use jj_lib::commit::Commit; use jj_lib::dag_walk::topo_order_reverse; use jj_lib::matchers::EverythingMatcher; +use jj_lib::rewrite::rebase_to_dest_parent; use tracing::instrument; -use super::rebase_to_dest_parent; use crate::cli_util::{ CommandError, CommandHelper, LogContentFormat, RevisionArg, WorkspaceCommandHelper, }; @@ -153,7 +153,8 @@ fn show_predecessor_patch( Some(predecessor) => predecessor, None => return Ok(()), }; - let predecessor_tree = rebase_to_dest_parent(workspace_command, predecessor, commit)?; + let predecessor_tree = + rebase_to_dest_parent(workspace_command.repo().as_ref(), predecessor, commit)?; let tree = commit.tree()?; diff_util::show_diff( ui, diff --git a/lib/src/rewrite.rs b/lib/src/rewrite.rs index 8373a5071..36bad4c74 100644 --- a/lib/src/rewrite.rs +++ b/lib/src/rewrite.rs @@ -127,6 +127,22 @@ pub fn rebase_commit( .write()?) } +pub fn rebase_to_dest_parent( + repo: &dyn Repo, + source: &Commit, + destination: &Commit, +) -> Result { + if source.parent_ids() == destination.parent_ids() { + Ok(source.tree()?) + } else { + let destination_parent_tree = merge_commit_trees(repo, &destination.parents())?; + let source_parent_tree = merge_commit_trees(repo, &source.parents())?; + let source_tree = source.tree()?; + let rebased_tree = destination_parent_tree.merge(&source_parent_tree, &source_tree)?; + Ok(rebased_tree) + } +} + pub fn back_out_commit( settings: &UserSettings, mut_repo: &mut MutableRepo,