Skip to contentSkip to conversation

Add support for presubject

PATCH Applied Louis Rannou 2 participants 4 messages Nov 13, 2025 – Nov 18, 2025

lore
Share & tools
lore
#0 lore raw

cover Add support for presubject

This takes the unmerged work from Antonin Godard <[email protected]> and adds the send-receive patch to accept presubjects.

---
Antonin Godard (1):
Add support for setting a presubject

Louis Rannou (1):
send-receive: support for presubjects

 misc/send-receive.py |  4 ++--
 src/b4/__init__.py   | 27 +++++++++++++++------
 src/b4/command.py    |  2 ++
 src/b4/ez.py         | 68 ++++++++++++++++++++++++++++++++++++++++++++--------
 4 files changed, 82 insertions(+), 19 deletions(-)

---
base-commit: a6db3f06ce9836a7fc8921f588452804fc62bed1
change-id: 20251113-sub-3118d60b006f

Best regards,

Signature · 1 line
Louis Rannou <[email protected]>
#1 lore raw

PATCH 1/2 Add support for setting a presubject

From: Antonin Godard <[email protected]>

Some mailing lists require a prefix to come before the [PATCH] in the subject of emails, such as OpenEmbedded or libgpiod. The current prefix mechanism does not allow for that (only after PATCH), and setting the format.subjectPrefix Git option does not work either.

Add a new configuration option send-presubject as well as a --set-presubject argument to be able to include anything that should come before the subject. The logic behind prefixes is not changed and this new option does not break any existing prefix assignments.

In order not to break the logic in LoreSubject's __init__ function, which parses the subject line and strips brackets in order to reorganize the subject line later, the presubject must be enclosed with brackets too (_check_presubject() is used to ensure that).

---
 src/b4/__init__.py | 27 ++++++++++++++++------
 src/b4/command.py  |  2 ++
 src/b4/ez.py       | 68 ++++++++++++++++++++++++++++++++++++++++++++++--------
 3 files changed, 80 insertions(+), 17 deletions(-)
src/b4/__init__.py +20 -7
index 7689550..ba76e83 100644
@@ -2552,7 +2552,7 @@ class LoreSubject:
     counters_inferred: bool
     prefixes: List[str]
 
-    def __init__(self, subject: str) -> None:
+    def __init__(self, subject: str, presubject: str = None) -> None:
         # Subject-based info
         self.reply = False
         self.resend = False
@@ -2592,6 +2592,9 @@ class LoreSubject:
             bracketed = re.sub(r'(patch)(v\d+)', r'\1 \2', bracketed, flags=re.I)
 
             for chunk in bracketed.split():
+                if presubject is not None and chunk in presubject:
+                    continue
+
                 # Remove any trailing commas or semicolons
                 chunk = chunk.strip(',;')
                 if re.search(r'^\d{1,4}/\d{1,4}$', chunk):
@@ -2629,7 +2632,9 @@ class LoreSubject:
 
         return ret
 
-    def get_rebuilt_subject(self, eprefixes: Optional[List[str]] = None) -> str:
+    def get_rebuilt_subject(self, eprefixes: Optional[List[str]] = None,
+                            presubject: str = None) -> str:
+
         exclude = None
         if eprefixes and 'PATCH' in eprefixes:
             exclude = ['patch']
@@ -2645,10 +2650,16 @@ class LoreSubject:
         if self.expected > 1:
             _pfx.append('%s/%s' % (str(self.counter).zfill(len(str(self.expected))), self.expected))
 
+        subject = ""
         if len(_pfx):
-            return '[' + ' '.join(_pfx) + '] ' + self.subject
+            subject = '[' + ' '.join(_pfx) + '] ' + self.subject
         else:
-            return f'[PATCH] {self.subject}'
+            subject = f'[PATCH] {self.subject}'
+
+        if presubject:
+            subject = f'{presubject}{subject}'
+
+        return subject
 
     def get_slug(self, sep: str = '_', with_counter: bool = True) -> str:
         unsafe = self.subject
@@ -3658,7 +3669,8 @@ def git_range_to_patches(gitdir: Optional[str], start: str, end: str,
                          mailfrom: Optional[Tuple[str, str]] = None,
                          extrahdrs: Optional[List[Tuple[str, str]]] = None,
                          ignore_commits: Optional[Set[str]] = None,
-                         limit_committer: Optional[str] = None) -> List[Tuple[str, EmailMessage]]:
+                         limit_committer: Optional[str] = None,
+                         presubject: Optional[str] = None) -> List[Tuple[str, EmailMessage]]:
     gitargs = ['rev-list', '--no-merges', '--reverse']
     if limit_committer:
         gitargs += ['-F', f'--committer={limit_committer}']
@@ -3714,12 +3726,13 @@ def git_range_to_patches(gitdir: Optional[str], start: str, end: str,
         msg.set_charset('utf-8')
         # Clean From to remove any 7bit-safe encoding
         origfrom = LoreMessage.clean_header(msg.get('From'))
-        lsubject = LoreSubject(msg.get('Subject'))
+        lsubject = LoreSubject(msg.get('Subject'), presubject=presubject)
         lsubject.counter = counter + 1
         lsubject.expected = expected
         if revision is not None:
             lsubject.revision = revision
-        subject = lsubject.get_rebuilt_subject(eprefixes=prefixes)
+        subject = lsubject.get_rebuilt_subject(eprefixes=prefixes,
+                                               presubject=presubject)
 
         logger.debug('  %s', subject)
         msg.replace_header('Subject', subject)
src/b4/command.py +2 -0
index 0114197..1f8b8f1 100644
@@ -318,6 +318,8 @@ def setup_parser() -> argparse.ArgumentParser:
                          help='Prefixes to include after [PATCH] (e.g.: RFC mydrv)')
     sp_prep.add_argument('--add-prefixes', metavar='PREFIX', nargs='+',
                          help='Additional prefixes to add to those already defined')
+    sp_prep.add_argument('--set-presubject', metavar='PRESUBJECT', type=str, default=None,
+                         help='Prefix to include before [PATCH] (e.g.: [mylist])')
     sp_prep.add_argument('-C', '--no-cache', dest='nocache', action='store_true', default=False,
                          help='Do not use local cache')
     sp_prep.add_argument('--range-diff-opts', default=None, type=str,
src/b4/ez.py +58 -10

154 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 send-receive: support for presubjects

In reply to Louis Rannou

Accept subjects which start with bracketed prefixes.

eg. [anyproject][PATCH] title
while 'anyproject[PATCH] title' won't pass

---
 misc/send-receive.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
misc/send-receive.py +2 -2
index bb65aaa..a3dd893 100644
@@ -433,12 +433,12 @@ class SendReceiveListener(object):
             msg = email.message_from_bytes(bdata, policy=emlpolicy)
             logger.debug('Checking sanity on message: %s', msg.get('Subject'))
             # Some quick sanity checking:
-            # - Subject has to start with [PATCH
+            # - Subject must include [PATCH and have only bracketed prefixes before
             # - Content-type may ONLY be text/plain
             # - Has to include a diff or a diffstat
             passes = True
             subject = self.clean_header(msg.get('Subject', ''))
-            if not subject.startswith('[PATCH'):
+            if not re.match(r'(\[[^]]+\])*\[PATCH', subject):
                 passes = False
             if passes:
                 cte = msg.get_content_type()
Signature · 1 line
2.43.0
#3 lore raw
In reply to Louis Rannou
Quoted 6 lines · Louis Rannou

This takes the unmerged work from Antonin Godard <[email protected]> and adds the send-receive patch to accept presubjects.

Applied, thanks!

[1/2] Add support for setting a presubject

      commit: d7232f5db2e4379bd9372b00707a78ec8d36b44a
[2/2] send-receive: support for presubjects
      commit: b45f88a7242ca817bdf4e0417f5967d9fee0c0f9

Best regards,

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