ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: pass &DiffFormatArgs in to default_diff_format()

Suppose we add -w/--ignore-all-space flag for example, it's probably better to
pass optional parameters by struct, not by separate arguments.
This commit is contained in:
Yuya Nishihara 2024-08-17 13:54:51 +09:00
parent f76db7fa4b
commit 5ff4e2d0a2

View file

@ -111,7 +111,7 @@ pub fn diff_formats_for(
) -> Result<Vec<DiffFormat>, config::ConfigError> { ) -> Result<Vec<DiffFormat>, config::ConfigError> {
let formats = diff_formats_from_args(settings, args)?; let formats = diff_formats_from_args(settings, args)?;
if formats.is_empty() { if formats.is_empty() {
Ok(vec![default_diff_format(settings, args.context)?]) Ok(vec![default_diff_format(settings, args)?])
} else { } else {
Ok(formats) Ok(formats)
} }
@ -127,7 +127,7 @@ pub fn diff_formats_for_log(
let mut formats = diff_formats_from_args(settings, args)?; let mut formats = diff_formats_from_args(settings, args)?;
// --patch implies default if no format other than --summary is specified // --patch implies default if no format other than --summary is specified
if patch && matches!(formats.as_slice(), [] | [DiffFormat::Summary]) { if patch && matches!(formats.as_slice(), [] | [DiffFormat::Summary]) {
formats.push(default_diff_format(settings, args.context)?); formats.push(default_diff_format(settings, args)?);
formats.dedup(); formats.dedup();
} }
Ok(formats) Ok(formats)
@ -168,7 +168,7 @@ fn diff_formats_from_args(
fn default_diff_format( fn default_diff_format(
settings: &UserSettings, settings: &UserSettings,
num_context_lines: Option<usize>, args: &DiffFormatArgs,
) -> Result<DiffFormat, config::ConfigError> { ) -> Result<DiffFormat, config::ConfigError> {
let config = settings.config(); let config = settings.config();
if let Some(args) = config.get("ui.diff.tool").optional()? { if let Some(args) = config.get("ui.diff.tool").optional()? {
@ -193,10 +193,10 @@ fn default_diff_format(
"types" => Ok(DiffFormat::Types), "types" => Ok(DiffFormat::Types),
"name-only" => Ok(DiffFormat::NameOnly), "name-only" => Ok(DiffFormat::NameOnly),
"git" => Ok(DiffFormat::Git { "git" => Ok(DiffFormat::Git {
context: num_context_lines.unwrap_or(DEFAULT_CONTEXT_LINES), context: args.context.unwrap_or(DEFAULT_CONTEXT_LINES),
}), }),
"color-words" => Ok(DiffFormat::ColorWords { "color-words" => Ok(DiffFormat::ColorWords {
context: num_context_lines.unwrap_or(DEFAULT_CONTEXT_LINES), context: args.context.unwrap_or(DEFAULT_CONTEXT_LINES),
}), }),
"stat" => Ok(DiffFormat::Stat), "stat" => Ok(DiffFormat::Stat),
_ => Err(config::ConfigError::Message(format!( _ => Err(config::ConfigError::Message(format!(