git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johannes Altmanninger <aclopte@gmail.com>
Date
Nov 17, 2020, 21:35 UTC
Message-ID
<20201117213551.2539438-4-aclopte@gmail.com>
In-Reply-To
<20201117213551.2539438-1-aclopte@gmail.com>
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 --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;
-- 
2.29.2
Previous: Eric Sunshine
Message 7 of 7 in “range-diff should suppress context-only changes?”
  1. Jeff KingNov 5, 2020
  2. Junio C HamanoNov 5, 2020
  3. Johannes AltmanningerNov 17, 2020
  4. 1/3 range-diff: move " ## filename ##" headers to the first columnJohannes Altmanninger, Nov 17, 2020
  5. 2/3 range-diff: ignore context-only changesJohannes Altmanninger, Nov 17, 2020
  6. Eric SunshineNov 17, 2020
  7. 3/3 range-diff: only compute patch diff when patches are differentJohannes Altmanninger, Nov 17, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.