Skip to contentSkip to conversation

Moved code detection: ignore space on uniform indentation

PATCH Superseded Stefan Beller 2 participants 18 messages Apr 24, 2018 – Apr 25, 2018 1 message not in the archive Documentation

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Moved code detection: ignore space on uniform indentation

v2:
I think I have addressed Jonathans feedback
* by using a string instead of counting the first character only.
* refined tests slightly (easier to read)
* moved white space handling for moved blocks into its own flag field, keeping the enum for the actual mode of move detection.

v1:
This is a re-attempt of [1], which allows the moved code detection to ignore blanks in various modes.

patches 1-5 are refactoring, patch 6 adds all existing white space options of regular diff to the move detection. (I am unsure about this patch, as I presume we want to keep the option space at a minimum if possible).

The fun is in the last patch, which allows white space sensitive languages to trust the move detection, too. Each block that is marked as moved will have the same delta in {in-, de-}dentation.
I would think this mode might be a reasonable default eventually.

Thanks,
Stefan

[1] https://public-inbox.org/git/[email protected]/

Stefan Beller (7):
xdiff/xdiff.h: remove unused flags
xdiff/xdiffi.c: remove unneeded function declarations diff.c: do not pass diff options as keydata to hashmap diff.c: adjust hash function signature to match hashmap expectation diff.c: add a blocks mode for moved code detection diff.c: decouple white space treatment from move detection algorithm diff.c: add --color-moved-ignore-space-delta option

 Documentation/diff-options.txt |  25 ++++-
 diff.c                         | 128 ++++++++++++++++++----
 diff.h                         |   8 +-
 t/t4015-diff-whitespace.sh     | 192 +++++++++++++++++++++++++++++++--
 xdiff/xdiff.h                  |   8 --
 xdiff/xdiffi.c                 |  17 ---
 6 files changed, 322 insertions(+), 56 deletions(-)
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#1 lore raw

PATCH v2 1/7 xdiff/xdiff.h: remove unused flags

These flags were there since the beginning (3443546f6e (Use a *real* built-in diff generator, 2006-03-24), but were never used. Remove them.

---
 xdiff/xdiff.h | 8 --------
 1 file changed, 8 deletions(-)
xdiff/xdiff.h +0 -8
index c1937a2911..2356da5f78 100644
@@ -52,14 +52,6 @@ extern "C" {
 #define XDL_EMIT_FUNCNAMES (1 << 0)
 #define XDL_EMIT_FUNCCONTEXT (1 << 2)
 
-#define XDL_MMB_READONLY (1 << 0)
-
-#define XDL_MMF_ATOMIC (1 << 0)
-
-#define XDL_BDOP_INS 1
-#define XDL_BDOP_CPY 2
-#define XDL_BDOP_INSB 3
-
 /* merge simplification levels */
 #define XDL_MERGE_MINIMAL 0
 #define XDL_MERGE_EAGER 1
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#2 lore raw

PATCH v2 2/7 xdiff/xdiffi.c: remove unneeded function declarations

In reply to Stefan Beller

There is no need to forward-declare these functions, as they are used after their implementation only.

---
 xdiff/xdiffi.c | 17 -----------------
 1 file changed, 17 deletions(-)
xdiff/xdiffi.c +0 -17
index 0de1ef463b..3e8aff92bc 100644
@@ -22,34 +22,17 @@
 
 #include "xinclude.h"
 
-
-
 #define XDL_MAX_COST_MIN 256
 #define XDL_HEUR_MIN_COST 256
 #define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1)
 #define XDL_SNAKE_CNT 20
 #define XDL_K_HEUR 4
 
-
-
 typedef struct s_xdpsplit {
 	long i1, i2;
 	int min_lo, min_hi;
 } xdpsplit_t;
 
-
-
-
-static long xdl_split(unsigned long const *ha1, long off1, long lim1,
-		      unsigned long const *ha2, long off2, long lim2,
-		      long *kvdf, long *kvdb, int need_min, xdpsplit_t *spl,
-		      xdalgoenv_t *xenv);
-static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, long chg2);
-
-
-
-
-
 /*
  * See "An O(ND) Difference Algorithm and its Variations", by Eugene Myers.
  * Basically considers a "box" (off1, off2, lim1, lim2) and scan from both
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#3 lore raw

PATCH v2 3/7 diff.c: do not pass diff options as keydata to hashmap

In reply to Stefan Beller

When we initialize the hashmap, we give it a pointer to the diff_options, which it then passes along to each call of the hashmap_cmp_fn function. There's no need to pass it a second time as the "keydata" parameter, and our comparison functions never look at keydata.

This was a mistake left over from an earlier round of 2e2d5ac184 (diff.c: color moved lines differently, 2017-06-30), before hashmap learned to pass the data pointer for us.

---
 diff.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff.c +2 -2
index 1289df4b1f..ce7bedc1b9 100644
@@ -842,13 +842,13 @@ static void mark_color_as_moved(struct diff_options *o,
 		case DIFF_SYMBOL_PLUS:
 			hm = del_lines;
 			key = prepare_entry(o, n);
-			match = hashmap_get(hm, key, o);
+			match = hashmap_get(hm, key, NULL);
 			free(key);
 			break;
 		case DIFF_SYMBOL_MINUS:
 			hm = add_lines;
 			key = prepare_entry(o, n);
-			match = hashmap_get(hm, key, o);
+			match = hashmap_get(hm, key, NULL);
 			free(key);
 			break;
 		default:
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#4 lore raw

PATCH v2 4/7 diff.c: adjust hash function signature to match hashmap expectation

In reply to Stefan Beller

This makes the follow up patch easier.

---
 diff.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
diff.c +9 -7
index ce7bedc1b9..d1bae900cd 100644
@@ -707,11 +707,15 @@ struct moved_entry {
 	struct moved_entry *next_line;
 };
 
-static int moved_entry_cmp(const struct diff_options *diffopt,
-			   const struct moved_entry *a,
-			   const struct moved_entry *b,
+static int moved_entry_cmp(const void *hashmap_cmp_fn_data,
+			   const void *entry,
+			   const void *entry_or_key,
 			   const void *keydata)
 {
+	const struct diff_options *diffopt = hashmap_cmp_fn_data;
+	const struct moved_entry *a = entry;
+	const struct moved_entry *b = entry_or_key;
+
 	return !xdiff_compare_lines(a->es->line, a->es->len,
 				    b->es->line, b->es->len,
 				    diffopt->xdl_opts);
@@ -5534,10 +5538,8 @@ static void diff_flush_patch_all_file_pairs(struct diff_options *o)
 		if (o->color_moved) {
 			struct hashmap add_lines, del_lines;
 
-			hashmap_init(&del_lines,
-				     (hashmap_cmp_fn)moved_entry_cmp, o, 0);
-			hashmap_init(&add_lines,
-				     (hashmap_cmp_fn)moved_entry_cmp, o, 0);
+			hashmap_init(&del_lines, moved_entry_cmp, o, 0);
+			hashmap_init(&add_lines, moved_entry_cmp, o, 0);
 
 			add_lines_to_move_detection(o, &add_lines, &del_lines);
 			mark_color_as_moved(o, &add_lines, &del_lines);
Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#5 lore raw

PATCH v2 5/7 diff.c: add a blocks mode for moved code detection

In reply to Stefan Beller

The new "blocks" mode provides a middle ground between plain and zebra. It is as intuitive (few colors) as plain, but still has the requirement for a minimum of lines/characters to count a block as moved.

(https://public-inbox.org/git/[email protected]/)

---
 Documentation/diff-options.txt |  8 ++++--
 diff.c                         |  6 +++--
 diff.h                         |  5 ++--
 t/t4015-diff-whitespace.sh     | 48 +++++++++++++++++++++++++++++++++-
 4 files changed, 60 insertions(+), 7 deletions(-)
Documentation/diff-options.txt +6 -2
index e3a44f03cd..bb9f1b7cd8 100644
@@ -276,10 +276,14 @@ plain::
 	that are added somewhere else in the diff. This mode picks up any
 	moved line, but it is not very useful in a review to determine
 	if a block of code was moved without permutation.
-zebra::
+blocks:
 	Blocks of moved text of at least 20 alphanumeric characters
 	are detected greedily. The detected blocks are
-	painted using either the 'color.diff.{old,new}Moved' color or
+	painted using either the 'color.diff.{old,new}Moved' color.
+	Adjacent blocks cannot be told apart.
+zebra::
+	Blocks of moved text are detected as in 'blocks' mode. The blocks
+	are painted using either the 'color.diff.{old,new}Moved' color or
 	'color.diff.{old,new}MovedAlternative'. The change between
 	the two colors indicates that a new block was detected.
 dimmed_zebra::
diff.c +4 -2
index d1bae900cd..95c51c0b7d 100644
@@ -271,6 +271,8 @@ static int parse_color_moved(const char *arg)
 		return COLOR_MOVED_NO;
 	else if (!strcmp(arg, "plain"))
 		return COLOR_MOVED_PLAIN;
+	else if (!strcmp(arg, "blocks"))
+		return COLOR_MOVED_BLOCKS;
 	else if (!strcmp(arg, "zebra"))
 		return COLOR_MOVED_ZEBRA;
 	else if (!strcmp(arg, "default"))
@@ -278,7 +280,7 @@ static int parse_color_moved(const char *arg)
 	else if (!strcmp(arg, "dimmed_zebra"))
 		return COLOR_MOVED_ZEBRA_DIM;
 	else
-		return error(_("color moved setting must be one of 'no', 'default', 'zebra', 'dimmed_zebra', 'plain'"));
+		return error(_("color moved setting must be one of 'no', 'default', 'blocks', 'zebra', 'dimmed_zebra', 'plain'"));
 }
 
 int git_diff_ui_config(const char *var, const char *value, void *cb)
@@ -903,7 +905,7 @@ static void mark_color_as_moved(struct diff_options *o,
 
 		block_length++;
 
-		if (flipped_block)
+		if (flipped_block && o->color_moved != COLOR_MOVED_BLOCKS)
 			l->flags |= DIFF_SYMBOL_MOVED_LINE_ALT;
 	}
 	adjust_last_block(o, n, block_length);
diff.h +3 -2
index d29560f822..7bd4f182c3 100644
@@ -208,8 +208,9 @@ struct diff_options {
 	enum {
 		COLOR_MOVED_NO = 0,
 		COLOR_MOVED_PLAIN = 1,
-		COLOR_MOVED_ZEBRA = 2,
-		COLOR_MOVED_ZEBRA_DIM = 3,
+		COLOR_MOVED_BLOCKS = 2,
+		COLOR_MOVED_ZEBRA = 3,
+		COLOR_MOVED_ZEBRA_DIM = 4,
 	} color_moved;
 	#define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
 	#define COLOR_MOVED_MIN_ALNUM_COUNT 20
t/t4015-diff-whitespace.sh +47 -1

60 lines not on this page · raw message

Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#6 lore raw

Re: [PATCH 5/7] diff.c: add a blocks mode for moved code detection

Quoted 3 lines · On Tue, 24 Apr 2018 14:03:28 -0700 Stefan Beller <[email protected]> wrote:

(https://public-inbox.org/git/[email protected]/)

Firstly, I don't know if this is the right solution- as written in the linked e-mail [1], the issue might be more that the config conflates 2 unrelated things, not that a certain intersection is missing.

[1] https://public-inbox.org/git/[email protected]/

Optional: Probably better to put the link inline, instead of in the trailer.

t/t4015-diff-whitespace.sh test_expect_success 'detect permutations inside moved code -- dimmed_zebra' ' · line 1273

Quoted 9 lines
t/t4015-diff-whitespace.sh +1 -1
-test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
+test_expect_success 'detect blocks of moved code' '
 	git reset --hard &&
 	cat <<-\EOF >lines.txt &&
 		long line 1
@@ -1271,6 +1271,52 @@ test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
 	test_config color.diff.newMovedDimmed "normal cyan" &&
 	test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
 	test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&

Add a comment here explaining that these colors do not appear in the output, but merely set to recognizable values to ensure that they do not appear in the output.

Quoted 35 lines
t/t4015-diff-whitespace.sh +35 -0
+
+	git diff HEAD --no-renames --color-moved=blocks --color |
+		grep -v "index" |
+		test_decode_color >actual &&
+	cat <<-\EOF >expected &&
+	<BOLD>diff --git a/lines.txt b/lines.txt<RESET>
+	<BOLD>--- a/lines.txt<RESET>
+	<BOLD>+++ b/lines.txt<RESET>
+	<CYAN>@@ -1,16 +1,16 @@<RESET>
+	<MAGENTA>-long line 1<RESET>
+	<MAGENTA>-long line 2<RESET>
+	<MAGENTA>-long line 3<RESET>
+	 line 4<RESET>
+	 line 5<RESET>
+	 line 6<RESET>
+	 line 7<RESET>
+	 line 8<RESET>
+	 line 9<RESET>
+	<CYAN>+<RESET><CYAN>long line 1<RESET>
+	<CYAN>+<RESET><CYAN>long line 2<RESET>
+	<CYAN>+<RESET><CYAN>long line 3<RESET>
+	<CYAN>+<RESET><CYAN>long line 14<RESET>
+	<CYAN>+<RESET><CYAN>long line 15<RESET>
+	<CYAN>+<RESET><CYAN>long line 16<RESET>
+	 line 10<RESET>
+	 line 11<RESET>
+	 line 12<RESET>
+	 line 13<RESET>
+	<MAGENTA>-long line 14<RESET>
+	<MAGENTA>-long line 15<RESET>
+	<MAGENTA>-long line 16<RESET>
+	EOF
+	test_cmp expected actual
+
+'

[snip]

#7 lore raw

Re: [PATCH 5/7] diff.c: add a blocks mode for moved code detection

Quoted 11 lines · Jonathan Tan
Quoted 3 lines · On Tue, 24 Apr 2018 14:03:28 -0700 Stefan Beller <[email protected]> wrote:

(https://public-inbox.org/git/[email protected]/)

Firstly, I don't know if this is the right solution- as written in the linked e-mail [1], the issue might be more that the config conflates 2 unrelated things, not that a certain intersection is missing.

The "plain zebra" or as I call them "blocks", has the "heuristic for a minimum of 20 characters" and "few colors" as its defining features, which solves that use case.

Stepping back a bit, we have different "building blocks" at our disposal:
* move detection by line or block
* alternating blocks
* a heuristic to skip over small chunks (20 alnum chars)

These can be combined independently, so would you expect the user to expect two options for them? For example "--color-moved=zebra" could be split into "--skip-small --alternate-blocks"

Eventually we'll use various colors to inform the user what these building blocks made of the diff.

Quoted 4 lines · Ævar

Which is what I mean by the current config conflating two (to me) unrelated things. One is how we, via any method, detect what's moved or not, and the other is what color/format we use to present this to the user.

So instead of building blocks we rather want to split into algorithms and presentation layer?

The presentation layer would be things like:
* use a different color for moved things
* alternate colors for adjacent blocks
* paint border of a block (dimmed zebra)

The algorithm side would be
* detect moves
* detect moves as blocks
* skip small heuristic

Am I still missing the big picture?

Quoted 4 lines

[1] https://public-inbox.org/git/[email protected]/

Optional: Probably better to put the link inline, instead of in the trailer.

ok.

Quoted 14 lines

t/t4015-diff-whitespace.sh test_expect_success 'detect permutations inside moved code -- dimmed_zebra' ' · line 1273

Quoted 10 lines
t/t4015-diff-whitespace.sh +1 -1
-test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
+test_expect_success 'detect blocks of moved code' '
      git reset --hard &&
      cat <<-\EOF >lines.txt &&
              long line 1
@@ -1271,6 +1271,52 @@ test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
      test_config color.diff.newMovedDimmed "normal cyan" &&
      test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
      test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&

Add a comment here explaining that these colors do not appear in the output, but merely set to recognizable values to ensure that they do not appear in the output.

ok.

#8 lore raw

Re: [PATCH 5/7] diff.c: add a blocks mode for moved code detection

Quoted 4 lines · On Tue, 24 Apr 2018 15:37:51 -0700 Stefan Beller <[email protected]> wrote:

These can be combined independently, so would you expect the user to expect two options for them? For example "--color-moved=zebra" could be split into "--skip-small --alternate-blocks"

Yes, this is a good explanation. Reusing your terms below, --skip-small controls the algorithm, and --alternate-blocks controls the presentation layer.

Quoted 8 lines

So instead of building blocks we rather want to split into algorithms and presentation layer?

The presentation layer would be things like:
* use a different color for moved things
* alternate colors for adjacent blocks
* paint border of a block (dimmed zebra)

Quoted 4 lines

The algorithm side would be
* detect moves
* detect moves as blocks
* skip small heuristic

Yes.

This was just brainstorming, though - this might not be the direction we want to take in this patch. (The right solution might just be to always use blocks - thereby simplifying the algorithm aspect.)

#9 lore raw

PATCH v2 6/7 diff.c: decouple white space treatment from move detection algorithm

In reply to Stefan Beller

In the original implementation of the move detection logic the choice for ignoring white space changes is the same for the move detection as it is for the regular diff. Some cases came up where different treatment would have been nice.

Allow the user to specify that whitespace should be ignored differently during detection of moved lines than during generation of added and removed lines. This is done by providing analogs to the --ignore-space-at-eol, -b, and -w options (namely,
--color-moved-[no-]ignore-space-at-eol --color-moved-[no-]ignore-space-change --color-moved-[no-]ignore-all-space) that affect only the color of the
output, and making the existing --ignore-space-at-eol, -b, and -w options no longer affect the color of the output.

As we change the default, we'll adjust the tests.

For now we do not infer any options to treat whitespaces in the move detection from the generic white space options given to diff. This can be tuned later to reasonable default.

---
 Documentation/diff-options.txt | 13 +++++
 diff.c                         | 19 ++++++-
 diff.h                         |  1 +
 t/t4015-diff-whitespace.sh     | 90 +++++++++++++++++++++++++++++++---
 4 files changed, 114 insertions(+), 9 deletions(-)
Documentation/diff-options.txt +13 -0
index bb9f1b7cd8..7b2527b9a1 100644
@@ -292,6 +292,19 @@ dimmed_zebra::
 	blocks are considered interesting, the rest is uninteresting.
 --
 
+--color-moved-[no-]ignore-space-at-eol::
+	Ignore changes in whitespace at EOL when performing the move
+	detection for --color-moved.
+--color-moved-[no-]ignore-space-change::
+	Ignore changes in amount of whitespace when performing the move
+	detection for --color-moved.  This ignores whitespace
+	at line end, and considers all other sequences of one or
+	more whitespace characters to be equivalent.
+--color-moved-[no-]ignore-all-space::
+	Ignore whitespace when comparing lines when performing the move
+	detection for --color-moved.  This ignores differences even if
+	one line has whitespace where the other line has none.
+
 --word-diff[=<mode>]::
 	Show a word diff, using the <mode> to delimit changed words.
 	By default, words are delimited by whitespace; see
diff.c +17 -2
index 95c51c0b7d..b5819dd538 100644
@@ -717,10 +717,12 @@ static int moved_entry_cmp(const void *hashmap_cmp_fn_data,
 	const struct diff_options *diffopt = hashmap_cmp_fn_data;
 	const struct moved_entry *a = entry;
 	const struct moved_entry *b = entry_or_key;
+	unsigned flags = diffopt->color_moved_ws_handling
+			 & XDF_WHITESPACE_FLAGS;
 
 	return !xdiff_compare_lines(a->es->line, a->es->len,
 				    b->es->line, b->es->len,
-				    diffopt->xdl_opts);
+				    flags);
 }
 
 static struct moved_entry *prepare_entry(struct diff_options *o,
@@ -728,8 +730,9 @@ static struct moved_entry *prepare_entry(struct diff_options *o,
 {
 	struct moved_entry *ret = xmalloc(sizeof(*ret));
 	struct emitted_diff_symbol *l = &o->emitted_symbols->buf[line_no];
+	unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;
 
-	ret->ent.hash = xdiff_hash_string(l->line, l->len, o->xdl_opts);
+	ret->ent.hash = xdiff_hash_string(l->line, l->len, flags);
 	ret->es = l;
 	ret->next_line = NULL;
 
@@ -4638,6 +4641,18 @@ int diff_opt_parse(struct diff_options *options,
 		DIFF_XDL_SET(options, IGNORE_CR_AT_EOL);
 	else if (!strcmp(arg, "--ignore-blank-lines"))
 		DIFF_XDL_SET(options, IGNORE_BLANK_LINES);
+	else if (!strcmp(arg, "--color-moved-no-ignore-all-space"))
+		options->color_moved_ws_handling &= ~XDF_IGNORE_WHITESPACE;
+	else if (!strcmp(arg, "--color-moved-no-ignore-space-change"))
+		options->color_moved_ws_handling &= ~XDF_IGNORE_WHITESPACE_CHANGE;
+	else if (!strcmp(arg, "--color-moved-no-ignore-space-at-eol"))
+		options->color_moved_ws_handling &= ~XDF_IGNORE_WHITESPACE_AT_EOL;
+	else if (!strcmp(arg, "--color-moved-ignore-all-space"))
+		options->color_moved_ws_handling |= XDF_IGNORE_WHITESPACE;
+	else if (!strcmp(arg, "--color-moved-ignore-space-change"))
+		options->color_moved_ws_handling |= XDF_IGNORE_WHITESPACE_CHANGE;
+	else if (!strcmp(arg, "--color-moved-ignore-space-at-eol"))
+		options->color_moved_ws_handling |= XDF_IGNORE_WHITESPACE_AT_EOL;
 	else if (!strcmp(arg, "--indent-heuristic"))
 		DIFF_XDL_SET(options, INDENT_HEURISTIC);
 	else if (!strcmp(arg, "--no-indent-heuristic"))
diff.h +1 -0
index 7bd4f182c3..de5dc68005 100644
@@ -214,6 +214,7 @@ struct diff_options {
 	} color_moved;
 	#define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
 	#define COLOR_MOVED_MIN_ALNUM_COUNT 20
+	int color_moved_ws_handling;
 };
 
 void diff_emit_submodule_del(struct diff_options *o, const char *line);
t/t4015-diff-whitespace.sh +83 -7

132 lines not on this page · raw message

Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#10 lore raw

Re: [PATCH 6/7] diff.c: decouple white space treatment from move detection algorithm

Quoted 1 line · On Tue, 24 Apr 2018 14:03:29 -0700 Stefan Beller <[email protected]> wrote:

As we change the default, we'll adjust the tests.

This statement is probably better written as:

In some existing tests, options like --ignore-space-at-eol were used to control the color of the output. They have been updated to use options like --color-moved-ignore-space-at-eol instead.

diff.c static int moved_entry_cmp(const void *hashmap_cmp_fn_data, · line 721

Quoted 2 lines
diff.c +2 -0
+	unsigned flags = diffopt->color_moved_ws_handling
+			 & XDF_WHITESPACE_FLAGS;

No need for "& XDF_WHITESPACE_FLAGS".

diff.c static struct moved_entry *prepare_entry(struct diff_options *o, · line 733

Quoted 1 line
diff.c +1 -0
+	unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;

Same here.

diff.h struct diff_options { · line 218

Quoted 6 lines
diff.h +1 -0
@@ -214,6 +214,7 @@ struct diff_options {
 	} color_moved;
 	#define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
 	#define COLOR_MOVED_MIN_ALNUM_COUNT 20
+	int color_moved_ws_handling;
 };

Should the "int" be "unsigned"? I noticed that the flag-like xdl_opts is signed, but I think it's better for flags to be unsigned. Also, document what this stores. (And also, I would limit the bits.)

Quoted 45 lines
t/t4015-diff-whitespace.sh +45 -0
+test_expect_success 'only move detection ignores white spaces' '
+	git reset --hard &&
+	q_to_tab <<-\EOF >text.txt &&
+		a long line to exceed per-line minimum
+		another long line to exceed per-line minimum
+		original file
+	EOF
+	git add text.txt &&
+	git commit -m "add text" &&
+	q_to_tab <<-\EOF >text.txt &&
+		Qa long line to exceed per-line minimum
+		Qanother long line to exceed per-line minimum
+		new file
+	EOF
+
+	# Make sure we get a different diff using -w
+	git diff --color --color-moved -w \
+		--color-moved-no-ignore-all-space \
+		--color-moved-no-ignore-space-change \
+		--color-moved-no-ignore-space-at-eol |
+		grep -v "index" |
+		test_decode_color >actual &&
+	q_to_tab <<-\EOF >expected &&
+	<BOLD>diff --git a/text.txt b/text.txt<RESET>
+	<BOLD>--- a/text.txt<RESET>
+	<BOLD>+++ b/text.txt<RESET>
+	<CYAN>@@ -1,3 +1,3 @@<RESET>
+	 Qa long line to exceed per-line minimum<RESET>
+	 Qanother long line to exceed per-line minimum<RESET>
+	<RED>-original file<RESET>
+	<GREEN>+<RESET><GREEN>new file<RESET>
+	EOF
+	test_cmp expected actual &&
+
+	# And now ignoring white space only in the move detection
+	git diff --color --color-moved \
+		--color-moved-ignore-all-space \
+		--color-moved-ignore-space-change \
+		--color-moved-ignore-space-at-eol |
+		grep -v "index" |
+		test_decode_color >actual &&
+	q_to_tab <<-\EOF >expected &&
+	<BOLD>diff --git a/text.txt b/text.txt<RESET>
+	<BOLD>--- a/text.txt<RESET>
+	<BOLD>+++ b/text.txt<RESET>

t/t4015-diff-whitespace.sh test_expect_success 'move detection with submodules' ' · line 1848

Quoted 10 lines
t/t4015-diff-whitespace.sh +9 -0
+	<CYAN>@@ -1,3 +1,3 @@<RESET>
+	<BOLD;MAGENTA>-a long line to exceed per-line minimum<RESET>
+	<BOLD;MAGENTA>-another long line to exceed per-line minimum<RESET>
+	<RED>-original file<RESET>
+	<BOLD;YELLOW>+<RESET>Q<BOLD;YELLOW>a long line to exceed per-line minimum<RESET>
+	<BOLD;YELLOW>+<RESET>Q<BOLD;YELLOW>another long line to exceed per-line minimum<RESET>
+	<GREEN>+<RESET><GREEN>new file<RESET>
+	EOF
+	test_cmp expected actual
 '

I know I suggested "per-line minimum", but I don't think there is one - I think we only have a per-block minimum. Maybe delete "per-line" in each of the lines.

#11 lore raw

Re: [PATCH 6/7] diff.c: decouple white space treatment from move detection algorithm

Hi Jonathan,

Quoted 10 lines · Jonathan Tan
Quoted 1 line · On Tue, 24 Apr 2018 14:03:29 -0700 Stefan Beller <[email protected]> wrote:

As we change the default, we'll adjust the tests.

This statement is probably better written as:

In some existing tests, options like --ignore-space-at-eol were used to control the color of the output. They have been updated to use options like --color-moved-ignore-space-at-eol instead.

I'll adjust that statement; thanks for helping me out with good commit messages (even the "As we change the defaults, .." was proposed by you in a previous round)

Quoted 5 lines

diff.c static int moved_entry_cmp(const void *hashmap_cmp_fn_data, · line 721

Quoted 3 lines
diff.c +2 -0
+     unsigned flags = diffopt->color_moved_ws_handling
+                      & XDF_WHITESPACE_FLAGS;

No need for "& XDF_WHITESPACE_FLAGS".

This is in anticipation of the next commit, when
color_moved_ws_handling takes more flags.
I can move that over to the last commit.

Quoted 4 lines
Quoted 2 lines

+ unsigned flags = o->color_moved_ws_handling & XDF_WHITESPACE_FLAGS;

Same here.

Maybe I'll just state in the commit message why we keep the masking here.

Quoted 9 lines

diff.h struct diff_options { · line 218

Quoted 7 lines
diff.h +1 -0
@@ -214,6 +214,7 @@ struct diff_options {
      } color_moved;
      #define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
      #define COLOR_MOVED_MIN_ALNUM_COUNT 20
+     int color_moved_ws_handling;
 };

Should the "int" be "unsigned"?

yes.

Quoted 2 lines

I noticed that the flag-like xdl_opts is
signed, but I think it's better for flags to be unsigned.

I can change those, too.

Quoted 2 lines

Also, document
what this stores.

ok, will document.

Quoted 1 line

(And also, I would limit the bits.)

Not sure I follow. you want to make it e.g.

unsigned color_moved_ws_handling : 6;

?

Oh, that would actually work, as XDF_WHITESPACE_FLAGS are in second to fifth bits.

But then we need to document why the XDF_WHITESPACE need to be at these low positions.

Quoted 9 lines

t/t4015-diff-whitespace.sh test_expect_success 'move detection with submodules' ' · line 1806

Quoted 4 lines
t/t4015-diff-whitespace.sh +4 -0
+     q_to_tab <<-\EOF >text.txt &&
+             Qa long line to exceed per-line minimum
+             Qanother long line to exceed per-line minimum
+             new file

I know I suggested "per-line minimum", but I don't think there is one - I think we only have a per-block minimum. Maybe delete "per-line" in each of the lines.

yeah, I guess this heuristic could also make for another setting, though as of now I did not desire any other heuristic than you originally came up with. Will reword the text. Thanks!

Thanks,
Stefan

#12 lore raw

PATCH v2 7/7 diff.c: add --color-moved-ignore-space-delta option

In reply to Stefan Beller

This marks moved code still as blocks when their indentation level changes uniformly.

---
 Documentation/diff-options.txt |  4 ++
 diff.c                         | 83 +++++++++++++++++++++++++++++++---
 diff.h                         |  2 +
 t/t4015-diff-whitespace.sh     | 54 ++++++++++++++++++++++
 4 files changed, 137 insertions(+), 6 deletions(-)
Documentation/diff-options.txt +4 -0
index 7b2527b9a1..facdbc8f95 100644
@@ -304,6 +304,10 @@ dimmed_zebra::
 	Ignore whitespace when comparing lines when performing the move
 	detection for --color-moved.  This ignores differences even if
 	one line has whitespace where the other line has none.
+--color-moved-[no-]ignore-space-prefix-delta::
+	Ignores whitespace when comparing lines when performing the move
+	detection for --color-moved. This ignores uniform differences
+	of white space at the beginning lines in moved blocks.
 
 --word-diff[=<mode>]::
 	Show a word diff, using the <mode> to delimit changed words.
diff.c +77 -6

154 lines not on this page · raw message

diff.h +2 -0
index de5dc68005..b00ea76c08 100644
@@ -214,6 +214,8 @@ struct diff_options {
 	} color_moved;
 	#define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
 	#define COLOR_MOVED_MIN_ALNUM_COUNT 20
+	/* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
+	#define COLOR_MOVED_DELTA_WHITESPACES	(1 << 22)
 	int color_moved_ws_handling;
 };
 
t/t4015-diff-whitespace.sh +54 -0

58 lines not on this page · raw message

Signature · 1 line
2.17.0.441.gb46fe60e1d-goog
#13 lore raw

Re: [PATCH 7/7] diff.c: add --color-moved-ignore-space-delta option

Documentation/diff-options.txt dimmed_zebra:: · line 310

Quoted 4 lines · On Tue, 24 Apr 2018 14:03:30 -0700 Stefan Beller <[email protected]> wrote:

+--color-moved-[no-]ignore-space-prefix-delta::

Documentation/diff-options.txt +3 -0
+	Ignores whitespace when comparing lines when performing the move
+	detection for --color-moved. This ignores uniform differences
+	of white space at the beginning lines in moved blocks.

Setting this option means that moved lines may be indented or dedented, and if they have been indented or dedented by the same amount, they are still considered to be the same block. Maybe call this --color-moved-allow-indentation-change.

diff.c struct moved_entry { · line 713

Quoted 2 lines
diff.c +2 -0
+struct ws_delta {
+	char *string; /* The prefix delta, which is the same in the block */

Probably better described as "the difference between the '-' line and the '+' line". This may be the empty string if there is no difference.

diff.c struct moved_entry { · line 714

Quoted 1 line
diff.c +1 -0
+	int direction; /* adding or removing the line? */

What is the value when "added" and what when "removed"? Also, it is not truly "added" or "removed", so a better way might be: 1 if the '-' line is longer than the '+' line, and 0 otherwise. (And make sure that the documentation is correct with respect to equal lines.)

diff.c struct moved_entry { · line 715

Quoted 1 line
diff.c +1 -0
+	int missmatch; /* in the remainder */

s/missmatch/mismatch/
Also, what is this used for?

diff.c static int moved_entry_cmp(const void *hashmap_cmp_fn_data, · line 759

Quoted 12 lines
diff.c +9 -0
+	if (diffopt->color_moved_ws_handling & COLOR_MOVED_DELTA_WHITESPACES)
+		/*
+		 * As there is not specific white space config given,
+		 * we'd need to check for a new block, so ignore all
+		 * white space. The setup of the white space
+		 * configuration for the next block is done else where
+		 */
+		flags |= XDF_IGNORE_WHITESPACE;
+
 	return !xdiff_compare_lines(a->es->line, a->es->len,
 				    b->es->line, b->es->len,
 				    flags);

I wrote in [1]:

I think we should just prohibit combining this with any of the whitespace ignoring flags except for the space-at-eol one. They seem to contradict anyway.

To elaborate, adding a specific flag that may interfere with other user-provided flags sounds like we're unnecessarily adding combinations that we must keep track of, and that it's both logical (from a user's point of view) and clearer (as for the code) to just forbid such combinations.

[1] https://public-inbox.org/git/[email protected]/

diff.c static void mark_color_as_moved(struct diff_options *o, · line 883

Quoted 8 lines
diff.c +4 -1
 	struct moved_entry **pmb = NULL; /* potentially moved blocks */
 	int pmb_nr = 0, pmb_alloc = 0;
-	int n, flipped_block = 1, block_length = 0;
 
+	struct ws_delta *wsd = NULL; /* white space deltas between pmb */
+	int wsd_alloc = 0;
+
+	int n, flipped_block = 1, block_length = 0;

It seems like pmb and wsd are parallel arrays - could each wsd be embedded into the corresponding entry of pmb instead?

diff.h struct diff_options { · line 220

Quoted 10 lines
diff.h +2 -0
@@ -214,6 +214,8 @@ struct diff_options {
 	} color_moved;
 	#define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
 	#define COLOR_MOVED_MIN_ALNUM_COUNT 20
+	/* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
+	#define COLOR_MOVED_DELTA_WHITESPACES	(1 << 22)
 	int color_moved_ws_handling;
 };

Setting of DELTA_WHITESPACES should be a separate field, not as part of ws_handling. It's fine for the ws_handling to be a bitset, since that's how it's passed to xdiff_compare_lines(), but we don't need to do the same for DELTA_WHITESPACES.

Quoted 43 lines
diff.h +43 -0
+test_expect_success 'compare whitespace delta across moved blocks' '
+
+	git reset --hard &&
+	q_to_tab <<-\EOF >text.txt &&
+	QIndented
+	QText across
+	Qthree lines
+	QBut! <- this stands out
+	Qthis one
+	QQline did
+	Qnot adjust
+	EOF
+
+	git add text.txt &&
+	git commit -m "add text.txt" &&
+
+	q_to_tab <<-\EOF >text.txt &&
+	QQIndented
+	QQText across
+	QQthree lines
+	QQQBut! <- this stands out
+	this one
+	Qline did
+	not adjust
+	EOF
+
+	git diff --color --color-moved-ignore-space-prefix-delta |
+		grep -v "index" |
+		test_decode_color >actual &&
+
+	q_to_tab <<-\EOF >expected &&
+		<BOLD>diff --git a/text.txt b/text.txt<RESET>
+		<BOLD>--- a/text.txt<RESET>
+		<BOLD>+++ b/text.txt<RESET>
+		<CYAN>@@ -1,7 +1,7 @@<RESET>
+		<RED>-QIndented<RESET>
+		<RED>-QText across<RESET>
+		<RED>-Qthree lines<RESET>
+		<RED>-QBut! <- this stands out<RESET>
+		<RED>-Qthis one<RESET>
+		<RED>-QQline did<RESET>
+		<RED>-Qnot adjust<RESET>
+		<GREEN>+<RESET>QQ<GREEN>Indented<RESET>

diff.h struct diff_options {

Quoted 10 lines
diff.h +10 -0
+		<GREEN>+<RESET>QQ<GREEN>Text across<RESET>
+		<GREEN>+<RESET>QQ<GREEN>three lines<RESET>
+		<GREEN>+<RESET>QQQ<GREEN>But! <- this stands out<RESET>
+		<GREEN>+<RESET><GREEN>this one<RESET>
+		<GREEN>+<RESET>Q<GREEN>line did<RESET>
+		<GREEN>+<RESET><GREEN>not adjust<RESET>
+	EOF
+
+	test_cmp expected actual
+'

I would have expected every line except the "this stands out" line to be colored differently than the usual RED and GREEN. Is this test output expected?

A message that is not in the archive (sent off-list or not yet received): CAGZ79kbGkHFSS9K8KKTwNikx3Tw+m+RMLY3RAf8SW_iK9a2OJQ@mail.gmail.com

#15 lore raw

Re: [PATCH 7/7] diff.c: add --color-moved-ignore-space-delta option

Replied to Jonathan only instead of all. My reply is below:

Quoted 181 lines · Stefan Beller
Quoted 8 lines · Jonathan Tan

Documentation/diff-options.txt dimmed_zebra:: · line 310

Quoted 4 lines · On Tue, 24 Apr 2018 14:03:30 -0700 Stefan Beller <[email protected]> wrote:

+--color-moved-[no-]ignore-space-prefix-delta::

Documentation/diff-options.txt +3 -0
+     Ignores whitespace when comparing lines when performing the move
+     detection for --color-moved. This ignores uniform differences
+     of white space at the beginning lines in moved blocks.
Quoted 4 lines

Setting this option means that moved lines may be indented or dedented, and if they have been indented or dedented by the same amount, they are still considered to be the same block. Maybe call this --color-moved-allow-indentation-change.

ok, sounds good as well. I tried coming up with a name that refers to the block check as that is the important part.

Quoted 5 lines

diff.c struct moved_entry { · line 713

Quoted 2 lines
diff.c +2 -0
+struct ws_delta {
+     char *string; /* The prefix delta, which is the same in the block */

Probably better described as "the difference between the '-' line and the '+' line". This may be the empty string if there is no difference.

Makes sense.

Quoted 8 lines
Quoted 2 lines

+ int direction; /* adding or removing the line? */

What is the value when "added" and what when "removed"? Also, it is not truly "added" or "removed", so a better way might be: 1 if the '-' line is longer than the '+' line, and 0 otherwise. (And make sure that the documentation is correct with respect to equal lines.)

Quoted 4 lines
Quoted 1 line

+ int missmatch; /* in the remainder */

s/missmatch/mismatch/
Also, what is this used for?

The mismatch should be used for (thanks for catching!) checking if the remainder of a line is the same, although a boolean may be not the correct choice. We know that the two strings passed into compute_ws_delta come from a complete white space agnostic comparison, so consider:

+ SP SP more TAB more
+ SP SP text TAB text

- SP more TAB more
- SP text TAB text

which would mark this as a moved block. This is the feature working as intended, but what about

+ SP SP more TAB more
+ SP SP text TAB text

- SP more SP more
- SP text TAB text

Note how the length of the strings is the same, hence the current code of

    compute_ws_delta(...) {
        int d = longer->len - shorter->len;
        out->string = xmemdupz(longer->line, d);
    }

would work fine and not notice the "change in the remainder". That ought to be caught by the mismatch variable, that is assigned, but not used.

The compare_ws_delta(a, b) needs to be extended to

  !a->mismatch && !b->mismatch && existing_condition

Ideally the example from above would be different depending on whether the other white space flags are given or not.

Quoted 13 lines

diff.c static int moved_entry_cmp(const void *hashmap_cmp_fn_data, · line 759

Quoted 12 lines
diff.c +9 -0
+     if (diffopt->color_moved_ws_handling & COLOR_MOVED_DELTA_WHITESPACES)
+             /*
+              * As there is not specific white space config given,
+              * we'd need to check for a new block, so ignore all
+              * white space. The setup of the white space
+              * configuration for the next block is done else where
+              */
+             flags |= XDF_IGNORE_WHITESPACE;
+
      return !xdiff_compare_lines(a->es->line, a->es->len,
                                  b->es->line, b->es->len,
                                  flags);
Quoted 5 lines

I wrote in [1]:

I think we should just prohibit combining this with any of the whitespace ignoring flags except for the space-at-eol one. They seem to contradict anyway.

As outlined above, I think there are corner cases in which they do not contradict. So I think the COLOR_MOVED_DELTA_WHITESPACES will go into its own variable, and then we can solve the corner cases correctly.

Quoted 5 lines

To elaborate, adding a specific flag that may interfere with other user-provided flags sounds like we're unnecessarily adding combinations that we must keep track of, and that it's both logical (from a user's point of view) and clearer (as for the code) to just forbid such combinations.

Yes, I think you mentioned this before. Thanks for reminding!

Quoted 7 lines

diff.c static void mark_color_as_moved(struct diff_options *o, · line 883

Quoted 4 lines
diff.c +4 -0
+     struct ws_delta *wsd = NULL; /* white space deltas between pmb */
+     int wsd_alloc = 0;
+
+     int n, flipped_block = 1, block_length = 0;

It seems like pmb and wsd are parallel arrays - could each wsd be embedded into the corresponding entry of pmb instead?

I'll explore that. It sounds like a good idea for code hygiene. Although if you do not intend to use this feature, then keeping it separate would allow for a smaller footprint in memory.

Quoted 16 lines

diff.h struct diff_options { · line 220

Quoted 11 lines
diff.h +2 -0
@@ -214,6 +214,8 @@ struct diff_options {
      } color_moved;
      #define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
      #define COLOR_MOVED_MIN_ALNUM_COUNT 20
+     /* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
+     #define COLOR_MOVED_DELTA_WHITESPACES   (1 << 22)
      int color_moved_ws_handling;
 };

Setting of DELTA_WHITESPACES should be a separate field, not as part of ws_handling. It's fine for the ws_handling to be a bitset, since that's how it's passed to xdiff_compare_lines(), but we don't need to do the same for DELTA_WHITESPACES.

You are correct. Thanks for your patience in this series!

Quoted 28 lines
t/t4015-diff-whitespace.sh +3 -0
+     git diff --color --color-moved-ignore-space-prefix-delta |
+             grep -v "index" |
+             test_decode_color >actual &&
Quoted 14 lines
diff.h +13 -0
+     q_to_tab <<-\EOF >expected &&
+             <BOLD>diff --git a/text.txt b/text.txt<RESET>
+             <BOLD>--- a/text.txt<RESET>
+             <BOLD>+++ b/text.txt<RESET>
+             <CYAN>@@ -1,7 +1,7 @@<RESET>
+             <RED>-QIndented<RESET>
+             <RED>-QText across<RESET>
+             <RED>-Qthree lines<RESET>
+             <RED>-QBut! <- this stands out<RESET>
+             <RED>-Qthis one<RESET>
+             <RED>-QQline did<RESET>
+             <RED>-Qnot adjust<RESET>
+             <GREEN>+<RESET>QQ<GREEN>Indented<RESET>

diff.h struct diff_options {

Quoted 10 lines
diff.h +10 -0
+             <GREEN>+<RESET>QQ<GREEN>Text across<RESET>
+             <GREEN>+<RESET>QQ<GREEN>three lines<RESET>
+             <GREEN>+<RESET>QQQ<GREEN>But! <- this stands out<RESET>
+             <GREEN>+<RESET><GREEN>this one<RESET>
+             <GREEN>+<RESET>Q<GREEN>line did<RESET>
+             <GREEN>+<RESET><GREEN>not adjust<RESET>
+     EOF
+
+     test_cmp expected actual
+'
Quoted 3 lines

I would have expected every line except the "this stands out" line to be colored differently than the usual RED and GREEN. Is this test output expected?

It is wrong indeed. I blindly copied the actual file once interactive testing confirmed it worked.

The command is missing a --color-moved, as the --color-moved-whitespace-settings do not imply --color-moved, yet(?)

Thanks,
Stefan

#16 lore raw

Re: [PATCH 7/7] diff.c: add --color-moved-ignore-space-delta option

Quoted 36 lines · On Tue, 24 Apr 2018 16:23:28 -0700 Stefan Beller <[email protected]> wrote:
Quoted 36 lines
Quoted 2 lines

s/missmatch/mismatch/
Also, what is this used for?

The mismatch should be used for (thanks for catching!) checking if the remainder of a line is the same, although a boolean may be not the correct choice. We know that the two strings passed into compute_ws_delta come from a complete white space agnostic comparison, so consider:

+ SP SP more TAB more
+ SP SP text TAB text

- SP more TAB more
- SP text TAB text

which would mark this as a moved block. This is the feature working as intended, but what about

+ SP SP more TAB more
+ SP SP text TAB text

- SP more SP more
- SP text TAB text

Note how the length of the strings is the same, hence the current code of

    compute_ws_delta(...) {
        int d = longer->len - shorter->len;
        out->string = xmemdupz(longer->line, d);
    }

would work fine and not notice the "change in the remainder". That ought to be caught by the mismatch variable, that is assigned, but not used.

Quoted 6 lines
Quoted 6 lines

The compare_ws_delta(a, b) needs to be extended to

  !a->mismatch && !b->mismatch && existing_condition

Ideally the example from above would be different depending on whether the other white space flags are given or not.

Thanks - this gives me food for thought.

I'm starting to think that it is impossible to avoid creating our own string comparison function that:
- seeks to the first non-whitespace character in both strings
- checks that both strings, from that first non-whitespace characters, are equal for some definition of equal (whether through strcmp or xdiff_compare_lines)
- walks backwards from that first non-whitespace characters to look for the first non-matching whitespace character between the 2 strings

The existing diff whitespace modes (to be passed to xdiff_compare_lines) do not give the exact result we want. For example, if XDF_IGNORE_WHITESPACE is used (as is in this patch), lines like "a b" and "ab " would match even though they shouldn't.

This comparison function can be used both in moved_entry_cmp() and when constructing the ws_delta (in which case it should be made to output whatever information is needed as out parameters or similar).

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
diff.c +4 -0
+     if (diffopt->color_moved_ws_handling & COLOR_MOVED_DELTA_WHITESPACES)
+             /*
+              * As there is not specific white space config given,
+              * we'd need to check for a new block, so ignore all
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

diff.c static int moved_entry_cmp(const void *hashmap_cmp_fn_data, · line 759

Quoted 8 lines
diff.c +5 -0
+              * white space. The setup of the white space
+              * configuration for the next block is done else where
+              */
+             flags |= XDF_IGNORE_WHITESPACE;
+
      return !xdiff_compare_lines(a->es->line, a->es->len,
                                  b->es->line, b->es->len,
                                  flags);

We can't add XDF_IGNORE_WHITESPACE here - as far as I can tell, this means that more lines will be treated as moved than the user wants (if the user did not set --color-moved-ignore-all-space).

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

It seems like pmb and wsd are parallel arrays - could each wsd be embedded into the corresponding entry of pmb instead?

I'll explore that. It sounds like a good idea for code hygiene. Although if you do not intend to use this feature, then keeping it separate would allow for a smaller footprint in memory.

If you're worried about memory, wsd can be embedded as a pointer.

Quoted 2 lines
Quoted 2 lines

The command is missing a --color-moved, as the --color-moved-whitespace-settings do not imply --color-moved, yet(?)

Maybe one should imply the other (or at least a warning).

#17 lore raw
In reply to Stefan Beller
Quoted 6 lines · On Tue, 24 Apr 2018 14:03:23 -0700 Stefan Beller <[email protected]> wrote:

v2:
I think I have addressed Jonathans feedback
* by using a string instead of counting the first character only.
* refined tests slightly (easier to read)
* moved white space handling for moved blocks into its own flag field, keeping the enum for the actual mode of move detection.

For reference, v1 is here:
https://public-inbox.org/git/[email protected]/

Quoted 8 lines

Stefan Beller (7):
xdiff/xdiff.h: remove unused flags
xdiff/xdiffi.c: remove unneeded function declarations diff.c: do not pass diff options as keydata to hashmap diff.c: adjust hash function signature to match hashmap expectation diff.c: add a blocks mode for moved code detection diff.c: decouple white space treatment from move detection algorithm diff.c: add --color-moved-ignore-space-delta option

I'm not sure if we should add a new "blocks" mode, or if we should modify the existing plain mode to have the minimum block length instead. I reviewed the code as if we want the new "blocks" mode.

#18 lore raw
Quoted 22 lines · Jonathan Tan
Quoted 6 lines · On Tue, 24 Apr 2018 14:03:23 -0700 Stefan Beller <[email protected]> wrote:

v2:
I think I have addressed Jonathans feedback
* by using a string instead of counting the first character only.
* refined tests slightly (easier to read)
* moved white space handling for moved blocks into its own flag field, keeping the enum for the actual mode of move detection.

For reference, v1 is here:
https://public-inbox.org/git/[email protected]/

Quoted 8 lines

Stefan Beller (7):
xdiff/xdiff.h: remove unused flags
xdiff/xdiffi.c: remove unneeded function declarations diff.c: do not pass diff options as keydata to hashmap diff.c: adjust hash function signature to match hashmap expectation diff.c: add a blocks mode for moved code detection diff.c: decouple white space treatment from move detection algorithm diff.c: add --color-moved-ignore-space-delta option

Quoted 3 lines

I'm not sure if we should add a new "blocks" mode, or if we should modify the existing plain mode to have the minimum block length instead. I reviewed the code as if we want the new "blocks" mode.

Thanks for the review!

I think keeping plain is useful, see 176841f0c9 (diff.c: color moved lines differently, plain mode, 2017-06-30)

diff.c: color moved lines differently, plain mode

Add the 'plain' mode for move detection of code. This omits the checking for adjacent blocks, so it is not as useful. If you have a lot of the same blocks moved in the same patch, the 'Zebra' would end up slow as it is O(n^2) (n is number of same blocks). So this may be useful there and is generally easy to add. Instead be very literal at the move detection, do not skip over short blocks here.

Although if we do not care about that use case we can just add heuristics to plain.

As eluded to in Ævars email, we might want to break it up into multiple options as well?