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

[PATCH 08/10] diff.c: factor advance_or_nullify out of mark_color_as_moved

From
Stefan Beller <sbeller@google.com>
Date
Jul 18, 2018, 19:31 UTC
Message-ID
<20180718193156.47365-9-sbeller@google.com>
In-Reply-To
<20180718193156.47365-1-sbeller@google.com>

This moves the part of code that checks if we're still in a block into its own function. We'll need a different approach on advancing the blocks in a later patch, so having it as a separate function will prove useful.

While at it rename the variable `p` to `prev` to indicate that it refers to the previous line. This is as pmb[i] was assigned in the last iteration of the outmost for loop.

Further rename `pnext` to `cur` to indicate that this should match up with the current line of the outmost for loop.

Also replace the advancement of pmb[i] to reuse `cur` instead of using `p->next` (which is how the name for pnext could be explained.

Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/diff.c b/diff.c
index 70eeb40c5fd..4963819e530 100644
--- a/diff.c
+++ b/diff.c
@@ -801,6 +801,25 @@ static void add_lines_to_move_detection(struct diff_options *o,
 	}
 }
 
+static void pmb_advance_or_null(struct diff_options *o,
+				struct moved_entry *match,
+				struct hashmap *hm,
+				struct moved_entry **pmb,
+				int pmb_nr)
+{
+	int i;
+	for (i = 0; i < pmb_nr; i++) {
+		struct moved_entry *prev = pmb[i];
+		struct moved_entry *cur = (prev && prev->next_line) ?
+				prev->next_line : NULL;
+		if (cur && !hm->cmpfn(o, cur, match, NULL)) {
+			pmb[i] = cur;
+		} else {
+			pmb[i] = NULL;
+		}
+	}
+}
+
 static int shrink_potential_moved_blocks(struct moved_entry **pmb,
 					 int pmb_nr)
 {
@@ -875,7 +894,6 @@ 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;
 
 		switch (l->s) {
 		case DIFF_SYMBOL_PLUS:
@@ -906,17 +924,7 @@ static void mark_color_as_moved(struct diff_options *o,
 		if (o->color_moved == COLOR_MOVED_PLAIN)
 			continue;
 
-		/* Check any potential block runs, advance each or nullify */
-		for (i = 0; i < pmb_nr; i++) {
-			struct moved_entry *p = pmb[i];
-			struct moved_entry *pnext = (p && p->next_line) ?
-					p->next_line : NULL;
-			if (pnext && !hm->cmpfn(o, pnext, match, NULL)) {
-				pmb[i] = p->next_line;
-			} else {
-				pmb[i] = NULL;
-			}
-		}
+		pmb_advance_or_null(o, match, hm, pmb, pmb_nr);
 
 		pmb_nr = shrink_potential_moved_blocks(pmb, pmb_nr);
 
-- 
2.18.0.233.g985f88cf7e-goog
Previous: Stefan BellerNext: Stefan Beller
Message 9 of 12 in “[PATCHv6 00/10] Reroll of sb/diff-color-move-more”
  1. Stefan BellerJul 18, 2018
  2. 01/10 xdiff/xdiff.h: remove unused flagsStefan Beller, Jul 18, 2018
  3. 02/10 xdiff/xdiffi.c: remove unneeded function declarationsStefan Beller, Jul 18, 2018
  4. 03/10 t4015: avoid git as a pipe inputStefan Beller, Jul 18, 2018
  5. 04/10 diff.c: do not pass diff options as keydata to hashmapStefan Beller, Jul 18, 2018
  6. 05/10 diff.c: adjust hash function signature to match hashmap expectationStefan Beller, Jul 18, 2018
  7. 06/10 diff.c: add a blocks mode for moved code detectionStefan Beller, Jul 18, 2018
  8. 07/10 diff.c: decouple white space treatment from move detection algorithmStefan Beller, Jul 18, 2018
  9. 08/10 diff.c: factor advance_or_nullify out of mark_color_as_movedStefan Beller, Jul 18, 2018
  10. 09/10 diff.c: add white space mode to move detection that allows indent changesStefan Beller, Jul 18, 2018
  11. 10/10 diff.c: offer config option to control ws handling in move detectionStefan Beller, Jul 18, 2018
  12. Junio C HamanoJul 19, 2018

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.