skermes / review

3 stars 1 forks source link

Whitespace in the presence of --word-diff #2

Open skermes opened 12 years ago

ScottDugas commented 12 years ago

Relevant info from the man page: --word-diff[=]

Show a word diff, using the <mode> to delimit changed words. By default, words are delimited by whitespace; see --word-diff-regex below. The <mode> defaults to plain, and must be one of:

color

    Highlight changed words using only colors. Implies --color. 

plain

    Show words as [-removed-] and {+added+}. Makes no attempts to escape the delimiters if they appear in the input, so the output may be ambiguous. 

porcelain

    Use a special line-based format intended for script consumption. Added/removed/unchanged runs are printed in the usual unified diff format, starting with a +/-/ character at the beginning of the line and extending to the end of the line. Newlines in the input are represented by a tilde ~ on a line of its own. 

none

    Disable word diff again. 

Since plain is ambiguous, probably will need to use porcelain.

It looks like the ~ only accounts for newlines in both versions, or something

skermes commented 12 years ago

I dug into this a little more, and it looks like getting a nicely colorized word-level diff is decidedly non-trivial: http://www.spinics.net/lists/git/msg145186.html

As far as I could tell, none of the solutions in that thread (with the possible exception of the perl script here: http://www.spinics.net/lists/git/msg145893.html) had a good solution, only an explication of the problems. I haven't read the script closely enough to figure out how it works, or tried running it to see the output.

That said, the thread is over a year old, so there might have been some progress. Someone mentioned a --color-words option in gitk, which could be worth looking into.