diff --git a/llvm/utils/lit/lit/builtin_commands/diff.py b/llvm/utils/lit/lit/builtin_commands/diff.py --- a/llvm/utils/lit/lit/builtin_commands/diff.py +++ b/llvm/utils/lit/lit/builtin_commands/diff.py @@ -4,6 +4,7 @@ import io import locale import os +import re import sys import util @@ -13,6 +14,8 @@ 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 @@ -95,6 +98,8 @@ 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 @@ -190,7 +195,7 @@ 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) @@ -214,6 +219,9 @@ 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": diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell/diff-I.txt b/llvm/utils/lit/tests/Inputs/shtest-shell/diff-I.txt new file mode 100644 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-shell/diff-I.txt @@ -0,0 +1,11 @@ +# 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