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:
Yuya Nishihara 2024-02-29 18:11:11 +09:00
parent 51496de9fb
commit fbabd0c9a7
9 changed files with 24 additions and 15 deletions

View file

@ -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 {

View file

@ -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)?;

View file

@ -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 {

View file

@ -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() {

View file

@ -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 {

View file

@ -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() {

View file

@ -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"));

View file

@ -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();
}

View file

@ -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> {