threads / patch / 33056

patchAllow combined diff to ignore white-spaces

Subject: [PATCH] Allow combined diff to ignore white-spaces

## tl;dr

13 messages between Mar 2, 2013 and Mar 14, 2013. Diffs are folded; open one to read it.

replies: 12people: 3as markdown or json

Antoine Pelisse· Mar 2, 2013, 15:04 UTC · lore

Currently, it's not possible to use the space-ignoring options (-b, -w, --ignore-space-at-eol) with combined diff. It makes it pretty impossible to read a merge between a branch that changed all tabs to spaces, and a branch with functional changes.

Pass diff flags to diff engine, so that combined diff behaves as normal diff does with spaces.

It also means that a conflict-less merge done using a ignore-* strategy option will not show any conflict if shown in combined-diff using the same option.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
That should be reviewed carefully as I'm not exactly sure that does make
sense with the way combined-diff works.
Still it seems natural to me to be able to remove the space in combined
diff as we do with normal diff. Especially as I unfortunately have to
deal with many space + feature merges that are very hard to analyze/handle
if space differences can't be hidden.

Cheers, Antoine

 combine-diff.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Show changes to combine-diff.c +3 −4
diff --git a/combine-diff.c b/combine-diff.c
index 35d41cd..7ca0a72 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -215,7 +215,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
 			 struct sline *sline, unsigned int cnt, int n,
 			 int num_parent, int result_deleted,
 			 struct userdiff_driver *textconv,
-			 const char *path)
+			 const char *path, long flags)
 {
 	unsigned int p_lno, lno;
 	unsigned long nmask = (1UL << n);
@@ -231,7 +231,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
 	parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
 	parent_file.size = sz;
 	memset(&xpp, 0, sizeof(xpp));
-	xpp.flags = 0;
+	xpp.flags = flags;
 	memset(&xecfg, 0, sizeof(xecfg));
 	memset(&state, 0, sizeof(state));
 	state.nmask = nmask;
@@ -962,7 +962,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 				     elem->parent[i].mode,
 				     &result_file, sline,
 				     cnt, i, num_parent, result_deleted,
-				     textconv, elem->path);
+				     textconv, elem->path, opt->xdl_opts);
 	}

 	show_hunks = make_hunks(sline, cnt, num_parent, dense);
--
1.7.9.5
Junio C Hamano· Mar 3, 2013, 07:45 UTC · re: Antoine Pelisse · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

Antoine Pelisse <apelisse@gmail.com> writes:
Show 20 quoted lines
> Currently, it's not possible to use the space-ignoring options (-b, -w,
> --ignore-space-at-eol) with combined diff. It makes it pretty impossible
> to read a merge between a branch that changed all tabs to spaces, and a
> branch with functional changes.
>
> Pass diff flags to diff engine, so that combined diff behaves as normal
> diff does with spaces.
>
> It also means that a conflict-less merge done using a ignore-* strategy
> option will not show any conflict if shown in combined-diff using the
> same option.
>
> Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
> ---
> That should be reviewed carefully as I'm not exactly sure that does make
> sense with the way combined-diff works.
> Still it seems natural to me to be able to remove the space in combined
> diff as we do with normal diff. Especially as I unfortunately have to
> deal with many space + feature merges that are very hard to analyze/handle
> if space differences can't be hidden.

Assuming "That" at the beginning of the off-line comment refers to "this patch", I actually I do not think this patch needs to be reviewed carefully at all.

The change in your patch to make the internal pairwise diff to ignore whitespaces is an obvious and a sensible first step for your stated goal. With it, a block of lines where the postimage makes no change other than whitespace changes from one parent and matches with the other parent will see no hunks in either of the pair-wise diff, and such a hunk will not appear in the final output, which is exactly what you want.

What needs to be audited carefully is the part of combine diff logic that this patch does *not* touch.

An example. After collecting pairwise diffs between the shared postimage and individual parents, we align the hunks and coalesce "identical" preimage lines to form shared "-" (removed) lines. I think that step is done with byte-for-byte comparison. If the postimage removes a line from one parent and a corresponding line from another parent, and if these corresponding lines in the parents differ only by whitespaces in a way the user told us to ignore with -b/-w/etc., you would need to tweak the logic to coalesce corresponding "lost" lines in the append_lost() function. Otherwise, you will see two " -" and "- " lines that remove these corresponding lines from the parents that are identical when you ignore whitespaces.

You should add some tests; it would help you think about these issues through.

For example, in this history:
       git init
       seq 11 >ten
       git add ten
       git commit -m initial
       seq 10 | sed -e 's/6/6 six/' -e 's/2/2 two/' >ten
       echo 11 >>ten
       git commit -m ten -a
       git checkout -b side HEAD^
       seq 10 | sed -e 's/^/  /' | sed -e 's/2/2 dos/' >ten
       echo 11 >>ten
       git commit -m indent -a
       git merge master
       seq 10 | sed -e 's/5/5 go/' -e 's/2/2 dois/' >ten
       git commit -m merged -a

one side indents the original and tweaks some lines, while the other side tweaks some other lines without reindenting. Most notably, the fifth line on one side is "5" while on the other side is " 5", and this line is rewritten to "5 go" in the final. The lost lines are not coalesced to a single "-- 5" (nor "-- 5") but shows that two preimages were different only by whitespaces. Compare that with what happens to the final line "11" that gets lost in the result.

Thanks.
Show 39 quoted lines
> Cheers,
> Antoine
>
>  combine-diff.c |    6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/combine-diff.c b/combine-diff.c
> index 35d41cd..7ca0a72 100644
> --- a/combine-diff.c
> +++ b/combine-diff.c
> @@ -215,7 +215,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
>  			 struct sline *sline, unsigned int cnt, int n,
>  			 int num_parent, int result_deleted,
>  			 struct userdiff_driver *textconv,
> -			 const char *path)
> +			 const char *path, long flags)
>  {
>  	unsigned int p_lno, lno;
>  	unsigned long nmask = (1UL << n);
> @@ -231,7 +231,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
>  	parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
>  	parent_file.size = sz;
>  	memset(&xpp, 0, sizeof(xpp));
> -	xpp.flags = 0;
> +	xpp.flags = flags;
>  	memset(&xecfg, 0, sizeof(xecfg));
>  	memset(&state, 0, sizeof(state));
>  	state.nmask = nmask;
> @@ -962,7 +962,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
>  				     elem->parent[i].mode,
>  				     &result_file, sline,
>  				     cnt, i, num_parent, result_deleted,
> -				     textconv, elem->path);
> +				     textconv, elem->path, opt->xdl_opts);
>  	}
>
>  	show_hunks = make_hunks(sline, cnt, num_parent, dense);
> --
> 1.7.9.5
Antoine Pelisse· Mar 4, 2013, 18:17 UTC · re: Junio C Hamano · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

Show 10 quoted lines
>> That should be reviewed carefully as I'm not exactly sure that does make
>> sense with the way combined-diff works.
>> Still it seems natural to me to be able to remove the space in combined
>> diff as we do with normal diff. Especially as I unfortunately have to
>> deal with many space + feature merges that are very hard to analyze/handle
>> if space differences can't be hidden.
>
> Assuming "That" at the beginning of the off-line comment refers to
> "this patch", I actually I do not think this patch needs to be
> reviewed carefully at all.

I actually meant: "is that patch enough or is there anything I missed". Considering your answer, it looks like I did ;)

Show 12 quoted lines
> An example.  After collecting pairwise diffs between the shared
> postimage and individual parents, we align the hunks and coalesce
> "identical" preimage lines to form shared "-" (removed) lines.  I
> think that step is done with byte-for-byte comparison.  If the
> postimage removes a line from one parent and a corresponding line
> from another parent, and if these corresponding lines in the parents
> differ only by whitespaces in a way the user told us to ignore with
> -b/-w/etc., you would need to tweak the logic to coalesce
> corresponding "lost" lines in the append_lost() function. Otherwise,
> you will see two " -" and "- " lines that remove these corresponding
> lines from the parents that are identical when you ignore
> whitespaces.
That is the part I missed, and it's nicely explained.
> You should add some tests; it would help you think about these
> issues through.
I will definitely add some tests.
Show 28 quoted lines
> For example, in this history:
>
>        git init
>        seq 11 >ten
>        git add ten
>        git commit -m initial
>
>        seq 10 | sed -e 's/6/6 six/' -e 's/2/2 two/' >ten
>        echo 11 >>ten
>        git commit -m ten -a
>
>        git checkout -b side HEAD^
>        seq 10 | sed -e 's/^/  /' | sed -e 's/2/2 dos/' >ten
>        echo 11 >>ten
>        git commit -m indent -a
>
>        git merge master
>
>        seq 10 | sed -e 's/5/5 go/' -e 's/2/2 dois/' >ten
>        git commit -m merged -a
>
> one side indents the original and tweaks some lines, while the other
> side tweaks some other lines without reindenting.  Most notably, the
> fifth line on one side is "5" while on the other side is "  5", and
> this line is rewritten to "5 go" in the final.  The lost lines are
> not coalesced to a single "-- 5" (nor "--   5") but shows that two
> preimages were different only by whitespaces.  Compare that with
> what happens to the final line "11" that gets lost in the result.

It feels incorrect to me to coalsesce "- 5" and "- 5" as it might look incorrect to the user. But still the idea is appealing. I have an implementation for that that requires more testing.

Using the exact example you gave, and running the latest next, I have this output, where 11 is not coalesced. Is that a bug ?

diff --cc ten index d213a99,ed40ab2..37c2af2

Show changes to ten +10 −11
--- a/ten
+++ b/ten
@@@ -1,11 -1,11 +1,10 @@@
-   1
-   2 dos
-   3
-   4
-   5
-   6
-   7
-   8
-   9
-   10
- 11
+ 1
 -2 two
++2 dois
+ 3
+ 4
 -5
 -6 six
++5 go
++6
+ 7
+ 8
+ 9
+ 10
 -11
Junio C Hamano· Mar 4, 2013, 18:36 UTC · re: Antoine Pelisse · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

Antoine Pelisse <apelisse@gmail.com> writes:
> It feels incorrect to me to coalsesce "- 5" and "-  5" as it might
> look incorrect to the user. But still the idea is appealing.

The users already need to see that when reading a regular patch with one or more context lines and -b/-w/etc., anyway. The context lines are made into context only because whitespace differences were ignored, and in the regular unified patch format we can show only one version, either from preimage or from postimage, and have to pick one. Coalescing "- 5" and "- 5" into "--5" or "-- 5" by picking one or the other is the same thing, no?

> Using the exact example you gave, and running the latest next, I have
> this output, where 11 is not coalesced.
> Is that a bug ?

It could be tickling a corner case because the removal is at the end of the file. Perhaps adding 12 that is all common across three versions and see what happens?

Antoine Pelisse· Mar 4, 2013, 18:50 UTC · re: Junio C Hamano · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

On Mon, Mar 4, 2013 at 7:36 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> Antoine Pelisse <apelisse@gmail.com> writes:
>
>> It feels incorrect to me to coalsesce "- 5" and "-  5" as it might
>> look incorrect to the user. But still the idea is appealing.
>
> The users already need to see that when reading a regular patch with
> one or more context lines and -b/-w/etc., anyway.  The context lines
> are made into context only because whitespace differences were
> ignored, and in the regular unified patch format we can show only
> one version, either from preimage or from postimage, and have to
> pick one.  Coalescing "- 5" and "-  5" into "--5" or "--  5" by
> picking one or the other is the same thing, no?
That's all I needed to be convinced. I obviously don't care which one we pick.
Show 7 quoted lines
>> Using the exact example you gave, and running the latest next, I have
>> this output, where 11 is not coalesced.
>> Is that a bug ?
>
> It could be tickling a corner case because the removal is at the end
> of the file.  Perhaps adding 12 that is all common across three
> versions and see what happens?

Doesn't make a difference. Still have "- 11" and " -11". I will try to have a look at it.

Antoine Pelisse· Mar 13, 2013, 21:21 UTC · re: Junio C Hamano · lore

Currently, it's not possible to use the space-ignoring options (-b, -w, --ignore-space-at-eol) with combined diff. It makes it pretty impossible to read a merge between a branch that changed all tabs to spaces, and a branch with functional changes.

Pass diff flags to diff engine, so that combined diff behaves as normal diff does with spaces. Also coalesce lines that are removed from both (or more) parents.

It also means that a conflict-less merge done using a ignore-* strategy option will not show any conflict if shown in combined-diff using the same option.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
OK, I added some tests and coalesce similar lost lines (using the same flags
we used for diff.
 combine-diff.c           |   57 ++++++++++++++++++++++++++++++-----
 t/t4038-diff-combined.sh |   75 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 125 insertions(+), 7 deletions(-)
Show changes to 2 files +125 −8

combine-diff.c, t/t4038-diff-combined.sh

diff --git a/combine-diff.c b/combine-diff.c
index 35d41cd..0f33983 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -5,6 +5,7 @@
 #include "diffcore.h"
 #include "quote.h"
 #include "xdiff-interface.h"
+#include "xdiff/xmacros.h"
 #include "log-tree.h"
 #include "refs.h"
 #include "userdiff.h"
@@ -122,7 +123,47 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
 	return blob;
 }

-static void append_lost(struct sline *sline, int n, const char *line, int len)
+static int match_string_spaces(const char *line1, int len1,
+			       const char *line2, int len2,
+			       long flags)
+{
+	if (flags & XDF_WHITESPACE_FLAGS) {
+		for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
+		for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
+	}
+
+	if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE)))
+		return (len1 == len2 && !memcmp(line1, line2, len1));
+
+	while (len1 > 0 && len2 > 0) {
+		len1--;
+		len2--;
+		if (XDL_ISSPACE(line1[len1]) || XDL_ISSPACE(line2[len2])) {
+			if ((flags & XDF_IGNORE_WHITESPACE_CHANGE) &&
+			    (!XDL_ISSPACE(line1[len1]) || !XDL_ISSPACE(line2[len2])))
+				return 0;
+
+			for (; len1 > 0 && XDL_ISSPACE(line1[len1]); len1--);
+			for (; len2 > 0 && XDL_ISSPACE(line2[len2]); len2--);
+		}
+		if (line1[len1] != line2[len2])
+			return 0;
+	}
+
+	if (flags & XDF_IGNORE_WHITESPACE) {
+		// Consume remaining spaces
+		for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
+		for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
+	}
+
+	// We matched full line1 and line2
+	if (!len1 && !len2)
+		return 1;
+
+	return 0;
+}
+
+static void append_lost(struct sline *sline, int n, const char *line, int len, long flags)
 {
 	struct lline *lline;
 	unsigned long this_mask = (1UL<<n);
@@ -133,8 +174,8 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
 	if (sline->lost_head) {
 		lline = sline->next_lost;
 		while (lline) {
-			if (lline->len == len &&
-			    !memcmp(lline->line, line, len)) {
+			if (match_string_spaces(lline->line, lline->len,
+						line, len, flags)) {
 				lline->parent_map |= this_mask;
 				sline->next_lost = lline->next;
 				return;
@@ -162,6 +203,7 @@ struct combine_diff_state {
 	int n;
 	struct sline *sline;
 	struct sline *lost_bucket;
+	long flags;
 };

 static void consume_line(void *state_, char *line, unsigned long len)
@@ -201,7 +243,7 @@ static void consume_line(void *state_, char *line, unsigned long len)
 		return; /* not in any hunk yet */
 	switch (line[0]) {
 	case '-':
-		append_lost(state->lost_bucket, state->n, line+1, len-1);
+		append_lost(state->lost_bucket, state->n, line+1, len-1, state->flags);
 		break;
 	case '+':
 		state->sline[state->lno-1].flag |= state->nmask;
@@ -215,7 +257,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
 			 struct sline *sline, unsigned int cnt, int n,
 			 int num_parent, int result_deleted,
 			 struct userdiff_driver *textconv,
-			 const char *path)
+			 const char *path, long flags)
 {
 	unsigned int p_lno, lno;
 	unsigned long nmask = (1UL << n);
@@ -231,9 +273,10 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
 	parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
 	parent_file.size = sz;
 	memset(&xpp, 0, sizeof(xpp));
-	xpp.flags = 0;
+	xpp.flags = flags;
 	memset(&xecfg, 0, sizeof(xecfg));
 	memset(&state, 0, sizeof(state));
+	state.flags = flags;
 	state.nmask = nmask;
 	state.sline = sline;
 	state.lno = 1;
@@ -962,7 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 				     elem->parent[i].mode,
 				     &result_file, sline,
 				     cnt, i, num_parent, result_deleted,
-				     textconv, elem->path);
+				     textconv, elem->path, opt->xdl_opts);
 	}

 	show_hunks = make_hunks(sline, cnt, num_parent, dense);
diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
index 614425a..ba8a56b 100755
--- a/t/t4038-diff-combined.sh
+++ b/t/t4038-diff-combined.sh
@@ -113,4 +113,79 @@ test_expect_success 'check --cc --raw with forty trees' '
 	grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
 '

+test_expect_success 'setup combined ignore spaces' '
+	git checkout master &&
+	>test &&
+	git add test &&
+	git commit -m initial &&
+
+	echo "
+	always coalesce
+	eol space coalesce \n\
+	space  change coalesce
+	all spa ces coalesce
+	eol spaces \n\
+	space  change
+	all spa ces" >test &&
+	git commit -m "change three" -a &&
+
+	git checkout -b side HEAD^ &&
+	echo "
+	always coalesce
+	eol space coalesce
+	space change coalesce
+	all spaces coalesce
+	eol spaces
+	space change
+	all spaces" >test &&
+	git commit -m indent -a &&
+
+	test_must_fail git merge master &&
+	echo "
+	eol spaces \n\
+	space  change
+	all spa ces" > test &&
+	git commit -m merged -a
+'
+
+test_expect_success 'check combined output (no ignore space)' '
+	git show | test_i18ngrep "^-\s*eol spaces" &&
+	git show | test_i18ngrep "^-\s*eol space coalesce" &&
+	git show | test_i18ngrep "^-\s*space change" &&
+	git show | test_i18ngrep "^-\s*space change coalesce" &&
+	git show | test_i18ngrep "^-\s*all spaces" &&
+	git show | test_i18ngrep "^-\s*all spaces coalesce" &&
+	git show | test_i18ngrep "^--\s*always coalesce"
+'
+
+test_expect_success 'check combined output (ignore space at eol)' '
+	git show --ignore-space-at-eol | test_i18ngrep "^\s*eol spaces" &&
+	git show --ignore-space-at-eol | test_i18ngrep "^--\s*eol space coalesce" &&
+	git show --ignore-space-at-eol | test_i18ngrep "^-\s*space change" &&
+	git show --ignore-space-at-eol | test_i18ngrep "^-\s*space change coalesce" &&
+	git show --ignore-space-at-eol | test_i18ngrep "^-\s*all spaces" &&
+	git show --ignore-space-at-eol | test_i18ngrep "^-\s*all spaces coalesce" &&
+	git show --ignore-space-at-eol | test_i18ngrep "^--\s*always coalesce"
+'
+
+test_expect_success 'check combined output (ignore space change)' '
+	git show -b | test_i18ngrep "^\s*eol spaces" &&
+	git show -b | test_i18ngrep "^--\s*eol space coalesce" &&
+	git show -b | test_i18ngrep "^\s*space  change" &&
+	git show -b | test_i18ngrep "^--\s*space change coalesce" &&
+	git show -b | test_i18ngrep "^-\s*all spaces" &&
+	git show -b | test_i18ngrep "^-\s*all spaces coalesce" &&
+	git show -b | test_i18ngrep "^--\s*always coalesce"
+'
+
+test_expect_success 'check combined output (ignore all spaces)' '
+	git show -w | test_i18ngrep "^\s*eol spaces" &&
+	git show -w | test_i18ngrep "^--\s*eol space coalesce" &&
+	git show -w | test_i18ngrep "^\s*space  change" &&
+	git show -w | test_i18ngrep "^--\s*space change coalesce" &&
+	git show -w | test_i18ngrep "^\s*all spa ces" &&
+	git show -w | test_i18ngrep "^--\s*all spaces coalesce" &&
+	git show -w | test_i18ngrep "^--\s*always coalesce"
+'
+
 test_done
--
1.7.9.5
Junio C Hamano· Mar 13, 2013, 23:42 UTC · re: Antoine Pelisse · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

Antoine Pelisse <apelisse@gmail.com> writes:
Show 47 quoted lines
> Currently, it's not possible to use the space-ignoring options (-b, -w,
> --ignore-space-at-eol) with combined diff. It makes it pretty impossible
> to read a merge between a branch that changed all tabs to spaces, and a
> branch with functional changes.
>
> Pass diff flags to diff engine, so that combined diff behaves as normal
> diff does with spaces.
> Also coalesce lines that are removed from both (or more) parents.
>
> It also means that a conflict-less merge done using a ignore-* strategy
> option will not show any conflict if shown in combined-diff using the
> same option.
>
> Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
> ---
> OK, I added some tests and coalesce similar lost lines (using the same flags
> we used for diff.
>
>  combine-diff.c           |   57 ++++++++++++++++++++++++++++++-----
>  t/t4038-diff-combined.sh |   75 ++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 125 insertions(+), 7 deletions(-)
>
> diff --git a/combine-diff.c b/combine-diff.c
> index 35d41cd..0f33983 100644
> --- a/combine-diff.c
> +++ b/combine-diff.c
> @@ -5,6 +5,7 @@
>  #include "diffcore.h"
>  #include "quote.h"
>  #include "xdiff-interface.h"
> +#include "xdiff/xmacros.h"
>  #include "log-tree.h"
>  #include "refs.h"
>  #include "userdiff.h"
> @@ -122,7 +123,47 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
>  	return blob;
>  }
>
> -static void append_lost(struct sline *sline, int n, const char *line, int len)
> +static int match_string_spaces(const char *line1, int len1,
> +			       const char *line2, int len2,
> +			       long flags)
> +{
> +	if (flags & XDF_WHITESPACE_FLAGS) {
> +		for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
> +		for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
> +	}

This says "any XDF_WHITESPACE_FLAGS causes the trailing blanks ignored", which is correct: --ignore-space-at-eol, -b or -w are all we have. OK.

> +	if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE)))
> +		return (len1 == len2 && !memcmp(line1, line2, len1));

If --ignore-space-at-eol is the only one given, or none of the whitespace flags is given, then we can just do memcmp(). OK.

The remainder of the function is only used when either -b or -w is (or both are) in effect.

> +	while (len1 > 0 && len2 > 0) {
> +		len1--;
> +		len2--;
Scanning from the tail end of the strings...
> +		if (XDL_ISSPACE(line1[len1]) || XDL_ISSPACE(line2[len2])) {
> +			if ((flags & XDF_IGNORE_WHITESPACE_CHANGE) &&
> +			    (!XDL_ISSPACE(line1[len1]) || !XDL_ISSPACE(line2[len2])))
> +				return 0;

If --ignore-space-change and one side is blank while the other not, then these cannot be the same. If we see blank on both sides, that is fine under --ignore-whitespace, too.

> +			for (; len1 > 0 && XDL_ISSPACE(line1[len1]); len1--);
> +			for (; len2 > 0 && XDL_ISSPACE(line2[len2]); len2--);

Then, strip the blanks, if any, so that the next comparison is done for the last non-blank char from both sides. OK.

> +		}
> +		if (line1[len1] != line2[len2])
> +			return 0;

And we can say "not same" as soon as we find differences. Rinse and repeat.

> +	}
> +
> +	if (flags & XDF_IGNORE_WHITESPACE) {
> +		// Consume remaining spaces
No C++/C99 comments in our codebase, please.
> +		for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
> +		for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
If we are ignoring all whitespaces, we can simply discard them.  OK.

I wonder what happens when --ignore-space-change is in effect but not --ignore-all-space? The loop must have exited because one (or both) of len1 and len2 went down to zero. If both are zero, we obviously have a match, and otherwise, one has blanks at the beginning and the other does not. Wait, is that really true? Yes, because if len1 == 0 && len2 != 0, line2[len2] cannot be blank (otherwise len2 would be zero because we have a loop to eat a run of blanks).

OK, sounds good.
> +	}
> +
> +	// We matched full line1 and line2
Likewise for "//".
Show 5 quoted lines
> +	if (!len1 && !len2)
> +		return 1;
> +
> +	return 0;
> +}
Show 15 quoted lines
> +static void append_lost(struct sline *sline, int n, const char *line, int len, long flags)
>  {
>  	struct lline *lline;
>  	unsigned long this_mask = (1UL<<n);
> @@ -133,8 +174,8 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
>  	if (sline->lost_head) {
>  		lline = sline->next_lost;
>  		while (lline) {
> -			if (lline->len == len &&
> -			    !memcmp(lline->line, line, len)) {
> +			if (match_string_spaces(lline->line, lline->len,
> +						line, len, flags)) {
>  				lline->parent_map |= this_mask;
>  				sline->next_lost = lline->next;
>  				return;
Nicely done.
Thanks, will queue with comment style fix-ups.
Show 86 quoted lines
> diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
> index 614425a..ba8a56b 100755
> --- a/t/t4038-diff-combined.sh
> +++ b/t/t4038-diff-combined.sh
> @@ -113,4 +113,79 @@ test_expect_success 'check --cc --raw with forty trees' '
>  	grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
>  '
>
> +test_expect_success 'setup combined ignore spaces' '
> +	git checkout master &&
> +	>test &&
> +	git add test &&
> +	git commit -m initial &&
> +
> +	echo "
> +	always coalesce
> +	eol space coalesce \n\
> +	space  change coalesce
> +	all spa ces coalesce
> +	eol spaces \n\
> +	space  change
> +	all spa ces" >test &&
> +	git commit -m "change three" -a &&
> +
> +	git checkout -b side HEAD^ &&
> +	echo "
> +	always coalesce
> +	eol space coalesce
> +	space change coalesce
> +	all spaces coalesce
> +	eol spaces
> +	space change
> +	all spaces" >test &&
> +	git commit -m indent -a &&
> +
> +	test_must_fail git merge master &&
> +	echo "
> +	eol spaces \n\
> +	space  change
> +	all spa ces" > test &&
> +	git commit -m merged -a
> +'
> +
> +test_expect_success 'check combined output (no ignore space)' '
> +	git show | test_i18ngrep "^-\s*eol spaces" &&
> +	git show | test_i18ngrep "^-\s*eol space coalesce" &&
> +	git show | test_i18ngrep "^-\s*space change" &&
> +	git show | test_i18ngrep "^-\s*space change coalesce" &&
> +	git show | test_i18ngrep "^-\s*all spaces" &&
> +	git show | test_i18ngrep "^-\s*all spaces coalesce" &&
> +	git show | test_i18ngrep "^--\s*always coalesce"
> +'
> +
> +test_expect_success 'check combined output (ignore space at eol)' '
> +	git show --ignore-space-at-eol | test_i18ngrep "^\s*eol spaces" &&
> +	git show --ignore-space-at-eol | test_i18ngrep "^--\s*eol space coalesce" &&
> +	git show --ignore-space-at-eol | test_i18ngrep "^-\s*space change" &&
> +	git show --ignore-space-at-eol | test_i18ngrep "^-\s*space change coalesce" &&
> +	git show --ignore-space-at-eol | test_i18ngrep "^-\s*all spaces" &&
> +	git show --ignore-space-at-eol | test_i18ngrep "^-\s*all spaces coalesce" &&
> +	git show --ignore-space-at-eol | test_i18ngrep "^--\s*always coalesce"
> +'
> +
> +test_expect_success 'check combined output (ignore space change)' '
> +	git show -b | test_i18ngrep "^\s*eol spaces" &&
> +	git show -b | test_i18ngrep "^--\s*eol space coalesce" &&
> +	git show -b | test_i18ngrep "^\s*space  change" &&
> +	git show -b | test_i18ngrep "^--\s*space change coalesce" &&
> +	git show -b | test_i18ngrep "^-\s*all spaces" &&
> +	git show -b | test_i18ngrep "^-\s*all spaces coalesce" &&
> +	git show -b | test_i18ngrep "^--\s*always coalesce"
> +'
> +
> +test_expect_success 'check combined output (ignore all spaces)' '
> +	git show -w | test_i18ngrep "^\s*eol spaces" &&
> +	git show -w | test_i18ngrep "^--\s*eol space coalesce" &&
> +	git show -w | test_i18ngrep "^\s*space  change" &&
> +	git show -w | test_i18ngrep "^--\s*space change coalesce" &&
> +	git show -w | test_i18ngrep "^\s*all spa ces" &&
> +	git show -w | test_i18ngrep "^--\s*all spaces coalesce" &&
> +	git show -w | test_i18ngrep "^--\s*always coalesce"
> +'
> +
>  test_done
> --
> 1.7.9.5
Junio C Hamano· Mar 13, 2013, 23:53 UTC · re: Antoine Pelisse · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

Antoine Pelisse <apelisse@gmail.com> writes:
> OK, I added some tests and coalesce similar lost lines (using the same flags
> we used for diff.
Hmph, why doesn't this pass its own tests?
> +test_expect_success 'check combined output (no ignore space)' '
> +	git show | test_i18ngrep "^-\s*eol spaces" &&
What kind of grep pattern is "\s*"?
Johannes Sixt· Mar 14, 2013, 07:08 UTC · re: Antoine Pelisse · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

Am 3/13/2013 22:21, schrieb Antoine Pelisse:
Show 163 quoted lines
> Currently, it's not possible to use the space-ignoring options (-b, -w,
> --ignore-space-at-eol) with combined diff. It makes it pretty impossible
> to read a merge between a branch that changed all tabs to spaces, and a
> branch with functional changes.
> 
> Pass diff flags to diff engine, so that combined diff behaves as normal
> diff does with spaces.
> Also coalesce lines that are removed from both (or more) parents.
> 
> It also means that a conflict-less merge done using a ignore-* strategy
> option will not show any conflict if shown in combined-diff using the
> same option.
> 
> Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
> ---
> OK, I added some tests and coalesce similar lost lines (using the same flags
> we used for diff.
> 
>  combine-diff.c           |   57 ++++++++++++++++++++++++++++++-----
>  t/t4038-diff-combined.sh |   75 ++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 125 insertions(+), 7 deletions(-)
> 
> diff --git a/combine-diff.c b/combine-diff.c
> index 35d41cd..0f33983 100644
> --- a/combine-diff.c
> +++ b/combine-diff.c
> @@ -5,6 +5,7 @@
>  #include "diffcore.h"
>  #include "quote.h"
>  #include "xdiff-interface.h"
> +#include "xdiff/xmacros.h"
>  #include "log-tree.h"
>  #include "refs.h"
>  #include "userdiff.h"
> @@ -122,7 +123,47 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
>  	return blob;
>  }
> 
> -static void append_lost(struct sline *sline, int n, const char *line, int len)
> +static int match_string_spaces(const char *line1, int len1,
> +			       const char *line2, int len2,
> +			       long flags)
> +{
> +	if (flags & XDF_WHITESPACE_FLAGS) {
> +		for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
> +		for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
> +	}
> +
> +	if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE)))
> +		return (len1 == len2 && !memcmp(line1, line2, len1));
> +
> +	while (len1 > 0 && len2 > 0) {
> +		len1--;
> +		len2--;
> +		if (XDL_ISSPACE(line1[len1]) || XDL_ISSPACE(line2[len2])) {
> +			if ((flags & XDF_IGNORE_WHITESPACE_CHANGE) &&
> +			    (!XDL_ISSPACE(line1[len1]) || !XDL_ISSPACE(line2[len2])))
> +				return 0;
> +
> +			for (; len1 > 0 && XDL_ISSPACE(line1[len1]); len1--);
> +			for (; len2 > 0 && XDL_ISSPACE(line2[len2]); len2--);
> +		}
> +		if (line1[len1] != line2[len2])
> +			return 0;
> +	}
> +
> +	if (flags & XDF_IGNORE_WHITESPACE) {
> +		// Consume remaining spaces
> +		for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
> +		for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
> +	}
> +
> +	// We matched full line1 and line2
> +	if (!len1 && !len2)
> +		return 1;
> +
> +	return 0;
> +}
> +
> +static void append_lost(struct sline *sline, int n, const char *line, int len, long flags)
>  {
>  	struct lline *lline;
>  	unsigned long this_mask = (1UL<<n);
> @@ -133,8 +174,8 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
>  	if (sline->lost_head) {
>  		lline = sline->next_lost;
>  		while (lline) {
> -			if (lline->len == len &&
> -			    !memcmp(lline->line, line, len)) {
> +			if (match_string_spaces(lline->line, lline->len,
> +						line, len, flags)) {
>  				lline->parent_map |= this_mask;
>  				sline->next_lost = lline->next;
>  				return;
> @@ -162,6 +203,7 @@ struct combine_diff_state {
>  	int n;
>  	struct sline *sline;
>  	struct sline *lost_bucket;
> +	long flags;
>  };
> 
>  static void consume_line(void *state_, char *line, unsigned long len)
> @@ -201,7 +243,7 @@ static void consume_line(void *state_, char *line, unsigned long len)
>  		return; /* not in any hunk yet */
>  	switch (line[0]) {
>  	case '-':
> -		append_lost(state->lost_bucket, state->n, line+1, len-1);
> +		append_lost(state->lost_bucket, state->n, line+1, len-1, state->flags);
>  		break;
>  	case '+':
>  		state->sline[state->lno-1].flag |= state->nmask;
> @@ -215,7 +257,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
>  			 struct sline *sline, unsigned int cnt, int n,
>  			 int num_parent, int result_deleted,
>  			 struct userdiff_driver *textconv,
> -			 const char *path)
> +			 const char *path, long flags)
>  {
>  	unsigned int p_lno, lno;
>  	unsigned long nmask = (1UL << n);
> @@ -231,9 +273,10 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
>  	parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
>  	parent_file.size = sz;
>  	memset(&xpp, 0, sizeof(xpp));
> -	xpp.flags = 0;
> +	xpp.flags = flags;
>  	memset(&xecfg, 0, sizeof(xecfg));
>  	memset(&state, 0, sizeof(state));
> +	state.flags = flags;
>  	state.nmask = nmask;
>  	state.sline = sline;
>  	state.lno = 1;
> @@ -962,7 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
>  				     elem->parent[i].mode,
>  				     &result_file, sline,
>  				     cnt, i, num_parent, result_deleted,
> -				     textconv, elem->path);
> +				     textconv, elem->path, opt->xdl_opts);
>  	}
> 
>  	show_hunks = make_hunks(sline, cnt, num_parent, dense);
> diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
> index 614425a..ba8a56b 100755
> --- a/t/t4038-diff-combined.sh
> +++ b/t/t4038-diff-combined.sh
> @@ -113,4 +113,79 @@ test_expect_success 'check --cc --raw with forty trees' '
>  	grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
>  '
> 
> +test_expect_success 'setup combined ignore spaces' '
> +	git checkout master &&
> +	>test &&
> +	git add test &&
> +	git commit -m initial &&
> +
> +	echo "
> +	always coalesce
> +	eol space coalesce \n\
> +	space  change coalesce
> +	all spa ces coalesce
> +	eol spaces \n\
> +	space  change
> +	all spa ces" >test &&
This form of 'echo' is not sufficiently portable. How about:
	tr -d Q <<-\EOF >test &&
	always coalesce
	eol space coalesce Q
	space  change coalesce
	all spa ces coalesce
	eol spaces Q
	space  change
	all spa ces
	EOF
Show 18 quoted lines
> +	git commit -m "change three" -a &&
> +
> +	git checkout -b side HEAD^ &&
> +	echo "
> +	always coalesce
> +	eol space coalesce
> +	space change coalesce
> +	all spaces coalesce
> +	eol spaces
> +	space change
> +	all spaces" >test &&
> +	git commit -m indent -a &&
> +
> +	test_must_fail git merge master &&
> +	echo "
> +	eol spaces \n\
> +	space  change
> +	all spa ces" > test &&
Ditto.
Show 11 quoted lines
> +	git commit -m merged -a
> +'
> +
> +test_expect_success 'check combined output (no ignore space)' '
> +	git show | test_i18ngrep "^-\s*eol spaces" &&
> +	git show | test_i18ngrep "^-\s*eol space coalesce" &&
> +	git show | test_i18ngrep "^-\s*space change" &&
> +	git show | test_i18ngrep "^-\s*space change coalesce" &&
> +	git show | test_i18ngrep "^-\s*all spaces" &&
> +	git show | test_i18ngrep "^-\s*all spaces coalesce" &&
> +	git show | test_i18ngrep "^--\s*always coalesce"
This loses the exit code of git show. We usually write this as
	git show >actual &&
	grep "^- *eol spaces" &&
	grep "^- *eol space coalesce" &&
	...
(Same for later tests.)
There is nothing i18n-ish in the test patterns. Use regular grep.

BTW, there is compare_diff_patch() in diff-lib.sh. You can use it to compare diff output to expected output. Then you do not need a grep invocation for each line of the test file.

-- Hannes
Junio C Hamano· Mar 14, 2013, 15:31 UTC · re: Johannes Sixt · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

Johannes Sixt <j.sixt@viscovery.net> writes:
Show 8 quoted lines
> This form of 'echo' is not sufficiently portable. How about:
>
> 	tr -d Q <<-\EOF >test &&
>
> 	always coalesce
> 	eol space coalesce Q
> ...
> 	EOF
Much better.
Show 19 quoted lines
>> +test_expect_success 'check combined output (no ignore space)' '
>> +	git show | test_i18ngrep "^-\s*eol spaces" &&
>> ...
>> +	git show | test_i18ngrep "^--\s*always coalesce"
>
> This loses the exit code of git show. We usually write this as
>
> 	git show >actual &&
> 	grep "^- *eol spaces" &&
> 	grep "^- *eol space coalesce" &&
> 	...
>
> (Same for later tests.)
>
> There is nothing i18n-ish in the test patterns. Use regular grep.
>
> BTW, there is compare_diff_patch() in diff-lib.sh. You can use it to
> compare diff output to expected output. Then you do not need a grep
> invocation for each line of the test file.
All good suggestions.  Thanks.
Antoine Pelisse· Mar 14, 2013, 15:51 UTC · re: Junio C Hamano · lore

Re: [PATCH] Allow combined diff to ignore white-spaces

On Thu, Mar 14, 2013 at 4:31 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 34 quoted lines
> Johannes Sixt <j.sixt@viscovery.net> writes:
>
>> This form of 'echo' is not sufficiently portable. How about:
>>
>>       tr -d Q <<-\EOF >test &&
>>
>>       always coalesce
>>       eol space coalesce Q
>> ...
>>       EOF
>
> Much better.
>
>>> +test_expect_success 'check combined output (no ignore space)' '
>>> +    git show | test_i18ngrep "^-\s*eol spaces" &&
>>> ...
>>> +    git show | test_i18ngrep "^--\s*always coalesce"
>>
>> This loses the exit code of git show. We usually write this as
>>
>>       git show >actual &&
>>       grep "^- *eol spaces" &&
>>       grep "^- *eol space coalesce" &&
>>       ...
>>
>> (Same for later tests.)
>>
>> There is nothing i18n-ish in the test patterns. Use regular grep.
>>
>> BTW, there is compare_diff_patch() in diff-lib.sh. You can use it to
>> compare diff output to expected output. Then you do not need a grep
>> invocation for each line of the test file.
>
> All good suggestions.  Thanks.

OK Very good, I will resubmit tonight. I was indeed not really sure about the best way to test here. Thanks for the tips and confirmation !

Cheers,
Antoine Pelisse· Mar 14, 2013, 21:03 UTC · re: Junio C Hamano · lore

[PATCH v3] Allow combined diff to ignore white-spaces

Currently, it's not possible to use the space-ignoring options (-b, -w, --ignore-space-at-eol) with combined diff. It makes it pretty impossible to read a merge between a branch that changed all tabs to spaces, and a branch with functional changes.

Pass diff flags to diff engine, so that combined diff behaves as normal diff does with spaces. Also coalesce lines that are removed from both (or more) parents.

It also means that a conflict-less merge done using a ignore-* strategy option will not show any conflict if shown in combined-diff using the same option.

Signed-off-by: Antoine Pelisse <apelisse@gmail.com>
---
Changes:
- Fixed comments
- Fixed tests (following Johannes suggestions)
 combine-diff.c           |   57 +++++++++++++++++++++---
 t/t4038-diff-combined.sh |  111 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 161 insertions(+), 7 deletions(-)
Show changes to 2 files +161 −8

combine-diff.c, t/t4038-diff-combined.sh

diff --git a/combine-diff.c b/combine-diff.c
index 35d41cd..6288485 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -5,6 +5,7 @@
 #include "diffcore.h"
 #include "quote.h"
 #include "xdiff-interface.h"
+#include "xdiff/xmacros.h"
 #include "log-tree.h"
 #include "refs.h"
 #include "userdiff.h"
@@ -122,7 +123,47 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
 	return blob;
 }

-static void append_lost(struct sline *sline, int n, const char *line, int len)
+static int match_string_spaces(const char *line1, int len1,
+			       const char *line2, int len2,
+			       long flags)
+{
+	if (flags & XDF_WHITESPACE_FLAGS) {
+		for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
+		for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
+	}
+
+	if (!(flags & (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE)))
+		return (len1 == len2 && !memcmp(line1, line2, len1));
+
+	while (len1 > 0 && len2 > 0) {
+		len1--;
+		len2--;
+		if (XDL_ISSPACE(line1[len1]) || XDL_ISSPACE(line2[len2])) {
+			if ((flags & XDF_IGNORE_WHITESPACE_CHANGE) &&
+			    (!XDL_ISSPACE(line1[len1]) || !XDL_ISSPACE(line2[len2])))
+				return 0;
+
+			for (; len1 > 0 && XDL_ISSPACE(line1[len1]); len1--);
+			for (; len2 > 0 && XDL_ISSPACE(line2[len2]); len2--);
+		}
+		if (line1[len1] != line2[len2])
+			return 0;
+	}
+
+	if (flags & XDF_IGNORE_WHITESPACE) {
+		/* Consume remaining spaces */
+		for (; len1 > 0 && XDL_ISSPACE(line1[len1 - 1]); len1--);
+		for (; len2 > 0 && XDL_ISSPACE(line2[len2 - 1]); len2--);
+	}
+
+	/* We matched full line1 and line2 */
+	if (!len1 && !len2)
+		return 1;
+
+	return 0;
+}
+
+static void append_lost(struct sline *sline, int n, const char *line, int len, long flags)
 {
 	struct lline *lline;
 	unsigned long this_mask = (1UL<<n);
@@ -133,8 +174,8 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
 	if (sline->lost_head) {
 		lline = sline->next_lost;
 		while (lline) {
-			if (lline->len == len &&
-			    !memcmp(lline->line, line, len)) {
+			if (match_string_spaces(lline->line, lline->len,
+						line, len, flags)) {
 				lline->parent_map |= this_mask;
 				sline->next_lost = lline->next;
 				return;
@@ -162,6 +203,7 @@ struct combine_diff_state {
 	int n;
 	struct sline *sline;
 	struct sline *lost_bucket;
+	long flags;
 };

 static void consume_line(void *state_, char *line, unsigned long len)
@@ -201,7 +243,7 @@ static void consume_line(void *state_, char *line, unsigned long len)
 		return; /* not in any hunk yet */
 	switch (line[0]) {
 	case '-':
-		append_lost(state->lost_bucket, state->n, line+1, len-1);
+		append_lost(state->lost_bucket, state->n, line+1, len-1, state->flags);
 		break;
 	case '+':
 		state->sline[state->lno-1].flag |= state->nmask;
@@ -215,7 +257,7 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
 			 struct sline *sline, unsigned int cnt, int n,
 			 int num_parent, int result_deleted,
 			 struct userdiff_driver *textconv,
-			 const char *path)
+			 const char *path, long flags)
 {
 	unsigned int p_lno, lno;
 	unsigned long nmask = (1UL << n);
@@ -231,9 +273,10 @@ static void combine_diff(const unsigned char *parent, unsigned int mode,
 	parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
 	parent_file.size = sz;
 	memset(&xpp, 0, sizeof(xpp));
-	xpp.flags = 0;
+	xpp.flags = flags;
 	memset(&xecfg, 0, sizeof(xecfg));
 	memset(&state, 0, sizeof(state));
+	state.flags = flags;
 	state.nmask = nmask;
 	state.sline = sline;
 	state.lno = 1;
@@ -962,7 +1005,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
 				     elem->parent[i].mode,
 				     &result_file, sline,
 				     cnt, i, num_parent, result_deleted,
-				     textconv, elem->path);
+				     textconv, elem->path, opt->xdl_opts);
 	}

 	show_hunks = make_hunks(sline, cnt, num_parent, dense);
diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh
index 614425a..b7e16a7 100755
--- a/t/t4038-diff-combined.sh
+++ b/t/t4038-diff-combined.sh
@@ -3,6 +3,7 @@
 test_description='combined diff'

 . ./test-lib.sh
+. "$TEST_DIRECTORY"/diff-lib.sh

 setup_helper () {
 	one=$1 branch=$2 side=$3 &&
@@ -113,4 +114,114 @@ test_expect_success 'check --cc --raw with forty trees' '
 	grep "^::::::::::::::::::::::::::::::::::::::::[^:]" out
 '

+test_expect_success 'setup combined ignore spaces' '
+	git checkout master &&
+	>test &&
+	git add test &&
+	git commit -m initial &&
+
+	tr -d Q <<-\EOF >test &&
+	always coalesce
+	eol space coalesce Q
+	space  change coalesce
+	all spa ces coalesce
+	eol spaces Q
+	space  change
+	all spa ces
+	EOF
+	git commit -m "test space change" -a &&
+
+	git checkout -b side HEAD^ &&
+	tr -d Q <<-\EOF >test &&
+	always coalesce
+	eol space coalesce
+	space change coalesce
+	all spaces coalesce
+	eol spaces
+	space change
+	all spaces
+	EOF
+	git commit -m "test other space changes" -a &&
+
+	test_must_fail git merge master &&
+	tr -d Q <<-\EOF >test &&
+	eol spaces Q
+	space  change
+	all spa ces
+	EOF
+	git commit -m merged -a
+'
+
+test_expect_success 'check combined output (no ignore space)' '
+	git show >actual.tmp &&
+	sed -e "1,/^@@@/d" < actual.tmp >actual &&
+	tr -d Q <<-\EOF >expected &&
+	--always coalesce
+	- eol space coalesce
+	- space change coalesce
+	- all spaces coalesce
+	- eol spaces
+	- space change
+	- all spaces
+	 -eol space coalesce Q
+	 -space  change coalesce
+	 -all spa ces coalesce
+	+ eol spaces Q
+	+ space  change
+	+ all spa ces
+	EOF
+	compare_diff_patch expected actual
+'
+
+test_expect_success 'check combined output (ignore space at eol)' '
+	git show --ignore-space-at-eol >actual.tmp &&
+	sed -e "1,/^@@@/d" < actual.tmp >actual &&
+	tr -d Q <<-\EOF >expected &&
+	--always coalesce
+	--eol space coalesce
+	- space change coalesce
+	- all spaces coalesce
+	 -space  change coalesce
+	 -all spa ces coalesce
+	  eol spaces Q
+	- space change
+	- all spaces
+	+ space  change
+	+ all spa ces
+	EOF
+	compare_diff_patch expected actual
+'
+
+test_expect_success 'check combined output (ignore space change)' '
+	git show -b >actual.tmp &&
+	sed -e "1,/^@@@/d" < actual.tmp >actual &&
+	tr -d Q <<-\EOF >expected &&
+	--always coalesce
+	--eol space coalesce
+	--space change coalesce
+	- all spaces coalesce
+	 -all spa ces coalesce
+	  eol spaces Q
+	  space  change
+	- all spaces
+	+ all spa ces
+	EOF
+	compare_diff_patch expected actual
+'
+
+test_expect_success 'check combined output (ignore all spaces)' '
+	git show -w >actual.tmp &&
+	sed -e "1,/^@@@/d" < actual.tmp >actual &&
+	tr -d Q <<-\EOF >expected &&
+	--always coalesce
+	--eol space coalesce
+	--space change coalesce
+	--all spaces coalesce
+	  eol spaces Q
+	  space  change
+	  all spa ces
+	EOF
+	compare_diff_patch expected actual
+'
+
 test_done
--
1.7.9.5
Junio C Hamano· Mar 14, 2013, 21:43 UTC · re: Antoine Pelisse · lore

Re: [PATCH v3] Allow combined diff to ignore white-spaces

Antoine Pelisse <apelisse@gmail.com> writes:
Show 20 quoted lines
> +test_expect_success 'check combined output (no ignore space)' '
> +	git show >actual.tmp &&
> +	sed -e "1,/^@@@/d" < actual.tmp >actual &&
> +	tr -d Q <<-\EOF >expected &&
> +	--always coalesce
> +	- eol space coalesce
> +	- space change coalesce
> +	- all spaces coalesce
> +	- eol spaces
> +	- space change
> +	- all spaces
> +	 -eol space coalesce Q
> +	 -space  change coalesce
> +	 -all spa ces coalesce
> +	+ eol spaces Q
> +	+ space  change
> +	+ all spa ces
> +	EOF
> +	compare_diff_patch expected actual
> +'
Nicely constructed ;-)
Thanks.

← back to recent threads