diff mbox series

[v2,3/3] patman: Support multi-line changes in changelogs

Message ID 20200413215126.548213-4-seanga2@gmail.com
State Superseded
Headers show
Series patman: Add changelog customization options | expand

Commit Message

Sean Anderson April 13, 2020, 9:51 p.m. UTC
This patch adds support to multi-line changes. That is, if one has a line
in a changelog like
- Do a thing but
  it spans multiple lines
Using Series-process-log sort would sort as if those lines were unrelated.
With this patch, any change line starting with whitespace will be
considered part of the change before it.

Signed-off-by: Sean Anderson <seanga2 at gmail.com>
---

Changes in v2:
- New

 tools/patman/README         | 10 ++++++++--
 tools/patman/patchstream.py | 35 +++++++++++++++++++++++++++--------
 2 files changed, 35 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/tools/patman/README b/tools/patman/README
index ce912aacbb..433bbf1683 100644
--- a/tools/patman/README
+++ b/tools/patman/README
@@ -270,8 +270,14 @@  Patch-cc: Their Name <email>
 	interpreted by git send-email if you use it.
 
 Series-process-log: sort, uniq
-	This tells patman to sort and/or uniq the change logs. It is
-	assumed that each change log entry is only a single line long.
+	This tells patman to sort and/or uniq the change logs. Changes may be
+	multiple lines long, as long as each subsequent line of a change begins
+	with a whitespace character. For example,
+
+- This change
+  continues onto the next line
+- But this change is separate
+
 	Use 'sort' to sort the entries, and 'uniq' to include only
 	unique entries. If omitted, no change log processing is done.
 	Separate each tag with a comma.
diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index f29ad87e70..eeac5d268e 100644
--- a/tools/patman/patchstream.py
+++ b/tools/patman/patchstream.py
@@ -45,6 +45,9 @@  re_commit = re.compile('^commit ([0-9a-f]*)$')
 # We detect these since checkpatch doesn't always do it
 re_space_before_tab = re.compile('^[+].* \t')
 
+# Match indented lines for changes
+re_leading_whitespace = re.compile('^\s')
+
 # States we can be in - can we use range() and still have comments?
 STATE_MSG_HEADER = 0        # Still in the message header
 STATE_PATCH_SUBJECT = 1     # In patch subject (first line of log for a commit)
@@ -72,6 +75,7 @@  class PatchStream:
         self.is_log = is_log             # True if indent like git log
         self.in_change = None            # Name of the change list we are in
         self.change_version = 0          # Non-zero if we are in a change list
+        self.change_lines = []           # Lines of the current change
         self.blank_count = 0             # Number of blank lines stored up
         self.state = STATE_MSG_HEADER    # What state are we in?
         self.signoff = []                # Contents of signoff line
@@ -130,6 +134,20 @@  class PatchStream:
             raise ValueError("%s: Cannot decode version info '%s'" %
                 (self.commit.hash, line))
 
+    def FinalizeChange(self):
+        """Finalize a (multi-line) change and add it to the series or commit"""
+        if not self.change_lines:
+            return
+        change = '\n'.join(self.change_lines)
+
+        if self.in_change == 'Series':
+            self.series.AddChange(self.change_version, self.commit, change)
+        elif self.in_change == 'Cover':
+            self.series.AddChange(self.change_version, None, change)
+        elif self.in_change == 'Commit':
+            self.commit.AddChange(self.change_version, change)
+        self.change_lines = []
+
     def ProcessLine(self, line):
         """Process a single line of a patch file or commit log
 
@@ -170,6 +188,7 @@  class PatchStream:
         commit_tag_match = re_commit_tag.match(line)
         cover_match = re_cover.match(line)
         signoff_match = re_signoff.match(line)
+        leading_whitespace_match = re_leading_whitespace.match(line)
         tag_match = None
         if self.state == STATE_PATCH_HEADER:
             tag_match = re_tag.match(line)
@@ -210,6 +229,7 @@  class PatchStream:
             # is missing, fix it up.
             if self.in_change:
                 self.warn.append("Missing 'blank line' in section '%s-changes'" % self.in_change)
+                self.FinalizeChange()
                 self.in_change = None
                 self.change_version = 0
 
@@ -264,20 +284,18 @@  class PatchStream:
         elif self.in_change:
             if is_blank:
                 # Blank line ends this change list
+                self.FinalizeChange()
                 self.in_change = None
                 self.change_version = 0
             elif line == '---':
+                self.FinalizeChange()
                 self.in_change = None
                 self.change_version = 0
                 out = self.ProcessLine(line)
-            else:
-                if self.is_log:
-                    if self.in_change == 'Series':
-                        self.series.AddChange(self.change_version, self.commit, line)
-                    elif self.in_change == 'Cover':
-                        self.series.AddChange(self.change_version, None, line)
-                    elif self.in_change == 'Commit':
-                        self.commit.AddChange(self.change_version, line)
+            elif self.is_log:
+                if not leading_whitespace_match:
+                    self.FinalizeChange()
+                self.change_lines.append(line)
             self.skip_blank = False
 
         # Detect Series-xxx tags
@@ -370,6 +388,7 @@  class PatchStream:
 
     def Finalize(self):
         """Close out processing of this patch stream"""
+        self.FinalizeChange()
         self.CloseCommit()
         if self.lines_after_test:
             self.warn.append('Found %d lines after TEST=' %