From 84b187e375a397027edd2833aee83e9d692f0c04 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 6 Jul 2023 20:39:35 +1200 Subject: [PATCH] diff: Only output a unified/context header if there is a diff --- Userland/Utilities/diff.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/diff.cpp b/Userland/Utilities/diff.cpp index 25fcc0651b..fce194728d 100644 --- a/Userland/Utilities/diff.cpp +++ b/Userland/Utilities/diff.cpp @@ -57,6 +57,9 @@ ErrorOr serenity_main(Main::Arguments arguments) auto hunks = TRY(Diff::from_text(TRY(file1->read_until_eof()), TRY(file2->read_until_eof()), number_context_lines)); + if (hunks.is_empty()) + return 0; + if (unified) { TRY(Diff::write_unified_header(filename1, filename2, *out)); for (auto const& hunk : hunks) @@ -70,5 +73,5 @@ ErrorOr serenity_main(Main::Arguments arguments) TRY(Diff::write_normal(hunk, *out, color_output)); } - return hunks.is_empty() ? 0 : 1; + return 1; }