Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix diff interactivefilter when decoration option is enabled #367

Merged
merged 3 commits into from Nov 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ pub fn set_options(
// there (does not emit lines in 1-1 correspondence with raw git output). See #274.
if opt.color_only {
opt.side_by_side = false;
opt.file_decoration_style = "none".to_string();
opt.commit_decoration_style = "none".to_string();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Ryuta69, thanks for this PR! I have one question: aren't these already set to "none" by the color-only feature? (see the way that feature "inherits" from the raw feature)

Copy link
Author

@ghost ghost Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dandavison
Thank you for review!
Oh, is that supposed to be? If so, currently it seems not working when a user supply some options in gitconfig.

In order to give priority to the options in features/** even when a user supply option in gitconfig, I think we must switch the conditions below (Of course only switching them would break some tests such as features::tests::test_main_section_overrides_feature. I still need extra check.)

delta/src/options/get.rs

Lines 54 to 72 in 1ca0615

if let Some(git_config) = git_config {
if let Some(value) = git_config.get::<Self>(&format!("delta.{}", option_name)) {
return Some(value);
}
}
for feature in opt.features.to_lowercase().split_whitespace().rev() {
match Self::get_provenanced_value_for_feature(
option_name,
&feature,
&builtin_features,
opt,
git_config,
) {
Some(GitConfigValue(value)) | Some(DefaultValue(value)) => {
return Some(value.into());
}
None => {}
}
}

Currently, both not working as you suggested.

[delta]
	file-decoration-style = ul
# git diff | delta --color-only
# => It still prints file-decoration-style as ul.

------------

[delta]
	minus-style = blue
# git diff | delta --raw
# => It still prints minus-style as blue.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Ryuta69, sorry to be slow -- I was meaning to look into what we're discussing here but didn't find time yet. Definitely looking forward to having this PR in the next release.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dandavison
Sure! The first priority is your schedule, and I'll help when you have a time. Again, thank you for this great OSS.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this sounds like a potential headache -- let's just keep the hard-coded override to "none" that you have, and we can maybe worry in the future about whether the none-value was supposed to be inherited from the feature automatically.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dandavison
I understand, thank you for review.
If I find a way to solve, I'm going to create PR.

opt.file_style = "raw".to_string();
opt.commit_style = "raw".to_string();
opt.hunk_header_style = "raw".to_string();
Expand Down
129 changes: 97 additions & 32 deletions src/tests/test_example_diffs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,38 +837,100 @@ src/align.rs

#[test]
fn test_color_only_output_is_in_one_to_one_correspondence_with_input() {
_do_test_output_is_in_one_to_one_correspondence_with_input(&["--color-only", "true"]);
_do_test_output_is_in_one_to_one_correspondence_with_input(&[
"--color-only",
"true",
"--hunk-header-style",
"normal",
"--line-numbers",
]);
_do_test_output_is_in_one_to_one_correspondence_with_input(&[
"--color-only",
"true",
"--file-style",
"blue",
"--commit-style",
"omit",
"--hunk-header-style",
"omit",
"--hunk-header-decoration-style",
"omit",
]);
_do_test_output_is_in_one_to_one_correspondence_with_input(&[
"--color-only",
"true",
"--file-style",
"blue",
"--commit-style",
"red",
"--hunk-header-style",
"syntax",
"--hunk-header-decoration-style",
"box",
]);
let user_suppliable_configs: &[&[&str]] = &[
&["--color-only", "--light"],
&["--color-only", "--dark"],
&["--color-only", "--line-numbers"],
&["--color-only", "--side-by-side"],
&["--color-only", "--diff-highlight"],
&["--color-only", "--diff-so-fancy"],
&["--color-only", "--navigate"],
&["--color-only", "--hyperlinks"],
&["--color-only", "--keep-plus-minus-markers"],
&["--color-only", "--raw"],
&["--color-only", "--syntax-theme", "Monokai Extended"],
&["--color-only", "--minus-style", "syntax bold auto"],
&["--color-only", "--zero-style", "red strike"],
&["--color-only", "--plus-style", "red blink"],
&["--color-only", "--minus-emph-style", "red dim"],
&["--color-only", "--minus-non-emph-style", "red hidden"],
&["--color-only", "--plus-emph-style", "red reverse"],
&["--color-only", "--plus-non-emph-style", "red bold ul"],
&["--color-only", "--commit-style", "red bold ul"],
&[
"--color-only",
"--commit-decoration-style",
"bold yellow box ul",
],
&["--color-only", "--file-style", "red bold ul"],
&[
"--color-only",
"--file-decoration-style",
"bold yellow box ul",
],
&["--color-only", "--hunk-header-style", "red bold ul"],
&[
"--color-only",
"--hunk-header-decoration-style",
"bold yellow box ul",
],
&[
"--color-only",
"--line-numbers",
"--line-numbers-minus-style",
"#444444",
],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, these --line-numbers-*** is not necessary because line-numbers would be disabled. However, I can't make sure if the option's behavior will be changed, so I added anyway.

It's just my opinion.

&[
"--color-only",
"--line-numbers",
"--line-numbers-zero-style",
"#444444",
],
&[
"--color-only",
"--line-numbers",
"--line-numbers-plus-style",
"#444444",
],
&[
"--color-only",
"--line-numbers",
"--line-numbers-left-format",
"{nm:>4}┊",
],
&[
"--color-only",
"--line-numbers",
"--line-numbers-right-format",
"{np:>4}│",
],
&[
"--color-only",
"--line-numbers",
"--line-numbers-left-style",
"blue",
],
&[
"--color-only",
"--line-numbers",
"--line-numbers-right-style",
"blue",
],
&["--color-only", "--file-modified-label", "hogehoge"],
&["--color-only", "--file-removed-label", "hogehoge"],
&["--color-only", "--file-added-label", "hogehoge"],
&["--color-only", "--file-renamed-label", "hogehoge"],
&["--color-only", "--max-line-length", "1"],
&["--color-only", "--width", "1"],
&["--color-only", "--tabs", "10"],
&["--color-only", "--24-bit-color", "always"],
&["--color-only", "--inspect-raw-lines", "false"],
&["--color-only", "--whitespace-error-style", "22 reverse"],
];

for config in user_suppliable_configs {
_do_test_output_is_in_one_to_one_correspondence_with_input(config);
}
}

fn _do_test_output_is_in_one_to_one_correspondence_with_input(args: &[&str]) {
Expand All @@ -882,6 +944,9 @@ src/align.rs

// Although git patch options only checks the line counts of input and output,
// we should check if they are identical as well to avoid unexpected decoration.
if args.contains(&"--max-line-length") {
return;
}
for n in 0..input_lines.len() {
let input_line = input_lines[n];
// If config.line_numbers is enabled,
Expand Down