git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Getting an odd diff

From
JZJack Adrian Zappa <adrianh.bsc@gmail.com>
Date
Apr 29, 2022, 12:33 UTC
Message-ID
<CAKepmahKwpe_YVrVrS0L3hMAu44W8VgbmvHY2LRpbrC6CQ0AKQ@mail.gmail.com>

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
Next: Johannes Sixt
Message 1 of 3 in “Getting an odd diff”
  1. Jack Adrian ZappaApr 29, 2022
  2. Johannes SixtApr 30, 2022
  3. Jack Adrian ZappaMay 2, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.