From 6df7db3dc0f00fdc16180707ff67501de3586a87 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 26 Aug 2023 22:03:53 -0700 Subject: [PATCH] merge_tools: pass `MergedTree` to `run_mergetool()` --- cli/src/cli_util.rs | 6 +++--- cli/src/commands/mod.rs | 4 ++-- cli/src/merge_tools/mod.rs | 30 ++++++++++-------------------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/cli/src/cli_util.rs b/cli/src/cli_util.rs index 23f3abac3..aa13a9915 100644 --- a/cli/src/cli_util.rs +++ b/cli/src/cli_util.rs @@ -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 { + ) -> Result { let settings = &self.helper.settings; Ok(crate::merge_tools::run_mergetool( ui, tree, repo_path, settings, diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 067708aa9..55b797341 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -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)?; diff --git a/cli/src/merge_tools/mod.rs b/cli/src/merge_tools/mod.rs index 1c2174443..0441269c8 100644 --- a/cli/src/merge_tools/mod.rs +++ b/cli/src/merge_tools/mod.rs @@ -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 { - 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 { + 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 = 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, + ), } }