From 82edb1883592b206032506d430020802022daa49 Mon Sep 17 00:00:00 2001 From: KrushnXGIT <256734098+KrushnXGIT@users.noreply.github.com> Date: Fri, 27 Nov 2026 22:14:23 +0530 Subject: [PATCH 1/2] diff: skip the diff for identical contents Text files always went through the diff algorithm, even when both had the same contents. Compare the contents first, as was already done for binary files. Side by side output and ed scripts still go through it: the first shows the lines, the second warns about a missing newline. --- src/diff.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/diff.rs b/src/diff.rs index 7931d4c1..dc045658 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -132,6 +132,13 @@ pub fn compare_files(params: &Params, header: Option<&[u8]>) -> Outcome { return Outcome::Trouble; } + // identical contents need no diff, unless side by side output shows their + // lines or an ed script warns about a missing newline + if from_content == to_content && !matches!(params.format, Format::SideBySide | Format::Ed) { + maybe_report_identical_files(); + return Outcome::Identical; + } + if !params.text && (is_binary(&from_content) || is_binary(&to_content)) { if from_content == to_content { maybe_report_identical_files(); From 1228acab451a3b4ce00ec4ca1555d2d100bc6dae Mon Sep 17 00:00:00 2001 From: KrushnXGIT <256734098+KrushnXGIT@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:39:52 +0530 Subject: [PATCH 2/2] diff: test that -y still prints the lines of identical files --- tests/by-util/test_diff.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/by-util/test_diff.rs b/tests/by-util/test_diff.rs index 2955704d..74c12453 100644 --- a/tests/by-util/test_diff.rs +++ b/tests/by-util/test_diff.rs @@ -36,6 +36,18 @@ fn no_differences_report_identical_files( .stdout_is(format!("Files file1 and {second} are identical\n")); } +// Side by side output still shows the lines of two identical files. +#[test] +fn no_differences_side_by_side() { + let (at, ts) = at_and_ts!(); + at.write("file1", "foo\nbar\n"); + at.write("file2", "foo\nbar\n"); + ts.ucmd() + .args(&["-y", "--width=40", "file1", "file2"]) + .succeeds() + .stdout_is("foo\t\t foo\nbar\t\t bar\n"); +} + #[rstest] fn differences(#[values(&[][..], &["-u"], &["-c"], &["-e"])] format: &[&str]) { let (at, ts) = at_and_ts!();