]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
patman: Avoid blank lines between tags
authorSimon Glass <sjg@chromium.org>
Sun, 1 Aug 2021 22:02:39 +0000 (16:02 -0600)
committerSimon Glass <sjg@chromium.org>
Sun, 8 Aug 2021 17:27:27 +0000 (11:27 -0600)
In some cases 'patman status' leaves a blank line between the sign-off
and the tags it collects from patchwork. Fix this and add a test.

Signed-off-by: Simon Glass <sjg@chromium.org>
tools/patman/func_test.py
tools/patman/patchstream.py

index 9871bb580d0c32731ae3c0b91a40c7dce4a1008f..2493e527f525cabd118b0696692698035ddb6c28 100644 (file)
@@ -136,7 +136,7 @@ class TestFunctional(unittest.TestCase):
             Commit-changes: 2
             - Changes only for this commit
 
-            Cover-changes: 4
+'            Cover-changes: 4
             - Some notes for the cover letter
 
             Cover-letter:
@@ -1293,3 +1293,24 @@ Reviewed-by: %s
         self.assertEqual(terminal.PrintLine(
             '4 new responses available in patchwork (use -d to write them to a new branch)',
             None), next(lines))
+
+    def testInsertTags(self):
+        """Test inserting of review tags"""
+        msg = '''first line
+second line.'''
+        tags = [
+            'Reviewed-by: Bin Meng <bmeng.cn@gmail.com>',
+            'Tested-by: Bin Meng <bmeng.cn@gmail.com>'
+            ]
+        signoff = 'Signed-off-by: Simon Glass <sjg@chromium.com>'
+        tag_str = '\n'.join(tags)
+
+        new_msg = patchstream.insert_tags(msg, tags)
+        self.assertEqual(msg + '\n\n' + tag_str, new_msg)
+
+        new_msg = patchstream.insert_tags(msg + '\n', tags)
+        self.assertEqual(msg + '\n\n' + tag_str, new_msg)
+
+        msg += '\n\n' + signoff
+        new_msg = patchstream.insert_tags(msg, tags)
+        self.assertEqual(msg + '\n' + tag_str, new_msg)
index b960292427376c21e816945041eb6d6ee26477d6..2439fb18e427de2f3f94bfb7fae9d4d2268b8b48 100644 (file)
@@ -662,6 +662,7 @@ def insert_tags(msg, tags_to_emit):
     out = []
     done = False
     emit_tags = False
+    emit_blank = False
     for line in msg.splitlines():
         if not done:
             signoff_match = RE_SIGNOFF.match(line)
@@ -672,9 +673,13 @@ def insert_tags(msg, tags_to_emit):
                 out += tags_to_emit
                 emit_tags = False
                 done = True
+            emit_blank = not (signoff_match or tag_match)
+        else:
+            emit_blank = line
         out.append(line)
     if not done:
-        out.append('')
+        if emit_blank:
+            out.append('')
         out += tags_to_emit
     return '\n'.join(out)