Is "git diff --word-diff" ambigious with respect to newlines?

116 Views Asked by At

I am trying to parse git diff, and I am confident I am able to do so unambigiously with the plain command (no word-diff). I would like to include word-diff, but am having trouble understanding the rules, specifically in regards to new lines.

For example, plain diff might give me an output like this:

-using LongNameSpace.LongMessages.InternalMessages.Amazon;
-using LongNameSpace.Voice;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Linq;
using NameSpace.Common.Enums;

While the same piece of code with word-diff=plain is:

[-using LongNameSpace.LongMessages.InternalMessages.Amazon;-]using [-LongNameSpace.Voice;-]{+System;+}
{+using System.Collections.Generic;+}
{+using System.Data;+}
{+using System.Linq;+}
using NameSpace.Common.Enums;

My issue is with the first line of the word-diff version. Programmatically, how am I supposed to know that a newline is being removed as part of the first line at the end of the first using, and not that the first and second usings both shared the same line?

1

There are 1 best solutions below

0
Lazy Badger On

As noted in --word-diff doc

By default, words are delimited by whitespace; see --word-diff-regex below.

and only using special (proper) --word-diff-regex you can add support of EOL as word-delimiters.

But yes, as @torek wrote, it doesn't help you with programmatic solution, --word-diff is "only for your eyes"