[RFC PATCH v2 14/16] scripts/get_maintainer.py: add keyword (K:) support

Alex Bennée posted 16 patches 1 day, 19 hours ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Thomas Huth <thuth@redhat.com>, John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>
[RFC PATCH v2 14/16] scripts/get_maintainer.py: add keyword (K:) support
Posted by Alex Bennée 1 day, 19 hours ago
We use the regex module to stay compatible with the Perl compatible
regex used in the MAINTAINERS file.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 scripts/get_maintainer.py | 36 +++++++++++++++++++++++++++---------
 1 file changed, 27 insertions(+), 9 deletions(-)

diff --git a/scripts/get_maintainer.py b/scripts/get_maintainer.py
index f46d8f6e073..b41f5342876 100755
--- a/scripts/get_maintainer.py
+++ b/scripts/get_maintainer.py
@@ -16,6 +16,7 @@
 from enum import StrEnum, auto
 from re import compile as re_compile
 from re import sub as re_sub
+from regex import compile as prec_compile
 
 #
 # Subsystem MAINTAINER entries
@@ -124,7 +125,8 @@ def __init__(self, section, entries):
             elif tag == 'W':
                 self.web.append(data)
             elif tag == 'K':
-                self.keywords.append(data)
+                match = prec_compile(data)
+                self.keywords.append(match)
             elif tag == 'T':
                 self.trees.append(data)
             elif tag == 'X':
@@ -160,6 +162,15 @@ def is_file_covered(self, filename):
 
         return False
 
+    def patch_contains_keyword(self, patch_lines):
+        "Does patch contain keyword covered by this maintainer section"
+
+        for l in patch_lines:
+            for k in self.keywords:
+                if k.findall(l):
+                    return True
+
+        return False
 
 def read_maintainers(src):
     """
@@ -194,18 +205,22 @@ def read_maintainers(src):
 #
 # Helper functions for dealing with patch files
 #
+
+
 patchfile_re = re_compile(r"\+\+\+\s+(\S+)")
 
-#TODO: also return a list of keyword hits for K:?
-def extract_filenames_from_patch(patchfile):
+
+def process_patch_file(patchfile):
     """
-    Read a patchfile and return a list of files which are modified by
+    Read a patchfile and return the message as a string and a list of files which are modified by
     the patch.
     """
     file_list = []
+    msg = []
 
     with open(patchfile, 'r', encoding='utf-8') as f:
         for line in f:
+            msg.append(line)
             m = patchfile_re.match(line)
             if m:
                 # strip leading [ab]/
@@ -213,7 +228,7 @@ def extract_filenames_from_patch(patchfile):
                 as_path = Path(path.abspath(stripped))
                 file_list.append(as_path)
 
-    return file_list
+    return (msg, file_list)
 
 #
 # Helper functions for dealing with the source path
@@ -335,13 +350,16 @@ def main():
     if args.file:
         files.append(args.file)
 
+    # unique set of maintainer sections
+    maintained: set[MaintainerSection] = set()
+
     if args.patch:
         for p in args.patch:
-            pfiles = extract_filenames_from_patch(p)
+            (msg, pfiles) = process_patch_file(p)
             files.extend(pfiles)
-
-    # unique set of maintainer sections
-    maintained: set[MaintainerSection] = set()
+            kmaint = [ms for ms in maint_sections if ms.patch_contains_keyword(msg)]
+            for m in kmaint:
+                maintained.add(m)
 
     for f in files:
         fmaint = [ms for ms in maint_sections if ms.is_file_covered(f)]
-- 
2.47.3