git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Getting an odd diff
@ 2022-04-29 12:33 Jack Adrian Zappa
  2022-04-30  7:16 ` Johannes Sixt
  0 siblings, 1 reply; 3+ messages in thread
From: Jack Adrian Zappa @ 2022-04-29 12:33 UTC (permalink / raw)
  To: git-mailing-list

So, I have a regex to select words so that I can focus on the actual
changes.  But then I noticed that it did something weird.  It grouped
some parenthesis with another word.  I generated a minimal example for
that line and it was reproducible.

Before:
var result = ((res.State == ResultState.Succeeded) &&
string.IsNullOrEmpty(res.ErrorCode) )? (byte)0 : (byte)1;

After:
var result = res.State == ResultState.Succeeded ? (byte)0 : (byte)1;

Diff:
$ git diff2 --no-index b a
warning: LF will be replaced by CRLF in b.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in a.
The file will have its original line endings in your working directory
diff --git a/b b/a
index 4e3604a8e..619d21e4e 100644
--- a/b
+++ b/a
@@ -1 +1 @@
var result = [-((res-]{+res+}.State == ResultState.Succeeded[-) &&
string.IsNullOrEmpty(res.ErrorCode) )-] ? (byte)0 : (byte)1;

I tried to make a smaller example and it didn't cause the issue.

Before:
var abc = ((xyz.Stuff == other_stuff) && stuff.yay(question) ? yes : no;

After:
var abc = xyz.Stuff == other_stuff ? yes : no;

Diff:
$ git diff2 --no-index b a
warning: LF will be replaced by CRLF in b.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in a.
The file will have its original line endings in your working directory
diff --git a/b b/a
index df18ca34e..1024d6b68 100644
--- a/b
+++ b/a
@@ -1 +1 @@
var abc =[-((-] xyz.Stuff == other_stuff[-) && stuff.yay(question)-] ? yes : no;

So, my question is, what's going on here?

The alias is as follows:
     diff2 = diff --color=always --ignore-space-change
'--word-diff-regex=((\\r\\n?|\\n\\r?)[\\t
]*)?([a-zA-Z_][a-zA-Z_0-9]*|0([xX]([0-9][a-fA-F])+|[0-7]+|[bB][01]+)|[1-9][0-9]*(\\.[0-9]+)?([eE][0-9]+|[pP][0-9a-fA-F])?|\\S)(\\r\\n?|\\n\\r?)?'
-p

Thanks,


JAZ
JAZ

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Getting an odd diff
  2022-04-29 12:33 Getting an odd diff Jack Adrian Zappa
@ 2022-04-30  7:16 ` Johannes Sixt
  2022-05-02 18:04   ` Jack Adrian Zappa
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Sixt @ 2022-04-30  7:16 UTC (permalink / raw)
  To: Jack Adrian Zappa; +Cc: git-mailing-list

Am 29.04.22 um 14:33 schrieb Jack Adrian Zappa:
> So, I have a regex to select words so that I can focus on the actual
> changes.  But then I noticed that it did something weird.  It grouped
> some parenthesis with another word.  I generated a minimal example for
> that line and it was reproducible.
> 
> Before:
> var result = ((res.State == ResultState.Succeeded) &&
> string.IsNullOrEmpty(res.ErrorCode) )? (byte)0 : (byte)1;
> 
> After:
> var result = res.State == ResultState.Succeeded ? (byte)0 : (byte)1;
> 
> Diff:
> $ git diff2 --no-index b a
> warning: LF will be replaced by CRLF in b.
> The file will have its original line endings in your working directory
> warning: LF will be replaced by CRLF in a.
> The file will have its original line endings in your working directory
> diff --git a/b b/a
> index 4e3604a8e..619d21e4e 100644
> --- a/b
> +++ b/a
> @@ -1 +1 @@
> var result = [-((res-]{+res+}.State == ResultState.Succeeded[-) &&
> string.IsNullOrEmpty(res.ErrorCode) )-] ? (byte)0 : (byte)1;
> 
> I tried to make a smaller example and it didn't cause the issue.
> 
> Before:
> var abc = ((xyz.Stuff == other_stuff) && stuff.yay(question) ? yes : no;
> 
> After:
> var abc = xyz.Stuff == other_stuff ? yes : no;
> 
> Diff:
> $ git diff2 --no-index b a
> warning: LF will be replaced by CRLF in b.
> The file will have its original line endings in your working directory
> warning: LF will be replaced by CRLF in a.
> The file will have its original line endings in your working directory
> diff --git a/b b/a
> index df18ca34e..1024d6b68 100644
> --- a/b
> +++ b/a
> @@ -1 +1 @@
> var abc =[-((-] xyz.Stuff == other_stuff[-) && stuff.yay(question)-] ? yes : no;
> 
> So, my question is, what's going on here?
> 
> The alias is as follows:
>      diff2 = diff --color=always --ignore-space-change
> '--word-diff-regex=((\\r\\n?|\\n\\r?)[\\t
> ]*)?([a-zA-Z_][a-zA-Z_0-9]*|0([xX]([0-9][a-fA-F])+|[0-7]+|[bB][01]+)|[1-9][0-9]*(\\.[0-9]+)?([eE][0-9]+|[pP][0-9a-fA-F])?|\\S)(\\r\\n?|\\n\\r?)?'
> -p

I am a bit reluctant to diagnose what exactly is happening here because
your word regex is outside the design space. It is definitely not a good
idea to declare whitespace and even line breaks as part of a word. And
in fact, when you remove the trailing (\\r\\n?|\\n\\r?)?, you get a more
sensible word diff:

var result =[-((-] resx.State == ResultState.Succeeded[-) &&-]
[-string.IsNullOrEmpty(res.ErrorCode) )-] ? (byte)0 : (byte)1;

But if I were you, I would remove all subexpressions that match any form
of whitespace.

-- Hannes

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Getting an odd diff
  2022-04-30  7:16 ` Johannes Sixt
@ 2022-05-02 18:04   ` Jack Adrian Zappa
  0 siblings, 0 replies; 3+ messages in thread
From: Jack Adrian Zappa @ 2022-05-02 18:04 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: git-mailing-list

On Sat, Apr 30, 2022 at 3:16 AM Johannes Sixt <j6t@kdbg.org> wrote:
> I am a bit reluctant to diagnose what exactly is happening here because
> your word regex is outside the design space. It is definitely not a good
> idea to declare whitespace and even line breaks as part of a word. And
> in fact, when you remove the trailing (\\r\\n?|\\n\\r?)?, you get a more
> sensible word diff:
>
> var result =[-((-] resx.State == ResultState.Succeeded[-) &&-]
> [-string.IsNullOrEmpty(res.ErrorCode) )-] ? (byte)0 : (byte)1;
>
> But if I were you, I would remove all subexpressions that match any form
> of whitespace.

Interesting... IIRC, the reason for the leading and trailing line
breaks in the regex is to stop the diff from messing up the alignment
of multiple edited lines.  I don't remember the exact sequence I was
seeing, but removing them doesn't appear to mess up the alignment so
badly anymore.  Still, I'm surprised that removing that trailing line
break capture would have caused the issue seen here.  For now, I'll
remove the captures and if I see what I was seeing before, I'll report
back to the group.

Thanks,


Jaz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-02 18:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 12:33 Getting an odd diff Jack Adrian Zappa
2022-04-30  7:16 ` Johannes Sixt
2022-05-02 18:04   ` Jack Adrian Zappa

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).