在补丁文件中突出显示添加/删除的行,忽略移动 [英] Highlighting added/deleted lines, ignoring moves, in a patch file
本文介绍了在补丁文件中突出显示添加/删除的行,忽略移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在审核一个移动了很多东西的补丁,添加了一些东西,并删除了一些东西。我想知道是否有人编写了一个实用程序来挑选通用差异中的唯一添加/删除?
也就是说,添加和删除同一行应该
显然这并不是一直有用,但有时它正是我想要的:)
解决方案
这是我最终使用的。
示例用法:
git diff -w | /path/to/ignore_moves.py | -R
ignore_moves.py
#!/ usr / bin / python
itertools导入sys
导入*
RED = 31
GREEN = 32
RESET_SEQ =\033 [0m
COLOR_SEQ =\033 [0;%dm
stack = []
def (line):
return(' - 'if line [0] =='+'else'+')+ line [1:]。strip()
$ b $ def reverse_enumerate( l):
for i,x in枚举(反转(l)):
yield len(l)-1 -i,x
def dumpchanges():
为行中的堆栈:
SEQ = COLOR_SEQ%(如果line.startswith('+')其他RED)
打印SEQ + line.strip()+ RESET_SEQ
堆栈[: ] = []
为sys.stdin.readlines()中的行:
if line [1:]。strip():
continue#ignore空行
如果line.startswith(('---','+++')):
dumpchanges()
print line.strip()
elif line.startswith ('+',' - ')):
inverted = inverse(line)
line = line [0] + line [1:]。strip()
for i,match in reverse_enumerate(stack):
if == match:
stack.pop(i)
break
else:
stack.append(line)
#读完,仍然有状态被转储
dumpchanges()
I'm reviewing a patch that moved a lot of things around, added a few things, and removed a few things. I'm wondering if anyone's written a utility for picking out the unique adds/removes in a universal diff?
That is, an add and a remove of the same line should cancel themselves out.
Obviously this isn't useful all the time, but sometimes it's exactly what I want :)
解决方案
This is what I ended up using.
Example usage:
git diff -w | /path/to/ignore_moves.py | less -R
ignore_moves.py
#!/usr/bin/python
import sys
from itertools import *
RED = 31
GREEN = 32
RESET_SEQ = "\033[0m"
COLOR_SEQ = "\033[0;%dm"
stack = []
def inverse(line):
return ('-' if line[0] == '+' else '+') + line[1:].strip()
def reverse_enumerate(l):
for i, x in enumerate(reversed(l)):
yield len(l)-1-i, x
def dumpchanges():
for line in stack:
SEQ = COLOR_SEQ % (GREEN if line.startswith('+') else RED)
print SEQ + line.strip() + RESET_SEQ
stack[:] = []
for line in sys.stdin.readlines():
if not line[1:].strip():
continue # ignore empty lines
if line.startswith(('---', '+++')):
dumpchanges()
print line.strip()
elif line.startswith(('+', '-')):
inverted = inverse(line)
line = line[0] + line[1:].strip()
for i, match in reverse_enumerate(stack):
if inverted == match:
stack.pop(i)
break
else:
stack.append(line)
# finished reading, still have state to be dumped
dumpchanges()
这篇关于在补丁文件中突出显示添加/删除的行,忽略移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文