diff mbox series

[b4] Handle author A, submitter B, committer A SOB chain correctly

Message ID 875xkqccgm.ffs@tglx (mailing list archive)
State New
Headers show
Series [b4] Handle author A, submitter B, committer A SOB chain correctly | expand

Commit Message

Thomas Gleixner March 3, 2025, 4:20 p.m. UTC
The trailer handling of b4 fails to handle one particular case
correctly:

Dev A posts a patch with his SOB

        Subject: [PATCH] subsys: Something
        From: Dev A <deva@k.org>

          Some explanation

          Signed-off-by: Dev A <deva@k.org>

Dev B picks the patch up, adds his SOB and reposts it in a follow up
series:

        Subject: [PATCH v2 1/5] subsys: Something
        From: Dev B <devb@k.org>

          From: Dev A <deva@k.org>
          
          Some explanation

          Signed-off-by: Dev A <deva@k.org>
          Signed-off-by: Dev B <devb@k.org>

Now Dev A who is also the maintainer picks the series up and b4 converts
it to:

        Author: Dev A <deva@k.org>

          subsys: Something

          Some explanation

          Signed-off-by: Dev B <devb@k.org>
          Signed-off-by: Dev A <deva@k.org>

While Dev A is correctly assigned to be the author of the commit, the
SOB chain is incorrect because the first SOB is not the author's
SOB. The correct resolution for this is:

        Author: Dev A <deva@k.org>

          subsys: Something

          Some explanation

          Signed-off-by: Dev A <deva@k.org>
          Signed-off-by: Dev B <devb@k.org>
          Signed-off-by: Dev A <deva@k.org>

Validate that the committers SOB is the last one in the SOB chain and
only remove it from processing if that's true. If the committers SOB is
before the last SOB in the submission, then keep the ordering intact and
add an extra committer SOB at the end.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 src/b4/__init__.py |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
diff mbox series

Patch

--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -2205,9 +2205,22 @@  MAILMAP_INFO = dict()
         sobtr = LoreTrailer()
         hasmysob = False
         if sobtr in btrailers:
+
+            found = False
+            last = True
+            for bltr in btrailers:
+                if not found:
+                    found = bltr == sobtr
+                else:
+                    if bltr.lname == 'signed-off-by':
+                        last = False
+                        break
+
             # Our own signoff always moves to the bottom of all trailers
-            hasmysob = True
-            btrailers.remove(sobtr)
+            # if it is the last signoff in the chain.
+            if last:
+                hasmysob = True
+                btrailers.remove(sobtr)
 
         new_trailers = self.followup_trailers
         if extras: