diff mbox series

[3/3] range-diff: only compute patch diff when patches are different

Message ID 20201117213551.2539438-4-aclopte@gmail.com (mailing list archive)
State New, archived
Headers show
Series [1/3] range-diff: move " ## filename ##" headers to the first column | expand

Commit Message

Johannes Altmanninger Nov. 17, 2020, 9:35 p.m. UTC
This is a pure optimization, probably with negligible impact. I'm not sure
if it is a good idea because it could obscure future bugs.
---
 range-diff.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/range-diff.c b/range-diff.c
index df2147ef79..343a71d3eb 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -388,7 +388,7 @@  static int are_diffs_equivalent(const char *a_diff, const char *b_diff) {
 	return 1;
 }
 
-static void output_pair_header(struct diff_options *diffopt,
+static char output_pair_header(struct diff_options *diffopt,
 			       int patch_no_width,
 			       struct strbuf *buf,
 			       struct strbuf *dashes,
@@ -456,6 +456,8 @@  static void output_pair_header(struct diff_options *diffopt,
 	strbuf_addf(buf, "%s\n", color_reset);
 
 	fwrite(buf->buf, buf->len, 1, diffopt->file);
+
+	return status;
 }
 
 static struct userdiff_driver section_headers = {
@@ -537,9 +539,9 @@  static void output(struct string_list *a, struct string_list *b,
 		/* Show matching LHS/RHS pair. */
 		if (j < b->nr) {
 			a_util = a->items[b_util->matching].util;
-			output_pair_header(diffopt, patch_no_width,
+			char status = output_pair_header(diffopt, patch_no_width,
 					   &buf, &dashes, a_util, b_util);
-			if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT)) {
+			if (!(diffopt->output_format & DIFF_FORMAT_NO_OUTPUT) && status != '=') {
 				patch_diff(a_util->patch, a_util->diff_offset, 
 						b_util->patch, b_util->diff_offset, diffopt);
 			        diffopt->ignore_regex_nr = ignoring_context_only_changes;