parse word-diff hidding whitespace or newline changes
This commit is contained in:
commit
848e6f833b
20
README.md
Normal file
20
README.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# word-diff-filter
|
||||
|
||||
Dealing with diff is a hard thing. You want to focus on big picture, what changes, what matters, but there's a lot to remove from a simple diff to make it usable (at least for a review)
|
||||
|
||||
Alghorithms like patience try to reorder diffs but thats not enough.
|
||||
|
||||
One of the most disrupting noise inside diffs is about indentation changes. They generate a lot of attention in a diff but in almost all code they are just a step further to ignore-whitespace, I want to take that step!
|
||||
|
||||
By now this is a filter for **git diff --word-diff=porcelain** which works on **--color** or plain output, I will work to provide an ecosystem to ease it use.
|
||||
|
||||
#Test
|
||||
|
||||
```bash
|
||||
$ git clone albfan:word-diff-filter
|
||||
$ cd word-diff-filter
|
||||
$ ln -s $(pwd)/word-diff-filter.py ~/bin/word-diff-filter
|
||||
$ cd <path-to-your-repo>
|
||||
$ git diff --word-diff=porcelain --color master feature | word-diff-filter
|
||||
```
|
||||
|
46
filter-word-diff.py
Executable file
46
filter-word-diff.py
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
header = ""
|
||||
chunk = ""
|
||||
add = 0
|
||||
change = False
|
||||
|
||||
COLOR="(\x1b\[\d*m)?"
|
||||
def printChunk():
|
||||
global header, chunk, change
|
||||
if change:
|
||||
if header:
|
||||
print(header)
|
||||
header = ""
|
||||
print(chunk)
|
||||
chunk = ""
|
||||
change = False
|
||||
|
||||
for line in sys.stdin:
|
||||
if re.match("^"+COLOR+"diff --git", line):
|
||||
printChunk()
|
||||
header = ""
|
||||
add = 5
|
||||
|
||||
if (add > 0):
|
||||
header += line
|
||||
add -= 1
|
||||
continue
|
||||
|
||||
if re.match("^"+COLOR+"~", line):
|
||||
continue
|
||||
|
||||
if re.match("^"+COLOR+"@@", line):
|
||||
#new chunk. does the actual contains a change
|
||||
printChunk()
|
||||
|
||||
chunk += line
|
||||
|
||||
if not change:
|
||||
change = re.match("^"+COLOR+"\+", line) or re.match("^"+COLOR+"-", line)
|
||||
|
||||
printChunk()
|
||||
|
Loading…
Reference in New Issue
Block a user