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

2013-03-14 Thread Antoine Pelisse
On Thu, Mar 14, 2013 at 4:31 PM, Junio C Hamano  wrote:
> Johannes Sixt  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,
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-03-14 Thread Junio C Hamano
Johannes Sixt  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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-03-14 Thread Johannes Sixt
Am 3/13/2013 22:21, schrieb Antoine Pelisse:
> 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 
> ---
> 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< @@ -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;
>   

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

2013-03-13 Thread Junio C Hamano
Antoine Pelisse  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*"?

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-03-13 Thread Junio C Hamano
Antoine Pelisse  writes:

> 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 
> ---
> 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 "//".

> + 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< @@ -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->lin

[PATCH] Allow combined diff to ignore white-spaces

2013-03-13 Thread Antoine Pelisse
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 
---
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 = (1ULnext_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;
+ 

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

2013-03-04 Thread Antoine Pelisse
On Mon, Mar 4, 2013 at 7:36 PM, Junio C Hamano  wrote:
> Antoine Pelisse  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.

>> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-03-04 Thread Junio C Hamano
Antoine Pelisse  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?
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-03-04 Thread Antoine Pelisse
>> 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 ;)

> 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.

> 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
--- 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2013-03-02 Thread Junio C Hamano
Antoine Pelisse  writes:

> 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 
> ---
> 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.

> 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_hunk

[PATCH] Allow combined diff to ignore white-spaces

2013-03-02 Thread Antoine Pelisse
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 
---
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(-)

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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html