Always use the RHS for language detection

Taking the longest path breaks if we have e.g. /dev/null and foo.py,
because foo.py is shorter.
pull/341/head
Wilfred Hughes 2022-08-18 22:58:43 +07:00
parent 01cce54978
commit fb38e7a24f
2 changed files with 7 additions and 4 deletions

@ -1,5 +1,10 @@
## 0.33 (unreleased)
### Parsing
Fixed an issue with language detection when file names were very
short.
### Command Line Interface
Difftastic prefers to show the second path when called with two

@ -242,10 +242,8 @@ fn diff_file_content(
rhs_src.pop();
}
// 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, guess_path) = if lhs_src.len() > rhs_src.len() {
// Prefer the RHS path for language detection, unless it's /dev/null.
let (guess_src, guess_path) = if rhs_display_path == "/dev/null" {
// TODO: take a Path directly instead.
(&lhs_src, Path::new(&lhs_display_path))
} else {