{"thread":{"id":"57816","subject":"Getting an odd diff","startedAt":"2022-04-29T12:33:41Z","lastAt":"2022-05-02T18:04:29Z","messageCount":3,"participants":["Jack Adrian Zappa","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"454616","messageId":"CAKepmahKwpe_YVrVrS0L3hMAu44W8VgbmvHY2LRpbrC6CQ0AKQ@mail.gmail.com","threadId":"57816","inReplyTo":null,"subject":"Getting an odd diff","fromName":"Jack Adrian Zappa","fromEmail":"adrianh.bsc@gmail.com","sentAt":"2022-04-29T12:33:26Z","receivedAt":"2022-04-29T12:33:41Z","isPatch":false,"sender":{"key":"adrianh.bsc@gmail.com","avatar":null},"body":"So, I have a regex to select words so that I can focus on the actual\nchanges.  But then I noticed that it did something weird.  It grouped\nsome parenthesis with another word.  I generated a minimal example for\nthat line and it was reproducible.\n\nBefore:\nvar result = ((res.State == ResultState.Succeeded) &&\nstring.IsNullOrEmpty(res.ErrorCode) )? (byte)0 : (byte)1;\n\nAfter:\nvar result = res.State == ResultState.Succeeded ? (byte)0 : (byte)1;\n\nDiff:\n$ git diff2 --no-index b a\nwarning: LF will be replaced by CRLF in b.\nThe file will have its original line endings in your working directory\nwarning: LF will be replaced by CRLF in a.\nThe file will have its original line endings in your working directory\ndiff --git a/b b/a\nindex 4e3604a8e..619d21e4e 100644\n--- a/b\n+++ b/a\n@@ -1 +1 @@\nvar result = [-((res-]{+res+}.State == ResultState.Succeeded[-) &&\nstring.IsNullOrEmpty(res.ErrorCode) )-] ? (byte)0 : (byte)1;\n\nI tried to make a smaller example and it didn't cause the issue.\n\nBefore:\nvar abc = ((xyz.Stuff == other_stuff) && stuff.yay(question) ? yes : no;\n\nAfter:\nvar abc = xyz.Stuff == other_stuff ? yes : no;\n\nDiff:\n$ git diff2 --no-index b a\nwarning: LF will be replaced by CRLF in b.\nThe file will have its original line endings in your working directory\nwarning: LF will be replaced by CRLF in a.\nThe file will have its original line endings in your working directory\ndiff --git a/b b/a\nindex df18ca34e..1024d6b68 100644\n--- a/b\n+++ b/a\n@@ -1 +1 @@\nvar abc =[-((-] xyz.Stuff == other_stuff[-) && stuff.yay(question)-] ? yes : no;\n\nSo, my question is, what's going on here?\n\nThe alias is as follows:\n     diff2 = diff --color=always --ignore-space-change\n'--word-diff-regex=((\\\\r\\\\n?|\\\\n\\\\r?)[\\\\t\n]*)?([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?)?'\n-p\n\nThanks,\n\n\nJAZ\nJAZ\n"},{"id":"454676","messageId":"1c11f705-596f-9e51-8017-2b59cac5f19d@kdbg.org","threadId":"57816","inReplyTo":"CAKepmahKwpe_YVrVrS0L3hMAu44W8VgbmvHY2LRpbrC6CQ0AKQ@mail.gmail.com","subject":"Re: Getting an odd diff","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2022-04-30T07:16:27Z","receivedAt":"2022-04-30T07:16:36Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 29.04.22 um 14:33 schrieb Jack Adrian Zappa:\n> So, I have a regex to select words so that I can focus on the actual\n> changes.  But then I noticed that it did something weird.  It grouped\n> some parenthesis with another word.  I generated a minimal example for\n> that line and it was reproducible.\n> \n> Before:\n> var result = ((res.State == ResultState.Succeeded) &&\n> string.IsNullOrEmpty(res.ErrorCode) )? (byte)0 : (byte)1;\n> \n> After:\n> var result = res.State == ResultState.Succeeded ? (byte)0 : (byte)1;\n> \n> Diff:\n> $ git diff2 --no-index b a\n> warning: LF will be replaced by CRLF in b.\n> The file will have its original line endings in your working directory\n> warning: LF will be replaced by CRLF in a.\n> The file will have its original line endings in your working directory\n> diff --git a/b b/a\n> index 4e3604a8e..619d21e4e 100644\n> --- a/b\n> +++ b/a\n> @@ -1 +1 @@\n> var result = [-((res-]{+res+}.State == ResultState.Succeeded[-) &&\n> string.IsNullOrEmpty(res.ErrorCode) )-] ? (byte)0 : (byte)1;\n> \n> I tried to make a smaller example and it didn't cause the issue.\n> \n> Before:\n> var abc = ((xyz.Stuff == other_stuff) && stuff.yay(question) ? yes : no;\n> \n> After:\n> var abc = xyz.Stuff == other_stuff ? yes : no;\n> \n> Diff:\n> $ git diff2 --no-index b a\n> warning: LF will be replaced by CRLF in b.\n> The file will have its original line endings in your working directory\n> warning: LF will be replaced by CRLF in a.\n> The file will have its original line endings in your working directory\n> diff --git a/b b/a\n> index df18ca34e..1024d6b68 100644\n> --- a/b\n> +++ b/a\n> @@ -1 +1 @@\n> var abc =[-((-] xyz.Stuff == other_stuff[-) && stuff.yay(question)-] ? yes : no;\n> \n> So, my question is, what's going on here?\n> \n> The alias is as follows:\n>      diff2 = diff --color=always --ignore-space-change\n> '--word-diff-regex=((\\\\r\\\\n?|\\\\n\\\\r?)[\\\\t\n> ]*)?([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?)?'\n> -p\n\nI am a bit reluctant to diagnose what exactly is happening here because\nyour word regex is outside the design space. It is definitely not a good\nidea to declare whitespace and even line breaks as part of a word. And\nin fact, when you remove the trailing (\\\\r\\\\n?|\\\\n\\\\r?)?, you get a more\nsensible word diff:\n\nvar result =[-((-] resx.State == ResultState.Succeeded[-) &&-]\n[-string.IsNullOrEmpty(res.ErrorCode) )-] ? (byte)0 : (byte)1;\n\nBut if I were you, I would remove all subexpressions that match any form\nof whitespace.\n\n-- Hannes\n"},{"id":"454736","messageId":"CAKepmahchaMVvOoWhnHzeBzKoYEHvmMJgHJ6fNBJ6C8bKMDjrA@mail.gmail.com","threadId":"57816","inReplyTo":"1c11f705-596f-9e51-8017-2b59cac5f19d@kdbg.org","subject":"Re: Getting an odd diff","fromName":"Jack Adrian Zappa","fromEmail":"adrianh.bsc@gmail.com","sentAt":"2022-05-02T18:04:14Z","receivedAt":"2022-05-02T18:04:29Z","isPatch":false,"sender":{"key":"adrianh.bsc@gmail.com","avatar":null},"body":"On Sat, Apr 30, 2022 at 3:16 AM Johannes Sixt <j6t@kdbg.org> wrote:\n> I am a bit reluctant to diagnose what exactly is happening here because\n> your word regex is outside the design space. It is definitely not a good\n> idea to declare whitespace and even line breaks as part of a word. And\n> in fact, when you remove the trailing (\\\\r\\\\n?|\\\\n\\\\r?)?, you get a more\n> sensible word diff:\n>\n> var result =[-((-] resx.State == ResultState.Succeeded[-) &&-]\n> [-string.IsNullOrEmpty(res.ErrorCode) )-] ? (byte)0 : (byte)1;\n>\n> But if I were you, I would remove all subexpressions that match any form\n> of whitespace.\n\nInteresting... IIRC, the reason for the leading and trailing line\nbreaks in the regex is to stop the diff from messing up the alignment\nof multiple edited lines.  I don't remember the exact sequence I was\nseeing, but removing them doesn't appear to mess up the alignment so\nbadly anymore.  Still, I'm surprised that removing that trailing line\nbreak capture would have caused the issue seen here.  For now, I'll\nremove the captures and if I see what I was seeing before, I'll report\nback to the group.\n\nThanks,\n\n\nJaz\n"}]}