[llvm] 22068a3 - [lit] Implement -I option for builtin "diff" command to ignore changes where all lines match RE
Bing1 Yu via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 4 04:49:21 PDT 2023
Author: Bing1 Yu
Date: 2023-04-04T19:49:12+08:00
New Revision: 22068a3d4b1a2eb5908654d9b2957a03c0f527b6
URL: https://github.com/llvm/llvm-project/commit/22068a3d4b1a2eb5908654d9b2957a03c0f527b6
DIFF: https://github.com/llvm/llvm-project/commit/22068a3d4b1a2eb5908654d9b2957a03c0f527b6.diff
LOG: [lit] Implement -I option for builtin "diff" command to ignore changes where all lines match RE
Reviewed By: pengfei
Differential Revision: https://reviews.llvm.org/D147301
Added:
llvm/utils/lit/tests/Inputs/shtest-shell/diff-I.txt
Modified:
llvm/utils/lit/lit/builtin_commands/diff.py
Removed:
################################################################################
diff --git a/llvm/utils/lit/lit/builtin_commands/
diff .py b/llvm/utils/lit/lit/builtin_commands/
diff .py
index a12e5e100b1bd..1b96a1504e5c1 100644
--- 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 @@ class DiffFlags():
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 @@ def compose2(f, g):
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 =
diff lib.unified_
diff if flags.unified_
diff else
diff lib.context_
diff
@@ -190,7 +195,7 @@ def main(argv):
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 @@ def main(argv):
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
index 0000000000000..c1817fd1e90e5
--- /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
More information about the llvm-commits
mailing list