cli: merge trees via MergedTree in jj move

This commit is contained in:
Martin von Zweigbergk 2023-08-27 07:03:38 -07:00 committed by Martin von Zweigbergk
parent 873a6f0674
commit bd6098e09e
2 changed files with 17 additions and 28 deletions

View File

@ -2407,8 +2407,8 @@ fn cmd_move(ui: &mut Ui, command: &CommandHelper, args: &MoveArgs) -> Result<(),
source.id().hex(), source.id().hex(),
destination.id().hex() destination.id().hex()
)); ));
let parent_tree = merge_commit_trees(tx.repo(), &source.parents())?; let parent_tree = MergedTree::legacy(merge_commit_trees(tx.repo(), &source.parents())?);
let source_tree = source.tree(); let source_tree = source.merged_tree()?;
let instructions = format!( let instructions = format!(
"\ "\
You are moving changes from: {} You are moving changes from: {}
@ -2425,32 +2425,27 @@ from the source will be moved into the destination.
tx.format_commit_summary(&source), tx.format_commit_summary(&source),
tx.format_commit_summary(&destination) tx.format_commit_summary(&destination)
); );
let new_parent_tree_id = tx let new_parent_tree_id = tx.select_diff(
.select_diff( ui,
ui, &parent_tree,
&MergedTree::Legacy(parent_tree.clone()), &source_tree,
&MergedTree::Legacy(source_tree.clone()), &instructions,
&instructions, args.interactive,
args.interactive, matcher.as_ref(),
matcher.as_ref(), )?;
)? if args.interactive && new_parent_tree_id == parent_tree.id() {
.to_legacy_tree_id();
if args.interactive && &new_parent_tree_id == parent_tree.id() {
return Err(user_error("No changes to move")); return Err(user_error("No changes to move"));
} }
let new_parent_tree = tx let new_parent_tree = tx.repo().store().get_root_tree(&new_parent_tree_id)?;
.repo()
.store()
.get_tree(&RepoPath::root(), &new_parent_tree_id)?;
// Apply the reverse of the selected changes onto the source // Apply the reverse of the selected changes onto the source
let new_source_tree = merge_trees(&source_tree, &new_parent_tree, &parent_tree)?; let new_source_tree = source_tree.merge(&new_parent_tree, &parent_tree)?;
let abandon_source = new_source_tree.id() == parent_tree.id(); let abandon_source = new_source_tree.id() == parent_tree.id();
if abandon_source { if abandon_source {
tx.mut_repo().record_abandoned_commit(source.id().clone()); tx.mut_repo().record_abandoned_commit(source.id().clone());
} else { } else {
tx.mut_repo() tx.mut_repo()
.rewrite_commit(command.settings(), &source) .rewrite_commit(command.settings(), &source)
.set_tree(new_source_tree.id().clone()) .set_tree_id(new_source_tree.id().clone())
.write()?; .write()?;
} }
if tx.repo().index().is_ancestor(source.id(), destination.id()) { if tx.repo().index().is_ancestor(source.id(), destination.id()) {
@ -2464,7 +2459,8 @@ from the source will be moved into the destination.
destination = tx.mut_repo().store().get_commit(&rebased_destination_id)?; destination = tx.mut_repo().store().get_commit(&rebased_destination_id)?;
} }
// Apply the selected changes onto the destination // Apply the selected changes onto the destination
let new_destination_tree = merge_trees(&destination.tree(), &parent_tree, &new_parent_tree)?; let destination_tree = destination.merged_tree()?;
let new_destination_tree = destination_tree.merge(&parent_tree, &new_parent_tree)?;
let description = combine_messages( let description = combine_messages(
tx.base_repo(), tx.base_repo(),
&source, &source,
@ -2474,7 +2470,7 @@ from the source will be moved into the destination.
)?; )?;
tx.mut_repo() tx.mut_repo()
.rewrite_commit(command.settings(), &destination) .rewrite_commit(command.settings(), &destination)
.set_tree(new_destination_tree.id().clone()) .set_tree_id(new_destination_tree.id().clone())
.set_description(description) .set_description(description)
.write()?; .write()?;
tx.finish(ui)?; tx.finish(ui)?;

View File

@ -186,13 +186,6 @@ impl MergedTreeId {
MergedTreeId::Merge(_) => panic!(), MergedTreeId::Merge(_) => panic!(),
} }
} }
/// If this is a legacy tree, gets its tree id
// TODO(#1624): delete when all callers have been updated to support tree-level
// conflicts
pub fn to_legacy_tree_id(&self) -> TreeId {
self.as_legacy_tree_id().clone()
}
} }
content_hash! { content_hash! {