import io
import locale
import os
+import re
import sys
import util
def __init__(self):
self.ignore_all_space = False
self.ignore_space_change = False
+ self.ignore_matching_lines = False
+ self.ignore_matching_lines_regex = ""
self.unified_diff = False
self.num_context_lines = 3
self.recursive_diff = False
f = compose2(ignoreAllSpaceOrSpaceChange, f)
for idx, lines in enumerate(filelines):
+ if flags.ignore_matching_lines:
+ lines = filter(lambda x: not re.match(r"{}".format(flags.ignore_matching_lines_regex), x), lines)
filelines[idx]= [f(line) for line in lines]
func = difflib.unified_diff if flags.unified_diff else difflib.context_diff
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
args = argv[1:]
try:
- opts, args = getopt.gnu_getopt(args, "wbuU:r", ["strip-trailing-cr"])
+ opts, args = getopt.gnu_getopt(args, "wbuI:U:r", ["strip-trailing-cr"])
except getopt.GetoptError as err:
sys.stderr.write("Unsupported: 'diff': %s\n" % str(err))
sys.exit(1)
sys.stderr.write("Error: invalid '-U' argument: {}\n"
.format(a))
sys.exit(1)
+ elif o == "-I":
+ flags.ignore_matching_lines = True
+ flags.ignore_matching_lines_regex = a
elif o == "-r":
flags.recursive_diff = True
elif o == "--strip-trailing-cr":
--- /dev/null
+# Check diff ("diff -I") which is aimed to ignore changes where all lines match RE.
+
+# RUN: echo 'foo' > %t.0
+# RUN: echo 'bar1' >> %t.0
+# RUN: echo 'foo' >> %t.0
+
+# RUN: echo 'foo' > %t.1
+# RUN: echo 'bar2' >> %t.1
+# RUN: echo 'foo' >> %t.1
+
+# RUN: diff -I "bar*" %t.0 %t.1
\ No newline at end of file