Improve handling of /dev/null paths when there are two CLI argsuments

When git calls us, we always know the file name. If we're called with
two arguments and one is /dev/null, use the other for language
detection and display.
pull/315/head
Wilfred Hughes 2022-07-11 21:38:36 +07:00
parent e8865905b7
commit 38c6718c86
3 changed files with 20 additions and 12 deletions

@ -13,6 +13,11 @@ TypeScript.
Fixed an issue with inline mode where there was a blank line between
every line.
### Command Line Interface
Fixed language detection and filename display when one path was
`/dev/null` and difftastic was invoked with two arguments.
## 0.30 (released 4th July 2022)
### Parsing

@ -380,19 +380,24 @@ pub fn header(
display_options.use_color,
display_options.background_color,
);
let lhs_path_pretty = apply_header_color(
lhs_display_path,
display_options.use_color,
display_options.background_color,
);
if hunk_num == 1 && lhs_display_path != rhs_display_path && display_options.in_vcs {
let lhs_path_pretty = apply_header_color(
lhs_display_path,
display_options.use_color,
display_options.background_color,
);
let renamed = format!("Renamed {} to {}", lhs_path_pretty, rhs_path_pretty,);
format!(
"{}\n{} --- {}{}",
renamed, rhs_path_pretty, divider, language_name
)
} else {
format!("{} --- {}{}", rhs_path_pretty, divider, language_name)
let path_pretty = if lhs_display_path == "/dev/null" {
rhs_path_pretty
} else {
lhs_path_pretty
};
format!("{} --- {}{}", path_pretty, divider, language_name)
}
}

@ -242,16 +242,14 @@ fn diff_file_content(
rhs_src.pop();
}
// TODO: take a Path directly instead.
let guess_path = Path::new(&rhs_display_path);
// Take the larger of the two files when guessing the
// language. This is useful when we've added or removed a whole
// file.
let guess_src = if lhs_src.len() > rhs_src.len() {
&lhs_src
let (guess_src, guess_path) = if lhs_src.len() > rhs_src.len() {
// TODO: take a Path directly instead.
(&lhs_src, Path::new(&lhs_display_path))
} else {
&rhs_src
(&rhs_src, Path::new(&rhs_display_path))
};
let language = language_override.or_else(|| guess(guess_path, guess_src));
let lang_config = language.map(tsp::from_language);