diff mbox series

[08/11] patchtest: mbox.py: improve 'From' line matching

Message ID 20260514194207.1958325-9-tgamblin@baylibre.com
State New
Headers show
Series patchtest: improve testing coverage | expand

Commit Message

Trevor Gamblin May 14, 2026, 7:42 p.m. UTC
It's possible that a patch's commit message includes a line that begins
with 'From' to indicate a range, where a change's inspiration came from,
and so on. The current patchtest logic automatically splits on anything
that looks this way, which results in an error thrown due to missing
context in the diff list. Add a new regex pattern matching the typical
'From' line format in patch files so that patchtest splits on the
correct text.

AI-Generated: Uses Claude Code

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
---
 meta/lib/patchtest/mbox.py               | 3 ++-
 meta/lib/patchtest/patchtest_patterns.py | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/lib/patchtest/mbox.py b/meta/lib/patchtest/mbox.py
index 2342fbda65..990ae02109 100644
--- a/meta/lib/patchtest/mbox.py
+++ b/meta/lib/patchtest/mbox.py
@@ -11,6 +11,7 @@ 
 #
 
 import email
+import patchtest_patterns
 import re
 
 # From: https://stackoverflow.com/questions/59681461/read-a-big-mbox-file-with-python
@@ -32,7 +33,7 @@  class MboxReader:
         lines = []
         while True:
             line = self.handle.readline()
-            if line == b'' or line.startswith(b'From '):
+            if line == b'' or patchtest_patterns.mbox_from.match(line):
                 yield email.message_from_bytes(b''.join(lines))
                 if line == b'':
                     break
diff --git a/meta/lib/patchtest/patchtest_patterns.py b/meta/lib/patchtest/patchtest_patterns.py
index b3478d2f0f..e12e85c65b 100644
--- a/meta/lib/patchtest/patchtest_patterns.py
+++ b/meta/lib/patchtest/patchtest_patterns.py
@@ -61,6 +61,10 @@  mbox_cover_letter_regex = pyparsing.Regex(r'\[\S+\s+0+/\d+\]')
 mbox_shortlog_maxlength = 90
 # based on https://stackoverflow.com/questions/30281026/regex-parsing-github-usernames-javascript
 mbox_github_username = pyparsing.Regex(r'\B(?<!\${)@([a-z0-9](?:-(?=[a-z0-9])|[a-z0-9]){0,38}(?<=[a-z0-9]))')
+# Standard mbox From_ separator line: "From <addr> Www Mmm [D]D HH:MM:SS YYYY"
+mbox_from = re.compile(
+    rb'^From \S+ \w{3} \w{3} [ \d]\d \d{2}:\d{2}:\d{2} \d{4}'
+)
 
 # patch