Commits

Yann E. MORIN  committed 515822a

patchmessage: detect SoB-block

The Message-Id line is intended to belong to a SoB-block, that is,
a set of SoB-like lines (SoB, Acked, Tested...). In this case, just
append the Message-Id line without a preceding blank line.

On the other hand, if a SoB-block is missing (because the project does
not use or enforce SoB-lines), but still want to use the Message-Id
line, it makes sense to append the MEssage-Id line with a preceding
blank line, to properly separate it from the original commit log.

Use a rather crude heuristic to detect presence of a SoB-block by
matching lines against a regexp with all known-today SoB-like lines.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

  • Participants
  • Parent commits 5f761b0

Comments (0)

Files changed (2)

                           r'retrieving revision [0-9]+(\.[0-9]+)*$|'
                           r'---[ \t].*?^\+\+\+[ \t]|'
                           r'\*\*\*[ \t].*?^---[ \t])', re.MULTILINE|re.DOTALL)
+re_sob = re.compile(r'^((Signed-off|Reported|Tested|Reviewed|Acked)-by|Cc):',
+                    re.MULTILINE|re.DOTALL)
 
 def parsesubject(s):
     """Return unbroken subject, title, index and total count from
         if messageid:
             m = re_startdiff.search(patch)
             if m:
+                # Do we have a SoB-block?
+                if re_sob.search(patch[:m.start(0)-1]):
+                    sep = ''        # Yes, no separator line
+                else:
+                    sep = '\n'      # No, add separator line
                 # Insert a Message-Id line
-                patch = patch[:m.start(0)-1]            + \
+                patch = patch[:m.start(0)-1] + sep      + \
                         'Message-Id: ' + self.id + '\n' + \
                         patch[m.start(0)-1:]
         return patch

File test-mbox.out

 Mercurial-devel@selenic.com
 http://selenic.com/mailman/listinfo/mercurial-devel
 test no SoB-block
+
 Message-Id: <5ab3c4562bd574dbd782.1230599538@localhost>
 
 diff --git a/a b/a