|
|
@ -2,22 +2,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
import difflib
|
|
|
|
import difflib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def same_slicer(l, a, b):
|
|
|
|
|
|
|
|
if a == b:
|
|
|
|
|
|
|
|
return [l[a]]
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return l[a:b]
|
|
|
|
|
|
|
|
|
|
|
|
# like .compare but a little different output
|
|
|
|
# like .compare but a little different output
|
|
|
|
def customSequenceMatcher(before, after, include_equal=False):
|
|
|
|
def customSequenceMatcher(before, after, include_equal=False):
|
|
|
|
cruncher = difflib.SequenceMatcher(isjunk=lambda x: x in " \\t", a=before, b=after)
|
|
|
|
cruncher = difflib.SequenceMatcher(isjunk=lambda x: x in " \\t", a=before, b=after)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @todo Line-by-line mode instead of buncghed, including `after` that is not in `before` (maybe unset?)
|
|
|
|
for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
|
|
|
|
for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
|
|
|
|
if include_equal and tag == 'equal':
|
|
|
|
if include_equal and tag == 'equal':
|
|
|
|
g = before[alo:ahi]
|
|
|
|
g = before[alo:ahi]
|
|
|
|
yield g
|
|
|
|
yield g
|
|
|
|
elif tag == 'delete':
|
|
|
|
elif tag == 'delete':
|
|
|
|
g = "(removed) {}".format(before[alo])
|
|
|
|
g = ["(removed) " + i for i in same_slicer(before, alo, ahi)]
|
|
|
|
yield g
|
|
|
|
yield g
|
|
|
|
elif tag == 'replace':
|
|
|
|
elif tag == 'replace':
|
|
|
|
g = ["(changed) {}".format(before[alo]), "(-> into) {}".format(after[blo])]
|
|
|
|
g = ["(changed) " + i for i in same_slicer(before, alo, ahi)]
|
|
|
|
|
|
|
|
g += ["(into ) " + i for i in same_slicer(after, blo, bhi)]
|
|
|
|
yield g
|
|
|
|
yield g
|
|
|
|
elif tag == 'insert':
|
|
|
|
elif tag == 'insert':
|
|
|
|
g = "(added) {}".format(after[blo])
|
|
|
|
g = ["(added ) " + i for i in same_slicer(after, blo, bhi)]
|
|
|
|
yield g
|
|
|
|
yield g
|
|
|
|
|
|
|
|
|
|
|
|
# only_differences - only return info about the differences, no context
|
|
|
|
# only_differences - only return info about the differences, no context
|
|
|
|