diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 7f0111452..33009c6cd 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -1725,16 +1725,6 @@ impl WorkspaceCommandTransaction<'_> { self.tx.mut_repo().edit(workspace_id, commit) } - // TODO: inline this - pub fn run_mergetool( - &self, - editor: &MergeEditor, - tree: &MergedTree, - repo_path: &RepoPath, - ) -> Result { - Ok(merge_tools::run_mergetool(editor, tree, repo_path)?) - } - // TODO: maybe capture parameters by diff_editor(), and inline this? pub fn edit_diff( &self, diff --git a/cli/src/commands/resolve.rs b/cli/src/commands/resolve.rs index 9422faed1..0e5370cc7 100644 --- a/cli/src/commands/resolve.rs +++ b/cli/src/commands/resolve.rs @@ -103,7 +103,7 @@ pub(crate) fn cmd_resolve( workspace_command.format_file_path(repo_path) )?; let mut tx = workspace_command.start_transaction(); - let new_tree_id = tx.run_mergetool(&merge_editor, &tree, repo_path)?; + let new_tree_id = merge_editor.edit_file(&tree, repo_path)?; let new_commit = tx .mut_repo() .rewrite_commit(command.settings(), &commit) diff --git a/cli/src/merge_tools/mod.rs b/cli/src/merge_tools/mod.rs index 886fd817e..dda43b252 100644 --- a/cli/src/merge_tools/mod.rs +++ b/cli/src/merge_tools/mod.rs @@ -85,46 +85,6 @@ pub enum ConflictResolveError { Backend(#[from] jj_lib::backend::BackendError), } -pub fn run_mergetool( - editor: &MergeEditor, - tree: &MergedTree, - repo_path: &RepoPath, -) -> Result { - let conflict = match tree.path_value(repo_path).into_resolved() { - Err(conflict) => conflict, - Ok(Some(_)) => return Err(ConflictResolveError::NotAConflict(repo_path.to_owned())), - Ok(None) => return Err(ConflictResolveError::PathNotFound(repo_path.to_owned())), - }; - let file_merge = conflict.to_file_merge().ok_or_else(|| { - let mut summary_bytes: Vec = vec![]; - conflict - .describe(&mut summary_bytes) - .expect("Writing to an in-memory buffer should never fail"); - ConflictResolveError::NotNormalFiles( - repo_path.to_owned(), - String::from_utf8_lossy(summary_bytes.as_slice()).to_string(), - ) - })?; - // We only support conflicts with 2 sides (3-way conflicts) - if file_merge.num_sides() > 2 { - return Err(ConflictResolveError::ConflictTooComplicated { - path: repo_path.to_owned(), - sides: file_merge.num_sides(), - }); - }; - let content = extract_as_single_hunk(&file_merge, tree.store(), repo_path).block_on(); - - match &editor.tool { - MergeTool::Builtin => { - let tree_id = edit_merge_builtin(tree, repo_path, content).map_err(Box::new)?; - Ok(tree_id) - } - MergeTool::External(editor) => { - external::run_mergetool_external(editor, file_merge, content, repo_path, conflict, tree) - } - } -} - pub fn edit_diff( editor: &DiffEditor, left_tree: &MergedTree, @@ -265,6 +225,47 @@ impl MergeEditor { } Ok(MergeEditor { tool }) } + + /// Starts a merge editor for the specified file. + pub fn edit_file( + &self, + tree: &MergedTree, + repo_path: &RepoPath, + ) -> Result { + let conflict = match tree.path_value(repo_path).into_resolved() { + Err(conflict) => conflict, + Ok(Some(_)) => return Err(ConflictResolveError::NotAConflict(repo_path.to_owned())), + Ok(None) => return Err(ConflictResolveError::PathNotFound(repo_path.to_owned())), + }; + let file_merge = conflict.to_file_merge().ok_or_else(|| { + let mut summary_bytes: Vec = vec![]; + conflict + .describe(&mut summary_bytes) + .expect("Writing to an in-memory buffer should never fail"); + ConflictResolveError::NotNormalFiles( + repo_path.to_owned(), + String::from_utf8_lossy(summary_bytes.as_slice()).to_string(), + ) + })?; + // We only support conflicts with 2 sides (3-way conflicts) + if file_merge.num_sides() > 2 { + return Err(ConflictResolveError::ConflictTooComplicated { + path: repo_path.to_owned(), + sides: file_merge.num_sides(), + }); + }; + let content = extract_as_single_hunk(&file_merge, tree.store(), repo_path).block_on(); + + match &self.tool { + MergeTool::Builtin => { + let tree_id = edit_merge_builtin(tree, repo_path, content).map_err(Box::new)?; + Ok(tree_id) + } + MergeTool::External(editor) => external::run_mergetool_external( + editor, file_merge, content, repo_path, conflict, tree, + ), + } + } } #[cfg(test)]