From: Sean Anderson Date: Mon, 4 May 2020 20:28:35 +0000 (-0400) Subject: patman: Support multi-line changes in changelogs X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-favicon.png?a=commitdiff_plain;h=0411fff36f432079cacc0697d72140b8594364f1;p=u-boot.git patman: Support multi-line changes in changelogs 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 Reviewed-by: Simon Glass --- diff --git a/tools/patman/README b/tools/patman/README index a99a68c6d5..52b2cf70bd 100644 --- a/tools/patman/README +++ b/tools/patman/README @@ -270,8 +270,14 @@ Patch-cc: Their Name 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 871c66aeb1..4fe465e9ab 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 @@ -138,6 +142,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 @@ -178,6 +196,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) @@ -218,6 +237,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 @@ -272,20 +292,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 @@ -378,6 +396,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=' %