mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-16 09:11:55 +00:00
merge_tools: take diff editor instruction as Option<&str>
This clarifies that the instructions text can be omitted. All callers appear to pass non-empty instructions, though.
This commit is contained in:
parent
51496de9fb
commit
fbabd0c9a7
9 changed files with 24 additions and 15 deletions
|
@ -1751,7 +1751,7 @@ impl WorkspaceCommandTransaction<'_> {
|
|||
left_tree: &MergedTree,
|
||||
right_tree: &MergedTree,
|
||||
matcher: &dyn Matcher,
|
||||
instructions: &str,
|
||||
instructions: Option<&str>,
|
||||
) -> Result<MergedTreeId, CommandError> {
|
||||
let base_ignores = self.helper.base_ignores()?;
|
||||
let settings = &self.helper.settings;
|
||||
|
@ -1772,7 +1772,7 @@ impl WorkspaceCommandTransaction<'_> {
|
|||
left_tree: &MergedTree,
|
||||
right_tree: &MergedTree,
|
||||
matcher: &dyn Matcher,
|
||||
instructions: &str,
|
||||
instructions: Option<&str>,
|
||||
interactive: bool,
|
||||
) -> Result<MergedTreeId, CommandError> {
|
||||
if interactive {
|
||||
|
|
|
@ -66,7 +66,7 @@ new working-copy commit.
|
|||
&base_tree,
|
||||
&commit.tree()?,
|
||||
matcher.as_ref(),
|
||||
&instructions,
|
||||
Some(&instructions),
|
||||
args.interactive,
|
||||
)?;
|
||||
let middle_tree = tx.repo().store().get_root_tree(&tree_id)?;
|
||||
|
|
|
@ -90,7 +90,13 @@ don't make any changes, then the operation will be aborted.",
|
|||
);
|
||||
let base_tree = merge_commit_trees(tx.repo(), base_commits.as_slice())?;
|
||||
let tree = target_commit.tree()?;
|
||||
let tree_id = tx.edit_diff(ui, &base_tree, &tree, &EverythingMatcher, &instructions)?;
|
||||
let tree_id = tx.edit_diff(
|
||||
ui,
|
||||
&base_tree,
|
||||
&tree,
|
||||
&EverythingMatcher,
|
||||
Some(&instructions),
|
||||
)?;
|
||||
if tree_id == *target_commit.tree_id() {
|
||||
writeln!(ui.stderr(), "Nothing changed.")?;
|
||||
} else {
|
||||
|
|
|
@ -93,7 +93,7 @@ from the source will be moved into the destination.
|
|||
&parent_tree,
|
||||
&source_tree,
|
||||
matcher.as_ref(),
|
||||
&instructions,
|
||||
Some(&instructions),
|
||||
args.interactive,
|
||||
)?;
|
||||
if args.interactive && new_parent_tree_id == parent_tree.id() {
|
||||
|
|
|
@ -81,7 +81,7 @@ don't make any changes, then the operation will be aborted.
|
|||
&base_tree,
|
||||
&end_tree,
|
||||
matcher.as_ref(),
|
||||
&instructions,
|
||||
Some(&instructions),
|
||||
interactive,
|
||||
)?;
|
||||
if &selected_tree_id == commit.tree_id() && interactive {
|
||||
|
|
|
@ -90,7 +90,7 @@ from the source will be moved into the parent.
|
|||
&parent_tree,
|
||||
&tree,
|
||||
matcher.as_ref(),
|
||||
&instructions,
|
||||
Some(&instructions),
|
||||
args.interactive,
|
||||
)?;
|
||||
if &new_parent_tree_id == parent.tree_id() {
|
||||
|
|
|
@ -86,7 +86,7 @@ aborted.
|
|||
&parent_base_tree,
|
||||
&parent_tree,
|
||||
&EverythingMatcher,
|
||||
&instructions,
|
||||
Some(&instructions),
|
||||
)?;
|
||||
if new_parent_tree_id == parent_base_tree.id() {
|
||||
return Err(user_error("No changes selected"));
|
||||
|
|
|
@ -427,7 +427,7 @@ pub fn edit_diff_external(
|
|||
left_tree: &MergedTree,
|
||||
right_tree: &MergedTree,
|
||||
matcher: &dyn Matcher,
|
||||
instructions: &str,
|
||||
instructions: Option<&str>,
|
||||
base_ignores: Arc<GitIgnoreFile>,
|
||||
settings: &UserSettings,
|
||||
) -> Result<MergedTreeId, DiffEditError> {
|
||||
|
@ -452,10 +452,13 @@ pub fn edit_diff_external(
|
|||
let instructions_path_to_cleanup = output_wc_path.join("JJ-INSTRUCTIONS");
|
||||
// In the unlikely event that the file already exists, then the user will simply
|
||||
// not get any instructions.
|
||||
let add_instructions = settings.diff_instructions()
|
||||
&& !instructions.is_empty()
|
||||
&& !instructions_path_to_cleanup.exists();
|
||||
if add_instructions {
|
||||
let add_instructions = if settings.diff_instructions() && !instructions_path_to_cleanup.exists()
|
||||
{
|
||||
instructions
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(instructions) = add_instructions {
|
||||
let mut output_instructions_file =
|
||||
File::create(&instructions_path_to_cleanup).map_err(ExternalToolError::SetUpDir)?;
|
||||
if diff_wc.right_working_copy_path() != output_wc_path {
|
||||
|
@ -513,7 +516,7 @@ diff editing in mind and be a little inaccurate.
|
|||
exit_status,
|
||||
}));
|
||||
}
|
||||
if add_instructions {
|
||||
if add_instructions.is_some() {
|
||||
std::fs::remove_file(instructions_path_to_cleanup).ok();
|
||||
}
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ pub fn edit_diff(
|
|||
left_tree: &MergedTree,
|
||||
right_tree: &MergedTree,
|
||||
matcher: &dyn Matcher,
|
||||
instructions: &str,
|
||||
instructions: Option<&str>,
|
||||
base_ignores: Arc<GitIgnoreFile>,
|
||||
settings: &UserSettings,
|
||||
) -> Result<MergedTreeId, DiffEditError> {
|
||||
|
|
Loading…
Reference in a new issue