summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2022-01-16 11:24:42 -0500
committerGitHub <noreply@github.com>2022-01-16 11:24:42 -0500
commit9106a51ac385f26d5eccdfd68af933508668ae28 (patch)
treeb95cfe784050319736224755bdc08f066fb79f3f
parentf498544dfd0ffe7d1a3edbfef65a5067ad50091d (diff)
Drop deprecated options (#914)
Drop deprecated options Fixes #891
-rw-r--r--src/cli.rs61
-rw-r--r--src/options/mod.rs1
-rw-r--r--src/options/rewrite.rs181
-rw-r--r--src/parse_style.rs104
-rw-r--r--src/parse_styles.rs56
-rw-r--r--src/tests/test_example_diffs.rs40
-rwxr-xr-xtests/test_deprecated_options18
7 files changed, 20 insertions, 441 deletions
diff --git a/src/cli.rs b/src/cli.rs
index cbc828b1..dece275b 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -891,51 +891,6 @@ pub struct Opt {
/// affect delta's performance when entire files are added/removed.
pub line_buffer_size: usize,
- #[clap(long = "minus-color")]
- /// Deprecated: use --minus-style='normal my_background_color'.
- pub deprecated_minus_background_color: Option<String>,
-
- #[clap(long = "minus-emph-color")]
- /// Deprecated: use --minus-emph-style='normal my_background_color'.
- pub deprecated_minus_emph_background_color: Option<String>,
-
- #[clap(long = "plus-color")]
- /// Deprecated: Use --plus-style='syntax my_background_color' to change the background color
- /// while retaining syntax-highlighting.
- pub deprecated_plus_background_color: Option<String>,
-
- #[clap(long = "plus-emph-color")]
- /// Deprecated: Use --plus-emph-style='syntax my_background_color' to change the background
- /// color while retaining syntax-highlighting.
- pub deprecated_plus_emph_background_color: Option<String>,
-
- #[clap(long = "highlight-removed")]
- /// Deprecated: use --minus-style='syntax'.
- pub deprecated_highlight_minus_lines: bool,
-
- #[clap(long = "commit-color")]
- /// Deprecated: use --commit-style='my_foreground_color'
- /// --commit-decoration-style='my_foreground_color'.
- pub deprecated_commit_color: Option<String>,
-
- #[clap(long = "file-color")]
- /// Deprecated: use --file-style='my_foreground_color'
- /// --file-decoration-style='my_foreground_color'.
- pub deprecated_file_color: Option<String>,
-
- #[clap(long = "hunk-style")]
- /// Deprecated: synonym of --hunk-header-decoration-style.
- pub deprecated_hunk_style: Option<String>,
-
- #[clap(long = "hunk-color")]
- /// Deprecated: use --hunk-header-style='my_foreground_color'
- /// --hunk-header-decoration-style='my_foreground_color'.
- pub deprecated_hunk_color: Option<String>,
-
- #[clap(long = "theme")]
- /// Deprecated: use --syntax-theme.
- pub deprecated_theme: Option<String>,
-
#[clap(skip)]
pub computed: ComputedValues,
@@ -1014,7 +969,6 @@ impl Opt {
) -> Self {
let mut opt = Opt::from_arg_matches(&arg_matches)
.unwrap_or_else(|_| delta_unreachable("Opt::from_arg_matches failed"));
- options::rewrite::apply_rewrite_rules(&mut opt, &arg_matches);
options::set::set_options(&mut opt, &mut git_config, &arg_matches, assets);
opt.git_config = git_config;
opt
@@ -1039,21 +993,10 @@ impl Opt {
}
}
-// Option names to exclude when listing options to process for various purposes. These are
-// (1) Deprecated options
-// (2) Pseudo-flag commands such as --list-languages
+// Option names to exclude when listing options to process for various purposes. These are all
+// pseudo-flag commands such as --list-languages
lazy_static! {
static ref IGNORED_OPTION_NAMES: HashSet<&'static str> = vec![
- "deprecated-file-color",
- "deprecated-hunk-style",
- "deprecated-minus-background-color",
- "deprecated-minus-emph-background-color",
- "deprecated-hunk-color",
- "deprecated-plus-emph-background-color",
- "deprecated-plus-background-color",
- "deprecated-highlight-minus-lines",
- "deprecated-theme",
- "deprecated-commit-color",
"list-languages",
"list-syntax-themes",
"show-config",
diff --git a/src/options/mod.rs b/src/options/mod.rs
index f15e5806..1ff1e72e 100644
--- a/src/options/mod.rs
+++ b/src/options/mod.rs
@@ -1,5 +1,4 @@
pub mod get;
pub mod option_value;
-pub mod rewrite;
pub mod set;
pub mod theme;
diff --git a/src/options/rewrite.rs b/src/options/rewrite.rs
deleted file mode 100644
index 6f90af2c..00000000
--- a/src/options/rewrite.rs
+++ /dev/null
@@ -1,181 +0,0 @@
-/// This module applies rewrite rules to the command line options, in order to
-/// 1. Express deprecated usages in the new non-deprecated form
-/// 2. Implement options such as --raw which are defined to be equivalent to some set of
-/// other options.
-use crate::cli;
-use crate::config::user_supplied_option;
-use crate::fatal;
-
-pub fn apply_rewrite_rules(opt: &mut cli::Opt, arg_matches: &clap::ArgMatches) {
- rewrite_style_strings_to_honor_deprecated_minus_plus_options(opt);
- rewrite_options_to_implement_deprecated_commit_and_file_style_box_option(opt);
- rewrite_options_to_implement_deprecated_hunk_style_option(opt);
- rewrite_options_to_implement_deprecated_theme_option(opt, arg_matches);
-}
-
-/// Honor deprecated --theme
-fn rewrite_options_to_implement_deprecated_theme_option(
- opt: &mut cli::Opt,
- arg_matches: &clap::ArgMatches,
-) {
- if user_supplied_option("deprecated-theme", arg_matches) {
- if let Some(syntax_theme) = opt.deprecated_theme.as_ref() {
- opt.syntax_theme = Some(syntax_theme.to_string());
- }
- }
-}
-
-/// Honor deprecated arguments by rewriting the canonical --*-style arguments if appropriate.
-// TODO: How to avoid repeating the default values for style options here and in
-// the structopt definition?
-fn rewrite_style_strings_to_honor_deprecated_minus_plus_options(opt: &mut cli::Opt) {
- // If --highlight-removed was passed then we should set minus and minus emph foreground to
- // "syntax", if they are still at their default values.
- let deprecated_minus_foreground_arg = if opt.deprecated_highlight_minus_lines {
- Some("syntax")
- } else {
- None
- };
-
- if let Some(rewritten) = _get_rewritten_minus_plus_style_string(
- &opt.minus_style,
- ("normal", "auto"),
- (
- deprecated_minus_foreground_arg,
- opt.deprecated_minus_background_color.as_deref(),
- ),
- "minus",
- ) {
- opt.minus_style = rewritten;
- }
- if let Some(rewritten) = _get_rewritten_minus_plus_style_string(
- &opt.minus_emph_style,
- ("normal", "auto"),
- (
- deprecated_minus_foreground_arg,
- opt.deprecated_minus_emph_background_color.as_deref(),
- ),
- "minus-emph",
- ) {
- opt.minus_emph_style = rewritten;
- }
- if let Some(rewritten) = _get_rewritten_minus_plus_style_string(
- &opt.plus_style,
- ("syntax", "auto"),
- (None, opt.deprecated_plus_background_color.as_deref()),
- "plus",
- ) {
- opt.plus_style = rewritten;
- }
- if let Some(rewritten) = _get_rewritten_minus_plus_style_string(
- &opt.plus_emph_style,
- ("syntax", "auto"),
- (None, opt.deprecated_plus_emph_background_color.as_deref()),
- "plus-emph",
- ) {
- opt.plus_emph_style = rewritten;
- }
-}
-
-/// For backwards-compatibility, --{commit,file}-style box means --element-decoration-style 'box ul'.
-fn rewrite_options_to_implement_deprecated_commit_and_file_style_box_option(opt: &mut cli::Opt) {
- if &opt.commit_style == "box" {
- opt.commit_decoration_style = format!("box ul {}", opt.commit_decoration_style);
- opt.commit_style.clear();
- }
- if &opt.file_style == "box" {
- opt.file_decoration_style = format!("box ul {}", opt.file_decoration_style);
- opt.file_style.clear();
- }
-}
-
-fn rewrite_options_to_implement_deprecated_hunk_style_option(opt: &mut cli::Opt) {
- // Examples of how --hunk-style was originally used are
- // --hunk-style box => --hunk-header-decoration-style box
- // --hunk-style underline => --hunk-header-decoration-style underline
- // --hunk-style plain => --hunk-header-decoration-style ''
- if opt.deprecated_hunk_style.is_some() {
- // As in the other cases, we only honor the deprecated option if the replacement option has
- // apparently been left at its default value.
- let hunk_header_decoration_default = "blue box";
- if opt.hunk_header_decoration_style != hunk_header_decoration_default {
- fatal(
- "Deprecated option --hunk-style cannot be used with --hunk-header-decoration-style. \
- Use --hunk-header-decoration-style.");
- }
- match opt.deprecated_hunk_style.as_deref().map(str::to_lowercase) {
- Some(attr) if attr == "plain" => opt.hunk_header_decoration_style = "".to_string(),
- Some(attr) if attr.is_empty() => {}
- Some(attr) => opt.hunk_header_decoration_style = attr,
- None => {}
- }
- opt.deprecated_hunk_style = None;
- }
-}
-
-fn _get_rewritten_commit_file_hunk_header_style_string(
- style_default_pair: (&str, Option<&str>),
- deprecated_args_style_pair: (Option<&str>, Option<&str>),
-) -> Option<String> {
- let format_style = |pair: (&str, Option<&str>)| {
- format!(
- "{}{}",
- pair.0,
- match pair.1 {
- Some(s) => format!(" {}", s),
- None => "".to_string(),
- }
- )
- };
- match deprecated_args_style_pair {
- (None, None) => None,
- deprecated_args_style_pair => Some(format_style((
- deprecated_args_style_pair.0.unwrap_or(style_default_pair.0),
- match deprecated_args_style_pair.1 {
- Some(s) => Some(s),
- None => style_default_pair.1,
- },
- ))),
- }
-}
-
-fn _get_rewritten_minus_plus_style_string(
- style: &str,
- style_default_pair: (&str, &str),
- deprecated_args_style_pair: (Option<&str>, Option<&str>),
- element_name: &str,
-) -> Option<String> {
- let format_style = |pair: (&str, &str)| format!("{} {}", pair.0, pair.1);
- match (style, deprecated_args_style_pair) {
- (_, (None, None)) => None, // no rewrite
- (style, deprecated_args_style_pair) if style == format_style(style_default_pair) => {
- // TODO: We allow the deprecated argument values to have effect if
- // the style argument value is equal to its default value. This is
- // non-ideal, because the user may have explicitly supplied the
- // style argument (i.e. it might just happen to equal the default).
- Some(format_style((
- deprecated_args_style_pair.0.unwrap_or(style_default_pair.0),
- deprecated_args_style_pair.1.unwrap_or(style_default_pair.1),
- )))
- }
- (_, (_, Some(_))) => {
- fatal(format!(
- "--{name}-color cannot be used with --{name}-style. \
- Use --{name}-style=\"fg bg attr1 attr2 ...\" to set \
- foreground color, background color, and style attributes. \
- --{name}-color can only be used to set the background color. \
- (It is still available for backwards-compatibility.)",
- name = element_name,
- ));
- }
- (_, (Some(_), None)) => {
- fatal(format!(
- "Deprecated option --highlight-removed cannot be used with \
- --{name}-style. Use --{name}-style=\"fg bg attr1 attr2 ...\" \
- to set foreground color, background color, and style \
- attributes.",
- name = element_name,
- ));
- }
- }
-}
diff --git a/src/parse_style.rs b/src/parse_style.rs
index 7c9ce347..eaeba24c 100644
--- a/src/parse_style.rs
+++ b/src/parse_style.rs
@@ -63,66 +63,6 @@ impl Style {
);
style
}
-
- /// As from_str_with_handling_of_special_decoration_attributes but respecting an optional
- /// foreground color which has precedence when present.
- pub fn from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
- style_string: &str,
- default: Option<Self>,
- decoration_style_string: Option<&str>,
- deprecated_foreground_color_arg: Option<&str>,
- true_color: bool,
- git_config: Option<&GitConfig>,
- ) -> Self {
- let mut style = Self::from_str_with_handling_of_special_decoration_attributes(
- style_string,
- default,
- decoration_style_string,
- true_color,
- git_config,
- );
- if let Some(s) = deprecated_foreground_color_arg {
- // The deprecated --{commit,file,hunk}-color args functioned to set the decoration
- // foreground color. In the case of file, it set the text foreground color also.
- let foreground_from_deprecated_arg =
- parse_ansi_term_style(s, None, true_color, git_config)
- .0
- .foreground;
- style.ansi_term_style.foreground = foreground_from_deprecated_arg;
- style.decoration_style = match style.decoration_style {
- DecorationStyle::Box(mut ansi_term_style) => {
- ansi_term_style.foreground = foreground_from_deprecated_arg;
- DecorationStyle::Box(ansi_term_style)
- }
- DecorationStyle::Underline(mut ansi_term_style) => {
- ansi_term_style.foreground = foreground_from_deprecated_arg;
- DecorationStyle::Underline(ansi_term_style)
- }
- DecorationStyle::Overline(mut ansi_term_style) => {
- ansi_term_style.foreground = foreground_from_deprecated_arg;
- DecorationStyle::Overline(ansi_term_style)
- }
- DecorationStyle::UnderOverline(mut ansi_term_style) => {
- ansi_term_style.foreground = foreground_from_deprecated_arg;
- DecorationStyle::UnderOverline(ansi_term_style)
- }
- DecorationStyle::BoxWithUnderline(mut ansi_term_style) => {
- ansi_term_style.foreground = foreground_from_deprecated_arg;
- DecorationStyle::BoxWithUnderline(ansi_term_style)
- }
- DecorationStyle::BoxWithOverline(mut ansi_term_style) => {
- ansi_term_style.foreground = foreground_from_deprecated_arg;
- DecorationStyle::BoxWithOverline(ansi_term_style)
- }
- DecorationStyle::BoxWithUnderOverline(mut ansi_term_style) => {
- ansi_term_style.foreground = foreground_from_deprecated_arg;
- DecorationStyle::BoxWithUnderOverline(ansi_term_style)
- }
- DecorationStyle::NoDecoration => style.decoration_style,
- };
- }
- style
- }
}
bitflags! {
@@ -632,48 +572,4 @@ mod tests {
}
)
}
-
- #[test]
- fn test_style_from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
- ) {
- let expected_decoration_style = DecorationStyle::BoxWithUnderOverline(ansi_term::Style {
- foreground: Some(ansi_term::Color::Red),
- background: Some(ansi_term::Color::Green),
- is_bold: true,
- ..ansi_term::Style::new()
- });
- let actual_style = Style::from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
- "", None, Some("ol red box bold green ul"), None, true, None
- );
- assert_eq!(
- actual_style,
- Style {
- decoration_style: expected_decoration_style,
- ..Style::new()
- }
- )
- }
-
- #[test]
- fn test_style_from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg_raw_with_box(
- ) {
- let actual_style = Style::from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
- "raw",
- None,
- Some("box"),
- None,
- true,
- None,
- );
- let empty_ansi_term_style = ansi_term::Style::new();
- assert_eq!(
- actual_style,
- Style {
- ansi_term_style: empty_ansi_term_style,
- decoration_style: DecorationStyle::Box(empty_ansi_term_style),
- is_raw: true,
- ..Style::new()
- }
- )
- }
}
diff --git a/src/parse_styles.rs b/src/parse_styles.rs
index 1bee9e54..4736db3b 100644
--- a/src/parse_styles.rs
+++ b/src/parse_styles.rs
@@ -310,53 +310,55 @@ fn make_line_number_styles(opt: &cli::Opt, styles: &mut HashMap<&str, StyleRefer
fn make_commit_file_hunk_header_styles(opt: &cli::Opt, styles: &mut HashMap<&str, StyleReference>) {
let true_color = opt.computed.true_color;
styles.extend([
- ("commit-style",
- style_from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
+ (
+ "commit-style",
+ style_from_str_with_handling_of_special_decoration_attributes(
&opt.commit_style,
None,
Some(&opt.commit_decoration_style),
- opt.deprecated_commit_color.as_deref(),
true_color,
opt.git_config.as_ref(),
- )
+ ),
),
- ("file-style",
- style_from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
+ (
+ "file-style",
+ style_from_str_with_handling_of_special_decoration_attributes(
&opt.file_style,
None,
Some(&opt.file_decoration_style),
- opt.deprecated_file_color.as_deref(),
true_color,
opt.git_config.as_ref(),
- )
+ ),
),
- ("hunk-header-style",
- style_from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
+ (
+ "hunk-header-style",
+ style_from_str_with_handling_of_special_decoration_attributes(
&opt.hunk_header_style,
None,
Some(&opt.hunk_header_decoration_style),
- opt.deprecated_hunk_color.as_deref(),
true_color,
opt.git_config.as_ref(),
- )
+ ),
),
- ("hunk-header-file-style",
+ (
+ "hunk-header-file-style",
style_from_str_with_handling_of_special_decoration_attributes(
&opt.hunk_header_file_style,
None,
None,
true_color,
opt.git_config.as_ref(),
- )
+ ),
),
- ("hunk-header-line-number-style",
+ (
+ "hunk-header-line-number-style",
style_from_str_with_handling_of_special_decoration_attributes(
&opt.hunk_header_line_number_style,
None,
None,
true_color,
opt.git_config.as_ref(),
- )
+ ),
),
]);
}
@@ -555,28 +557,6 @@ fn style_from_str_with_handling_of_special_decoration_attributes(
}
}
-fn style_from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
- style_string: &str,
- default: Option<Style>,
- decoration_style_string: Option<&str>,
- deprecated_foreground_color_arg: Option<&str>,
- true_color: bool,
- git_config: Option<&GitConfig>,
-) -> StyleReference {
- if is_style_reference(style_string) {
- StyleReference::Reference(style_string.to_owned())
- } else {
- StyleReference::Style(Style::from_str_with_handling_of_special_decoration_attributes_and_respecting_deprecated_foreground_color_arg(
- style_string,
- default,
- decoration_style_string,
- deprecated_foreground_color_arg,
- true_color,
- git_config,
- ))
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 3ef649b8..0db30977 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -387,11 +387,6 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e
]);
}
- #[test]
- fn test_commit_style_box_ul_deprecated_options() {
- _do_test_commit_style_box_ul(&["--commit-color", "blue", "--commit-style", "box"]);
- }
-
fn _do_test_commit_style_box(args: &[&str]) {
let config = integration_test_utils::make_config_from_args(args);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
@@ -527,16 +522,6 @@ commit 94907c0f136f46dc46ffae2dc92dca9af7eb7c2e │
]);
}
- #[test]
- fn test_commit_style_underline_deprecated_options() {
- _do_test_commit_style_underline(&[
- "--commit-color",
- "yellow",
- "--commit-style",
- "underline",
- ]);
- }
-
fn _do_test_commit_style_underline(args: &[&str]) {
let config = integration_test_utils::make_config_from_args(args);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
@@ -704,11 +689,6 @@ src/align.rs
]);
}
- #[test]
- fn test_file_style_box_ul_deprecated_options() {
- _do_test_file_style_box_ul(&["--file-color", "green", "--file-style", "box"]);
- }
-
fn _do_test_file_style_box(args: &[&str]) {
let config = integration_test_utils::make_config_from_args(args);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
@@ -784,11 +764,6 @@ src/align.rs │
]);
}
- #[test]
- fn test_file_style_underline_deprecated_options() {
- _do_test_file_style_underline(&["--file-color", "magenta", "--file-style", "underline"]);
- }
-
fn _do_test_file_style_underline(args: &[&str]) {
let config = integration_test_utils::make_config_from_args(args);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
@@ -1207,11 +1182,6 @@ impl<'a> Alignment<'a> {
]);
}
- #[test]
- fn test_hunk_header_style_box_deprecated_options() {
- _do_test_hunk_header_style_box(&["--hunk-color", "white", "--hunk-style", "box"]);
- }
-
fn _do_test_hunk_header_style_box(args: &[&str]) {
let config = integration_test_utils::make_config_from_args(args);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
@@ -1324,16 +1294,6 @@ src/align.rs:71: impl<'a> Alignment<'a> { │
]);
}
- #[test]
- fn test_hunk_header_style_underline_deprecated_options() {
- _do_test_hunk_header_style_underline(&[
- "--hunk-color",
- "black",
- "--hunk-style",
- "underline",
- ]);
- }
-
fn _do_test_hunk_header_style_underline(args: &[&str]) {
let config = integration_test_utils::make_config_from_args(args);
let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
diff --git a/tests/test_deprecated_options b/tests/test_deprecated_options
index 8202a70c..1665755e 100755
--- a/tests/test_deprecated_options
+++ b/tests/test_deprecated_options
@@ -6,24 +6,6 @@ DELTA="$DELTA_BIN --no-gitconfig"
foreground_color=red
for decoration_attr in box underline plain; do
-
git show | $DELTA --commit-style $decoration_attr
git show | $DELTA --file-style $decoration_attr
- git show | $DELTA --hunk-style $decoration_attr
-
- git show | $DELTA --commit-color $foreground_color
- git show | $DELTA --file-color $foreground_color
- git show | $DELTA --hunk-color $foreground_color
-
- git show | $DELTA --commit-color $foreground_color --commit-style $decoration_attr
- git show | $DELTA --file-color $foreground_color --file-style $decoration_attr
- git show | $DELTA --hunk-color $foreground_color --hunk-style $decoration_attr
-
done
-
-background_color=blue
-for option in --minus-color --plus-color --minus-emph-color --plus-emph-color; do
- git show | $DELTA $option $background_color
-done
-
-git show | $DELTA --theme=GitHub --highlight-removed