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

[PATCH 1/6] diff.c: factor out shrinking of potential moved line blocks

From
Stefan Beller <sbeller@google.com>
Date
Jun 28, 2017, 00:56 UTC
Message-ID
<20170628005651.8110-2-sbeller@google.com>
In-Reply-To
<20170628005651.8110-1-sbeller@google.com>

This is cleaner and keeps the rather large function that performs the move detection smaller.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 diff.c | 50 +++++++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/diff.c b/diff.c
index 82ace48c38..5311dcf133 100644
--- a/diff.c
+++ b/diff.c
@@ -808,6 +808,33 @@ static void add_lines_to_move_detection(struct diff_options *o,
 	}
 }
 
+static int shrink_potential_moved_blocks(struct moved_entry **pmb,
+					 int pmb_nr)
+{
+	int lp, rp;
+
+	/* Shrink the set of potential block to the remaining running */
+	for (lp = 0, rp = pmb_nr - 1; lp <= rp;) {
+		while (lp < pmb_nr && pmb[lp])
+			lp++;
+		/* lp points at the first NULL now */
+
+		while (rp > -1 && !pmb[rp])
+			rp--;
+		/* rp points at the last non-NULL */
+
+		if (lp < pmb_nr && rp > -1 && lp < rp) {
+			pmb[lp] = pmb[rp];
+			pmb[rp] = NULL;
+			rp--;
+			lp++;
+		}
+	}
+
+	/* Remember the number of running sets */
+	return rp + 1;
+}
+
 /* Find blocks of moved code, delegate actual coloring decision to helper */
 static void mark_color_as_moved(struct diff_options *o,
 				struct hashmap *add_lines,
@@ -822,7 +849,7 @@ static void mark_color_as_moved(struct diff_options *o,
 		struct moved_entry *key;
 		struct moved_entry *match = NULL;
 		struct emitted_diff_symbol *l = &o->emitted_symbols->buf[n];
-		int i, lp, rp;
+		int i;
 
 		switch (l->s) {
 		case DIFF_SYMBOL_PLUS:
@@ -864,26 +891,7 @@ static void mark_color_as_moved(struct diff_options *o,
 			}
 		}
 
-		/* Shrink the set of potential block to the remaining running */
-		for (lp = 0, rp = pmb_nr - 1; lp <= rp;) {
-			while (lp < pmb_nr && pmb[lp])
-				lp++;
-			/* lp points at the first NULL now */
-
-			while (rp > -1 && !pmb[rp])
-				rp--;
-			/* rp points at the last non-NULL */
-
-			if (lp < pmb_nr && rp > -1 && lp < rp) {
-				pmb[lp] = pmb[rp];
-				pmb[rp] = NULL;
-				rp--;
-				lp++;
-			}
-		}
-
-		/* Remember the number of running sets */
-		pmb_nr = rp + 1;
+		pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
 
 		if (pmb_nr == 0) {
 			/*
-- 
2.13.0.31.g9b732c453e
Previous: Stefan BellerNext: Stefan Beller
Message 2 of 18 in “Fixing up sb/diff-color-moved”
  1. 0/6 Fixing up sb/diff-color-movedStefan Beller, Jun 28, 2017
  2. 1/6 diff.c: factor out shrinking of potential moved line blocksStefan Beller, Jun 28, 2017
  3. 2/6 diff.c: change the default for move coloring to zebraStefan Beller, Jun 28, 2017
  4. Junio C HamanoJun 28, 2017
  5. Stefan BellerJun 28, 2017
  6. 3/6 diff.c: better reporting on color.moved bogus configurationStefan Beller, Jun 28, 2017
  7. 4/6 Documentation/diff: reword color movedStefan Beller, Jun 28, 2017
  8. Junio C HamanoJun 28, 2017
  9. 5/6 diff.c: omit uninteresting moved linesStefan Beller, Jun 28, 2017
  10. Junio C HamanoJun 28, 2017
  11. Stefan BellerJun 28, 2017
  12. 6/6 diff.c: detect blocks despite whitespace changesStefan Beller, Jun 28, 2017
  13. Junio C HamanoJun 28, 2017
  14. Junio C HamanoJun 28, 2017
  15. Stefan BellerJun 28, 2017
  16. Junio C HamanoJun 28, 2017
  17. Stefan BellerJun 29, 2017
  18. Junio C HamanoJun 29, 2017

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.