qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Cleber Rosa" <crosa@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"John Snow" <jsnow@redhat.com>
Subject: [RFC PATCH 8/9] scripts/get_maintainer.py: add support reading patch files
Date: Thu, 11 Dec 2025 18:01:31 +0000	[thread overview]
Message-ID: <20251211180132.3186564-9-alex.bennee@linaro.org> (raw)
In-Reply-To: <20251211180132.3186564-1-alex.bennee@linaro.org>

Not so different from individual files, we just need to parse the
patch looking for the files and add them to the list. As we can parse
multiple patches we also need to ensure the final list of sections is
unique so we don't repeat ourselves.

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

diff --git a/scripts/get_maintainer.py b/scripts/get_maintainer.py
index bf45865438e..daeefecef64 100755
--- a/scripts/get_maintainer.py
+++ b/scripts/get_maintainer.py
@@ -15,6 +15,7 @@
 from pathlib import Path
 from enum import StrEnum, auto
 from re import compile as re_compile
+from re import sub as re_sub
 
 #
 # Subsystem MAINTAINER entries
@@ -187,6 +188,29 @@ def read_maintainers(src):
 
     return entries
 
+#
+# 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):
+    """
+    Read a patchfile and return a list of files which are modified by
+    the patch.
+    """
+    file_list = []
+
+    with open(patchfile, 'r', encoding='utf-8') as f:
+        for line in f:
+            m = patchfile_re.match(line)
+            if m:
+                # strip leading [ab]/
+                stripped = re_sub(r'^[^/]*/', '', m.group(1))
+                as_path = Path(path.abspath(stripped))
+                file_list.append(as_path)
+
+    return file_list
 
 #
 # Helper functions for dealing with the source path
@@ -305,14 +329,27 @@ def main():
         print(f"loaded {len(maint_sections)} from MAINTAINERS")
         exit(0)
 
-    relevent_maintainers = None
+    # Build array of Path objects representing the files
+    files = []
 
     if args.file:
-        relevent_maintainers = [ms for ms in maint_sections if
-                                ms.is_file_covered(args.file)]
+        files.append(args.file)
+
+    if args.patch:
+        for p in args.patch:
+            pfiles = extract_filenames_from_patch(p)
+            files.extend(pfiles)
+
+    # unique set of maintainer sections
+    maintained: set[MaintainerSection] = set()
+
+    for f in files:
+        fmaint = [ms for ms in maint_sections if ms.is_file_covered(f)]
+        for m in fmaint:
+            maintained.add(m)
 
-    for rm in relevent_maintainers:
-        print(rm)
+    for rm in maintained:
+        print(str(rm))
 
 
 if __name__ == '__main__':
-- 
2.47.3



  parent reply	other threads:[~2025-12-11 18:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 18:01 [RFC PATCH 0/9] for 11.0 conversion* of get_maintainers.pl to python Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 1/9] MAINTAINERS: fix missing names Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 2/9] MAINTAINERS: fix libvirt entry Alex Bennée
2025-12-12  6:45   ` Philippe Mathieu-Daudé
2025-12-12 11:00     ` Alex Bennée
2025-12-12 11:12       ` Ján Tomko
2025-12-11 18:01 ` [RFC PATCH 3/9] MAINTAINERS: regularise the status fields Alex Bennée
2025-12-12  6:43   ` Philippe Mathieu-Daudé
2025-12-11 18:01 ` [RFC PATCH 4/9] scripts/get_maintainer.py: minimal argument parsing Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 5/9] scripts/get_maintainer.py: resolve the source path Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 6/9] scripts/get_maintainer.py: initial parsing of MAINTAINERS Alex Bennée
2025-12-11 18:01 ` [RFC PATCH 7/9] scripts/get_maintainer.py: add support for -f Alex Bennée
2025-12-11 18:01 ` Alex Bennée [this message]
2025-12-11 18:01 ` [RFC PATCH 9/9] gitlab: add a check-maintainers task Alex Bennée
2025-12-12  8:15 ` [RFC PATCH 0/9] for 11.0 conversion* of get_maintainers.pl to python Daniel P. Berrangé
2025-12-12 11:00   ` Alex Bennée
2025-12-12 11:25     ` Peter Maydell
2025-12-12 11:27 ` Peter Maydell
2025-12-12 14:38 ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251211180132.3186564-9-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=crosa@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).