mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-24 12:48:55 +00:00
merge_tools: pass MergedTree
s to edit_diff()
This commit is contained in:
parent
54b9ecce68
commit
17fe5e39c5
4 changed files with 30 additions and 22 deletions
|
@ -38,6 +38,7 @@ use jj_lib::gitignore::GitIgnoreFile;
|
|||
use jj_lib::hex_util::to_reverse_hex;
|
||||
use jj_lib::id_prefix::IdPrefixContext;
|
||||
use jj_lib::matchers::{EverythingMatcher, Matcher, PrefixMatcher, Visit};
|
||||
use jj_lib::merged_tree::MergedTree;
|
||||
use jj_lib::op_heads_store::{self, OpHeadResolutionError, OpHeadsStore};
|
||||
use jj_lib::op_store::{OpStore, OpStoreError, OperationId, RefTarget, WorkspaceId};
|
||||
use jj_lib::operation::Operation;
|
||||
|
@ -1474,12 +1475,13 @@ impl WorkspaceCommandTransaction<'_> {
|
|||
let settings = &self.helper.settings;
|
||||
Ok(crate::merge_tools::edit_diff(
|
||||
ui,
|
||||
left_tree,
|
||||
right_tree,
|
||||
&MergedTree::Legacy(left_tree.clone()),
|
||||
&MergedTree::Legacy(right_tree.clone()),
|
||||
instructions,
|
||||
base_ignores,
|
||||
settings,
|
||||
)?)
|
||||
)?
|
||||
.to_legacy_tree_id())
|
||||
}
|
||||
|
||||
pub fn select_diff(
|
||||
|
|
|
@ -24,6 +24,7 @@ use jj_lib::commit::Commit;
|
|||
use jj_lib::diff::{Diff, DiffHunk};
|
||||
use jj_lib::files::DiffLine;
|
||||
use jj_lib::matchers::Matcher;
|
||||
use jj_lib::merged_tree::MergedTree;
|
||||
use jj_lib::repo::{ReadonlyRepo, Repo};
|
||||
use jj_lib::repo_path::RepoPath;
|
||||
use jj_lib::settings::{ConfigResultExt as _, UserSettings};
|
||||
|
@ -186,7 +187,14 @@ pub fn show_diff(
|
|||
show_color_words_diff(formatter, workspace_command, tree_diff)?;
|
||||
}
|
||||
DiffFormat::Tool(tool) => {
|
||||
merge_tools::generate_diff(ui, formatter.raw(), from_tree, to_tree, matcher, tool)?;
|
||||
merge_tools::generate_diff(
|
||||
ui,
|
||||
formatter.raw(),
|
||||
&MergedTree::Legacy(from_tree.clone()),
|
||||
&MergedTree::Legacy(to_tree.clone()),
|
||||
matcher,
|
||||
tool,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::sync::Arc;
|
|||
|
||||
use config::ConfigError;
|
||||
use itertools::Itertools;
|
||||
use jj_lib::backend::{FileId, MergedTreeId, TreeId, TreeValue};
|
||||
use jj_lib::backend::{FileId, MergedTreeId, TreeValue};
|
||||
use jj_lib::conflicts::{self, materialize_merge_result};
|
||||
use jj_lib::gitignore::GitIgnoreFile;
|
||||
use jj_lib::matchers::{EverythingMatcher, Matcher};
|
||||
|
@ -16,7 +16,6 @@ use jj_lib::merged_tree::{MergedTree, MergedTreeBuilder};
|
|||
use jj_lib::repo_path::RepoPath;
|
||||
use jj_lib::settings::UserSettings;
|
||||
use jj_lib::store::Store;
|
||||
use jj_lib::tree::Tree;
|
||||
use jj_lib::working_copy::{CheckoutError, SnapshotOptions, TreeState, TreeStateError};
|
||||
use regex::{Captures, Regex};
|
||||
use tempfile::TempDir;
|
||||
|
@ -186,15 +185,14 @@ fn check_out(
|
|||
store: Arc<Store>,
|
||||
wc_dir: PathBuf,
|
||||
state_dir: PathBuf,
|
||||
tree: &Tree,
|
||||
tree: &MergedTree,
|
||||
sparse_patterns: Vec<RepoPath>,
|
||||
) -> Result<TreeState, DiffCheckoutError> {
|
||||
std::fs::create_dir(&wc_dir).map_err(DiffCheckoutError::SetUpDir)?;
|
||||
std::fs::create_dir(&state_dir).map_err(DiffCheckoutError::SetUpDir)?;
|
||||
let mut tree_state = TreeState::init(store, wc_dir, state_dir)?;
|
||||
tree_state.set_sparse_patterns(sparse_patterns)?;
|
||||
let tree = MergedTree::legacy(tree.clone());
|
||||
tree_state.check_out(&tree)?;
|
||||
tree_state.check_out(tree)?;
|
||||
Ok(tree_state)
|
||||
}
|
||||
|
||||
|
@ -233,14 +231,14 @@ enum DiffSide {
|
|||
/// in the sparse checkout patterns.
|
||||
fn check_out_trees(
|
||||
store: &Arc<Store>,
|
||||
left_tree: &Tree,
|
||||
right_tree: &Tree,
|
||||
left_tree: &MergedTree,
|
||||
right_tree: &MergedTree,
|
||||
output_is: Option<DiffSide>,
|
||||
matcher: &dyn Matcher,
|
||||
) -> Result<DiffWorkingCopies, DiffCheckoutError> {
|
||||
let changed_files = left_tree
|
||||
.diff(right_tree, matcher)
|
||||
.map(|(path, _value)| path)
|
||||
.map(|(path, _left, _right)| path)
|
||||
.collect_vec();
|
||||
|
||||
let temp_dir = new_utf8_temp_dir("jj-diff-").map_err(DiffCheckoutError::SetUpDir)?;
|
||||
|
@ -420,12 +418,12 @@ fn find_all_variables(args: &[String]) -> impl Iterator<Item = &str> {
|
|||
|
||||
pub fn edit_diff_external(
|
||||
editor: ExternalMergeTool,
|
||||
left_tree: &Tree,
|
||||
right_tree: &Tree,
|
||||
left_tree: &MergedTree,
|
||||
right_tree: &MergedTree,
|
||||
instructions: &str,
|
||||
base_ignores: Arc<GitIgnoreFile>,
|
||||
settings: &UserSettings,
|
||||
) -> Result<TreeId, DiffEditError> {
|
||||
) -> Result<MergedTreeId, DiffEditError> {
|
||||
let got_output_field = find_all_variables(&editor.edit_args).contains(&"output");
|
||||
let store = left_tree.store();
|
||||
let diff_wc = check_out_trees(
|
||||
|
@ -521,15 +519,15 @@ diff editing in mind and be a little inaccurate.
|
|||
progress: None,
|
||||
max_new_file_size: settings.max_new_file_size()?,
|
||||
})?;
|
||||
Ok(output_tree_state.current_tree_id().to_legacy_tree_id())
|
||||
Ok(output_tree_state.current_tree_id().clone())
|
||||
}
|
||||
|
||||
/// Generates textual diff by the specified `tool`, and writes into `writer`.
|
||||
pub fn generate_diff(
|
||||
ui: &Ui,
|
||||
writer: &mut dyn Write,
|
||||
left_tree: &Tree,
|
||||
right_tree: &Tree,
|
||||
left_tree: &MergedTree,
|
||||
right_tree: &MergedTree,
|
||||
matcher: &dyn Matcher,
|
||||
tool: &ExternalMergeTool,
|
||||
) -> Result<(), DiffGenerateError> {
|
||||
|
|
|
@ -17,7 +17,7 @@ mod external;
|
|||
use std::sync::Arc;
|
||||
|
||||
use config::ConfigError;
|
||||
use jj_lib::backend::{TreeId, TreeValue};
|
||||
use jj_lib::backend::{MergedTreeId, TreeId, TreeValue};
|
||||
use jj_lib::conflicts::extract_as_single_hunk;
|
||||
use jj_lib::gitignore::GitIgnoreFile;
|
||||
use jj_lib::merged_tree::MergedTree;
|
||||
|
@ -126,12 +126,12 @@ pub fn run_mergetool(
|
|||
|
||||
pub fn edit_diff(
|
||||
ui: &Ui,
|
||||
left_tree: &Tree,
|
||||
right_tree: &Tree,
|
||||
left_tree: &MergedTree,
|
||||
right_tree: &MergedTree,
|
||||
instructions: &str,
|
||||
base_ignores: Arc<GitIgnoreFile>,
|
||||
settings: &UserSettings,
|
||||
) -> Result<TreeId, DiffEditError> {
|
||||
) -> Result<MergedTreeId, DiffEditError> {
|
||||
// Start a diff editor on the two directories.
|
||||
let editor = get_diff_editor_from_settings(ui, settings)?;
|
||||
match editor {
|
||||
|
|
Loading…
Reference in a new issue