From a402892fe5808ba500d1cdd59ca9ce210daeaa62 Mon Sep 17 00:00:00 2001 From: FUTATSUKI Yasuhito Date: Sat, 26 Aug 2023 23:47:26 +0900 Subject: [PATCH 1/3] Implement diff compatible -L (--label) option. With this, we can use difft as a external diff for Apache Subversion, in the form: svn diff --diff-cmd=difft -x '' --- src/options.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/options.rs b/src/options.rs index 2f524f4e63..2557b371d7 100644 --- a/src/options.rs +++ b/src/options.rs @@ -150,6 +150,15 @@ fn app() -> clap::Command { .value_parser(clap::value_parser!(u32)) .required(false), ) + .arg( + Arg::new("label").short('L') + .long("label") + .takes_value(true) + .value_name("LABEL") + .max_occurrences(2) + .allow_invalid_utf8(true) + .help("Label of file(s) which should be used for printing instead of PATH(s).") + ) .arg( Arg::new("width") .long("width") @@ -791,7 +800,25 @@ pub(crate) fn parse_args() -> Mode { [lhs_path, rhs_path] => { let lhs_arg = FileArgument::from_cli_argument(lhs_path); let rhs_arg = FileArgument::from_cli_argument(rhs_path); - let display_path = build_display_path(&lhs_arg, &rhs_arg); + let display_path = if matches.is_present("label") { + let labels: Vec<_> = matches.values_of_os("label").unwrap_or_default().collect(); + let (_lhs_display_path, rhs_display_path) = match &labels[..] { + [lhs_display_path, rhs_display_path] => ( + lhs_display_path.to_string_lossy().to_string(), + rhs_display_path.to_string_lossy().to_string(), + ), + [display_path] => ( + display_path.to_string_lossy().to_string(), + display_path.to_string_lossy().to_string(), + ), + _ => { + unreachable!("clap has already validated label") + } + }; + rhs_display_path + } else { + build_display_path(&lhs_arg, &rhs_arg) + }; let lhs_permissions = lhs_arg.permissions(); let rhs_permissions = rhs_arg.permissions(); From a16aed19564fb4446725e01f6c64a5a2d99fb55d Mon Sep 17 00:00:00 2001 From: FUTATSUKI Yasuhito Date: Sun, 27 Aug 2023 00:02:36 +0900 Subject: [PATCH 2/3] Implement -u option with no effect If "svn diff --diff-cmd" is called without -x option, svn executes external diff command with -u option. So this allows to use difft as external diff for Apache Subversion, without extra options. --- src/options.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/options.rs b/src/options.rs index 2557b371d7..4f30354af7 100644 --- a/src/options.rs +++ b/src/options.rs @@ -150,6 +150,13 @@ fn app() -> clap::Command { .value_parser(clap::value_parser!(u32)) .required(false), ) + .arg( + // Dummy 'unified' flag of POSIX/GNU diff utility for svn support: + // This takes no effect. + Arg::new("nop_unified") + .short('u') + .hide(true) + ) .arg( Arg::new("label").short('L') .long("label") From 50f3c90eefb3637c93c423f0640fece94ec2188d Mon Sep 17 00:00:00 2001 From: FUTATSUKI Yasuhito Date: Tue, 25 Mar 2025 18:06:51 +0900 Subject: [PATCH 3/3] options-for-svn: Migrate to clap4 --- src/options.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/options.rs b/src/options.rs index 4f30354af7..5d5815a38b 100644 --- a/src/options.rs +++ b/src/options.rs @@ -155,15 +155,15 @@ fn app() -> clap::Command { // This takes no effect. Arg::new("nop_unified") .short('u') + .action(ArgAction::SetTrue) .hide(true) ) .arg( Arg::new("label").short('L') .long("label") - .takes_value(true) .value_name("LABEL") - .max_occurrences(2) - .allow_invalid_utf8(true) + .action(ArgAction::Append) + .value_parser(value_parser!(OsString)) .help("Label of file(s) which should be used for printing instead of PATH(s).") ) .arg( @@ -807,8 +807,11 @@ pub(crate) fn parse_args() -> Mode { [lhs_path, rhs_path] => { let lhs_arg = FileArgument::from_cli_argument(lhs_path); let rhs_arg = FileArgument::from_cli_argument(rhs_path); - let display_path = if matches.is_present("label") { - let labels: Vec<_> = matches.values_of_os("label").unwrap_or_default().collect(); + let display_path = if matches.contains_id("label") { + let labels: Vec<_> = matches + .get_many::("label") + .unwrap_or_default() + .collect(); let (_lhs_display_path, rhs_display_path) = match &labels[..] { [lhs_display_path, rhs_display_path] => ( lhs_display_path.to_string_lossy().to_string(), @@ -819,7 +822,8 @@ pub(crate) fn parse_args() -> Mode { display_path.to_string_lossy().to_string(), ), _ => { - unreachable!("clap has already validated label") + eprintln!("More than 2 labels specified"); + std::process::exit(EXIT_BAD_ARGUMENTS); } }; rhs_display_path