mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-28 09:14:04 +00:00
commands: move rebase_to_dest_parent to jj_lib::rewrite
What make rebase_to_dest_parent a good candidate for jj_lib::rewrite module: - It is used both in obslog and interdiff. It's a sign that it may be moved to a lower layer - CommandError is returned by converting from TreeMergeError. Not explicitly. - It only use jj_lib::rewrite fonctions.
This commit is contained in:
parent
4f84c6b5d5
commit
5973ab47b9
4 changed files with 21 additions and 24 deletions
|
@ -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)?;
|
||||
|
|
|
@ -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<MergedTree, CommandError> {
|
||||
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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -127,6 +127,22 @@ pub fn rebase_commit(
|
|||
.write()?)
|
||||
}
|
||||
|
||||
pub fn rebase_to_dest_parent(
|
||||
repo: &dyn Repo,
|
||||
source: &Commit,
|
||||
destination: &Commit,
|
||||
) -> Result<MergedTree, TreeMergeError> {
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue