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 040dd3b0e2
commit 5fe6d551d9
2 changed files with 7 additions and 4 deletions

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

@ -242,10 +242,8 @@ fn diff_file_content(
rhs_src.pop(); rhs_src.pop();
} }
// Take the larger of the two files when guessing the // Prefer the RHS path for language detection, unless it's /dev/null.
// language. This is useful when we've added or removed a whole let (guess_src, guess_path) = if rhs_display_path == "/dev/null" {
// file.
let (guess_src, guess_path) = if lhs_src.len() > rhs_src.len() {
// TODO: take a Path directly instead. // TODO: take a Path directly instead.
(&lhs_src, Path::new(&lhs_display_path)) (&lhs_src, Path::new(&lhs_display_path))
} else { } else {