forked from mirrors/jj
cli: implement Default for MergeTool, do not override it with empty args
The default edit_args will be changed to ["$left", "$right"] to support variable substitution without breaking the existing configuration too much. The default merge_args could also be set if we could come up with something meaningful.
This commit is contained in:
parent
2d17385d2e
commit
d5f05b7897
1 changed files with 25 additions and 13 deletions
|
@ -378,21 +378,18 @@ pub fn edit_diff(
|
||||||
|
|
||||||
/// Merge/diff tool loaded from the settings.
|
/// Merge/diff tool loaded from the settings.
|
||||||
#[derive(Clone, Debug, serde::Deserialize)]
|
#[derive(Clone, Debug, serde::Deserialize)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(default, rename_all = "kebab-case")]
|
||||||
struct MergeTool {
|
struct MergeTool {
|
||||||
/// Program to execute. Must be defined; defaults to the tool name
|
/// Program to execute. Must be defined; defaults to the tool name
|
||||||
/// if not specified in the config.
|
/// if not specified in the config.
|
||||||
#[serde(default)]
|
|
||||||
pub program: String,
|
pub program: String,
|
||||||
/// Arguments to pass to the program when editing diffs.
|
/// Arguments to pass to the program when editing diffs.
|
||||||
#[serde(default)]
|
|
||||||
pub edit_args: Vec<String>,
|
pub edit_args: Vec<String>,
|
||||||
/// Arguments to pass to the program when resolving 3-way conflicts.
|
/// Arguments to pass to the program when resolving 3-way conflicts.
|
||||||
/// `$left`, `$right`, `$base`, and `$output` are replaced with
|
/// `$left`, `$right`, `$base`, and `$output` are replaced with
|
||||||
/// paths to the corresponding files.
|
/// paths to the corresponding files.
|
||||||
/// TODO: Currently, the entire argument has to match one of these 4
|
/// TODO: Currently, the entire argument has to match one of these 4
|
||||||
/// strings to be substituted.
|
/// strings to be substituted.
|
||||||
#[serde(default)]
|
|
||||||
pub merge_args: Vec<String>,
|
pub merge_args: Vec<String>,
|
||||||
/// If false (default), the `$output` file starts out empty and is accepted
|
/// If false (default), the `$output` file starts out empty and is accepted
|
||||||
/// as a full conflict resolution as-is by `jj` after the merge tool is
|
/// as a full conflict resolution as-is by `jj` after the merge tool is
|
||||||
|
@ -403,29 +400,44 @@ struct MergeTool {
|
||||||
/// resolved.
|
/// resolved.
|
||||||
// TODO: Instead of a boolean, this could denote the flavor of conflict markers to put in
|
// TODO: Instead of a boolean, this could denote the flavor of conflict markers to put in
|
||||||
// the file (`jj` or `diff3` for example).
|
// the file (`jj` or `diff3` for example).
|
||||||
#[serde(default)]
|
|
||||||
pub merge_tool_edits_conflict_markers: bool,
|
pub merge_tool_edits_conflict_markers: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::derivable_impls)] // TODO
|
||||||
|
impl Default for MergeTool {
|
||||||
|
fn default() -> Self {
|
||||||
|
MergeTool {
|
||||||
|
program: String::new(),
|
||||||
|
edit_args: vec![],
|
||||||
|
merge_args: vec![],
|
||||||
|
merge_tool_edits_conflict_markers: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MergeTool {
|
impl MergeTool {
|
||||||
pub fn with_edit_args(command_args: &CommandNameAndArgs) -> Self {
|
pub fn with_edit_args(command_args: &CommandNameAndArgs) -> Self {
|
||||||
let (name, args) = command_args.split_name_and_args();
|
let (name, args) = command_args.split_name_and_args();
|
||||||
MergeTool {
|
let mut tool = MergeTool {
|
||||||
program: name.into_owned(),
|
program: name.into_owned(),
|
||||||
edit_args: args.to_vec(),
|
..Default::default()
|
||||||
merge_args: vec![],
|
};
|
||||||
merge_tool_edits_conflict_markers: false,
|
if !args.is_empty() {
|
||||||
|
tool.edit_args = args.to_vec();
|
||||||
}
|
}
|
||||||
|
tool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_merge_args(command_args: &CommandNameAndArgs) -> Self {
|
pub fn with_merge_args(command_args: &CommandNameAndArgs) -> Self {
|
||||||
let (name, args) = command_args.split_name_and_args();
|
let (name, args) = command_args.split_name_and_args();
|
||||||
MergeTool {
|
let mut tool = MergeTool {
|
||||||
program: name.into_owned(),
|
program: name.into_owned(),
|
||||||
edit_args: vec![],
|
..Default::default()
|
||||||
merge_args: args.to_vec(),
|
};
|
||||||
merge_tool_edits_conflict_markers: false,
|
if !args.is_empty() {
|
||||||
|
tool.merge_args = args.to_vec();
|
||||||
}
|
}
|
||||||
|
tool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue