merge_tools: pass MergedTree to run_mergetool()

This commit is contained in:
Martin von Zweigbergk 2023-08-26 22:03:53 -07:00 committed by Martin von Zweigbergk
parent 17fe5e39c5
commit 6df7db3dc0
3 changed files with 15 additions and 25 deletions

View file

@ -30,7 +30,7 @@ use clap::{Arg, ArgAction, ArgMatches, Command, FromArgMatches};
use git2::{Oid, Repository};
use indexmap::IndexSet;
use itertools::Itertools;
use jj_lib::backend::{BackendError, ChangeId, CommitId, ObjectId, TreeId};
use jj_lib::backend::{BackendError, ChangeId, CommitId, MergedTreeId, ObjectId, TreeId};
use jj_lib::commit::Commit;
use jj_lib::git::{GitConfigParseError, GitExportError, GitImportError, GitRemoteManagementError};
use jj_lib::git_backend::GitBackend;
@ -1455,9 +1455,9 @@ impl WorkspaceCommandTransaction<'_> {
pub fn run_mergetool(
&self,
ui: &Ui,
tree: &Tree,
tree: &MergedTree,
repo_path: &RepoPath,
) -> Result<TreeId, CommandError> {
) -> Result<MergedTreeId, CommandError> {
let settings = &self.helper.settings;
Ok(crate::merge_tools::run_mergetool(
ui, tree, repo_path, settings,

View file

@ -2745,11 +2745,11 @@ fn cmd_resolve(
"Resolve conflicts in commit {}",
commit.id().hex()
));
let new_tree_id = tx.run_mergetool(ui, &commit.tree(), repo_path)?;
let new_tree_id = tx.run_mergetool(ui, &tree, repo_path)?;
let new_commit = tx
.mut_repo()
.rewrite_commit(command.settings(), &commit)
.set_tree(new_tree_id)
.set_tree_id(new_tree_id)
.write()?;
tx.finish(ui)?;

View file

@ -17,13 +17,12 @@ mod external;
use std::sync::Arc;
use config::ConfigError;
use jj_lib::backend::{MergedTreeId, TreeId, TreeValue};
use jj_lib::backend::MergedTreeId;
use jj_lib::conflicts::extract_as_single_hunk;
use jj_lib::gitignore::GitIgnoreFile;
use jj_lib::merged_tree::MergedTree;
use jj_lib::repo_path::RepoPath;
use jj_lib::settings::{ConfigResultExt as _, UserSettings};
use jj_lib::tree::Tree;
use jj_lib::working_copy::SnapshotError;
use thiserror::Error;
@ -78,16 +77,15 @@ pub enum ConflictResolveError {
pub fn run_mergetool(
ui: &Ui,
tree: &Tree,
tree: &MergedTree,
repo_path: &RepoPath,
settings: &UserSettings,
) -> Result<TreeId, ConflictResolveError> {
let conflict_id = match tree.path_value(repo_path) {
Some(TreeValue::Conflict(id)) => id,
Some(_) => return Err(ConflictResolveError::NotAConflict(repo_path.clone())),
None => return Err(ConflictResolveError::PathNotFound(repo_path.clone())),
) -> Result<MergedTreeId, ConflictResolveError> {
let conflict = match tree.path_value(repo_path).into_resolved() {
Err(conflict) => conflict,
Ok(Some(_)) => return Err(ConflictResolveError::NotAConflict(repo_path.clone())),
Ok(None) => return Err(ConflictResolveError::PathNotFound(repo_path.clone())),
};
let conflict = tree.store().read_conflict(repo_path, &conflict_id)?;
let file_merge = conflict.to_file_merge().ok_or_else(|| {
let mut summary_bytes: Vec<u8> = vec![];
conflict
@ -110,17 +108,9 @@ pub fn run_mergetool(
let editor = get_merge_tool_from_settings(ui, settings)?;
match editor {
MergeTool::Internal => unimplemented!("run_mergetool with internal mergetool"),
MergeTool::External(editor) => {
let new_tree_id = external::run_mergetool_external(
&editor,
file_merge,
content,
repo_path,
conflict,
&MergedTree::Legacy(tree.clone()),
)?;
Ok(new_tree_id.to_legacy_tree_id())
}
MergeTool::External(editor) => external::run_mergetool_external(
&editor, file_merge, content, repo_path, conflict, tree,
),
}
}