[PATCH] D147301: [lit] Implement -I option for builtin "diff" command to ignore changes where all lines match RE
Bing Yu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 4 04:49:28 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG22068a3d4b1a: [lit] Implement -I option for builtin "diff" command to ignore changes where… (authored by yubing).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147301/new/
https://reviews.llvm.org/D147301
Files:
llvm/utils/lit/lit/builtin_commands/diff.py
llvm/utils/lit/tests/Inputs/shtest-shell/diff-I.txt
Index: llvm/utils/lit/tests/Inputs/shtest-shell/diff-I.txt
===================================================================
--- /dev/null
+++ 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
Index: llvm/utils/lit/lit/builtin_commands/diff.py
===================================================================
--- llvm/utils/lit/lit/builtin_commands/diff.py
+++ 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":
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147301.510747.patch
Type: text/x-patch
Size: 2361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230404/938e6127/attachment.bin>
More information about the llvm-commits
mailing list