Skip to contentSkip to conversation

Fix mail addresses parsing from `L:` entries in MAINTAINER file

PATCH Applied Clément Le Goffic 2 participants 4 messages Sep 25 – Oct 5

lore
Share & tools
lore
#0 lore raw

cover Fix mail addresses parsing from `L:` entries in MAINTAINER file

While testing the new maintainer container[1] tool, I subscribed to my prefered mailing list but I ended up not having the same mails as in my local inbox folder.
After investigating a little bit with an LLM tool, it found an issue in the MAINTAINER file entry parsing.

Patch 1: Fix the parsing issue
Patch 2: Refactor the code path

[1]: https://llore.docs.kernel.org/en/latest/

---
Clément Le Goffic (2):
Drop the comment from a MAINTAINERS L: line before querying lei Fold the M:, R: and L: branches into one table lookup

 CHANGELOG                    | 10 ++++++++
 src/korgalore/maintainers.py | 24 ++++++++++++-------
 tests/test_maintainers.py    | 56 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 81 insertions(+), 9 deletions(-)

---
base-commit: 29151623085919f57710589efdde80cb5115baa3
change-id: 20260925-fix-list-comment-08737d544b85

Best regards,

Signature · 1 line
Clément Le Goffic <[email protected]>
#1 lore raw

PATCH 1/2 Drop the comment from a MAINTAINERS L: line before querying lei

An L: line may carry a comment after the address, and most infradead lists do:
'[email protected] (moderated for non-subscribers)' The value was stored as written and turned into a lei term by replacing the `@', so the query became:

l:linux-arm-kernel.lists.infradead.org (moderated for non-subscribers)

which asks for messages on the list that also contain those words.

Parse L: through extract_email() the way M: and R: already are. parseaddr treats the parenthesised text as an RFC 822 comment and returns the bare address for every form the current MAINTAINERS uses.

Assisted-by LLM [analysis, codegen, tests]
---
 CHANGELOG                    |  7 +++++++
 src/korgalore/maintainers.py |  7 +++++--
 tests/test_maintainers.py    | 23 +++++++++++++++++++++++
 3 files changed, 35 insertions(+), 2 deletions(-)
CHANGELOG +7 -0
index 859a70684c99..fe96273605eb 100644
@@ -99,6 +99,13 @@ Refactoring
 Bug Fixes
 ~~~~~~~~~
 
+* A comment on a MAINTAINERS ``L:`` line, such as ``(moderated for
+  non-subscribers)``, is no longer passed to lei as search terms. Every
+  list carrying one was reduced to the few threads that happened to
+  contain those words instead of the whole list. ``main.catchall_lists``
+  is now matched against the bare address too, so an entry written with
+  the comment no longer matches.
+
 * A Message-ID with a trailing comment no longer defeats duplicate
   detection
 
src/korgalore/maintainers.py +5 -2
index 28b9eca3c6cb..69d3e2e09a73 100644
@@ -97,12 +97,13 @@ def normalize_subsystem_name(name: str) -> str:
 
 
 def extract_email(line: str) -> Optional[str]:
-    """Extract email address from a maintainer/reviewer line.
+    """Extract email address from a maintainer, reviewer or list line.
 
     Handles formats like:
         'Full Name <[email protected]>'
         '"Full Name" <[email protected]>'
         '[email protected]'
+        '[email protected] (moderated for non-subscribers)'
     """
     _, email = parseaddr(line)
     return email if email else None
@@ -194,7 +195,9 @@ def parse_maintainers(path: Path) -> Dict[str, SubsystemEntry]:
                         if email:
                             current_entry.reviewers.append(email)
                     elif prefix == 'L':
-                        current_entry.mailing_lists.append(value)
+                        email = extract_email(value)
+                        if email:
+                            current_entry.mailing_lists.append(email)
                     elif prefix == 'F':
                         current_entry.files.append(value)
                     elif prefix == 'X':
tests/test_maintainers.py +23 -0
index 217cb1b3fbd7..8926009be90c 100644
@@ -63,6 +63,10 @@ class TestExtractEmail:
         """Extracts email when name is quoted."""
         assert extract_email('"John Doe" <[email protected]>') == '[email protected]'
 
+    def test_list_with_comment(self) -> None:
+        """Drops the comment MAINTAINERS puts after a list address."""
+        assert extract_email('[email protected] (moderated for non-subscribers)') == '[email protected]'
+
     def test_bare_email(self) -> None:
         """Handles bare email addresses without angle brackets."""
         assert extract_email('[email protected]') == '[email protected]'
@@ -562,6 +566,25 @@ F:\tnet/9p/
         assert 'fs/9p/' in entry.files
         assert 'net/9p/' in entry.files
 
+    def test_parse_list_with_comment(self, tmp_path: Path) -> None:
+        """A comment after an L: address is dropped, not searched for."""
+        maintainers = tmp_path / 'MAINTAINERS'
+        maintainers.write_text("""
+ARM SUB-ARCHITECTURES
+M:\tArnd Bergmann <[email protected]>
+L:\[email protected] (moderated for non-subscribers)
+L:\[email protected]\t(subscribers-only)
+S:\tMaintained
+F:\tarch/arm/mach-*/
+""")
+        entry = parse_maintainers(maintainers)['ARM SUB-ARCHITECTURES']
+        assert entry.mailing_lists == [
+            '[email protected]',
+            '[email protected]',
+        ]
+        query, _ = build_mailinglist_query(entry, '30.days.ago')
+        assert query == '(l:linux-arm-kernel.lists.infradead.org OR l:pvrusb2.isely.net) AND d:30.days.ago..'
+
     def test_parse_multiple_subsystems(self, tmp_path: Path) -> None:
         """Parse multiple subsystem entries."""
         maintainers = tmp_path / 'MAINTAINERS'
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/2 Fold the M:, R: and L: branches into one table lookup

In reply to Clément Le Goffic

The three fields are parsed the same way -- extract_email() on the value, append what it returns -- and since the previous commit they are three copies of the same four lines. Three copies of one idea is how they drift.

Map each prefix to the list it fills and take the branch once. While here, say so when a line cannot be parsed: a maintainer or list line parseaddr rejects, such as two addresses on one line, was dropped without a word, and the only later symptom is an entry with no maintainers or a "No mailing lists found" warning that does not say why.

Assisted-by LLM [analysis, codegen, tests]
---
 CHANGELOG                    |  3 +++
 src/korgalore/maintainers.py | 23 +++++++++++++----------
 tests/test_maintainers.py    | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 10 deletions(-)
CHANGELOG +3 -0
index fe96273605eb..5766f2d2e4e7 100644
@@ -7,6 +7,9 @@ v0.7 (unreleased)
 Enhancements
 ~~~~~~~~~~~~
 
+* An ``M:``, ``R:`` or ``L:`` line in MAINTAINERS that cannot be parsed is
+  now reported in the log instead of being skipped silently
+
 * GUI: Add "About" dialog showing version, description, website, and license
 
 * HTTP failover and auto-probe for all lore.kernel.org requests
src/korgalore/maintainers.py +13 -10
index 69d3e2e09a73..bd84ea3a814f 100644
@@ -24,6 +24,14 @@ REGEX_METACHARACTERS = r'\[](){}|^$?+*'
 # Recognized SCM types for T: lines, per the MAINTAINERS file format.
 KNOWN_VCS_TYPES = {'git', 'hg', 'quilt', 'stgit', 'topgit'}
 
+# Fields whose value is an address, wrapped in a display name (M:, R:) or
+# followed by a comment (L:), mapped to the SubsystemEntry list it fills.
+EMAIL_FIELDS: Dict[str, str] = {
+    'M': 'maintainers',
+    'R': 'reviewers',
+    'L': 'mailing_lists',
+}
+
 
 @dataclass
 class Tree:
@@ -186,18 +194,13 @@ def parse_maintainers(path: Path) -> Dict[str, SubsystemEntry]:
                     prefix = line[0]
                     value = line[3:].strip()
 
-                    if prefix == 'M':
+                    if prefix in EMAIL_FIELDS:
                         email = extract_email(value)
                         if email:
-                            current_entry.maintainers.append(email)
-                    elif prefix == 'R':
-                        email = extract_email(value)
-                        if email:
-                            current_entry.reviewers.append(email)
-                    elif prefix == 'L':
-                        email = extract_email(value)
-                        if email:
-                            current_entry.mailing_lists.append(email)
+                            emails: List[str] = getattr(current_entry, EMAIL_FIELDS[prefix])
+                            emails.append(email)
+                        else:
+                            logger.warning('Ignoring unparsable %s: line in %s: %s', prefix, current_entry.name, value)
                     elif prefix == 'F':
                         current_entry.files.append(value)
                     elif prefix == 'X':
tests/test_maintainers.py +33 -0
index 8926009be90c..d33cd2d4f10d 100644
@@ -1,5 +1,6 @@
 """Tests for MAINTAINERS file parser and query builders."""
 
+import logging
 from pathlib import Path
 
 import pytest
@@ -585,6 +586,38 @@ F:\tarch/arm/mach-*/
         query, _ = build_mailinglist_query(entry, '30.days.ago')
         assert query == '(l:linux-arm-kernel.lists.infradead.org OR l:pvrusb2.isely.net) AND d:30.days.ago..'
 
+    def test_parse_unparsable_list_is_dropped(self, tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
+        """An L: line with no usable address is dropped, with a warning saying so."""
+        maintainers = tmp_path / 'MAINTAINERS'
+        maintainers.write_text("""
+BROKEN ENTRY
+M:\tSome One <[email protected]>
+L:\[email protected] (moderated for non-subscribers
+L:\[email protected]
+S:\tMaintained
+F:\tdrivers/broken/
+""")
+        with caplog.at_level(logging.WARNING, logger='korgalore'):
+            entry = parse_maintainers(maintainers)['BROKEN ENTRY']
+        assert entry.mailing_lists == ['[email protected]']
+        assert 'Ignoring unparsable L: line in BROKEN ENTRY' in caplog.text
+
+    def test_parse_unparsable_maintainer_warns(self, tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None:
+        """M: and R: lines get the same treatment as L: when they cannot be parsed."""
+        maintainers = tmp_path / 'MAINTAINERS'
+        maintainers.write_text("""
+BROKEN ENTRY
+M:\[email protected], [email protected]
+R:\tReviewer <[email protected]>
+S:\tMaintained
+F:\tdrivers/broken/
+""")
+        with caplog.at_level(logging.WARNING, logger='korgalore'):
+            entry = parse_maintainers(maintainers)['BROKEN ENTRY']
+        assert entry.maintainers == []
+        assert entry.reviewers == ['[email protected]']
+        assert 'Ignoring unparsable M: line in BROKEN ENTRY' in caplog.text
+
     def test_parse_multiple_subsystems(self, tmp_path: Path) -> None:
         """Parse multiple subsystem entries."""
         maintainers = tmp_path / 'MAINTAINERS'
Signature · 1 line
2.55.0
#3 lore raw
In reply to Clément Le Goffic
Quoted 9 lines · Clément Le Goffic

Fix mail addresses parsing from L: entries in MAINTAINER file

While testing the new maintainer container[1] tool, I subscribed to my prefered mailing list but I ended up not having the same mails as in my local inbox folder.
After investigating a little bit with an LLM tool, it found an issue in the MAINTAINER file entry parsing.

[...]

Applied, thanks!

[1/2] Drop the comment from a MAINTAINERS L: line before querying lei

      commit: 428baec86eb5adec79ae7931dca7055bb1bea5e0
[2/2] Fold the M:, R: and L: branches into one table lookup
      commit: e24b2bddd9ff7d4064a8f4ea4360f6f987e1ecc3

Best regards,

Signature · 1 line
Konstantin Ryabitsev <[email protected]>