1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-30 23:11:32 +02:00

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 <seanga2@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Sean Anderson
2020-05-04 16:28:35 -04:00
committed by Simon Glass
parent 6949f70c6d
commit 0411fff36f
2 changed files with 35 additions and 10 deletions

View File

@@ -270,8 +270,14 @@ Patch-cc: Their Name <email>
interpreted by git send-email if you use it. interpreted by git send-email if you use it.
Series-process-log: sort, uniq Series-process-log: sort, uniq
This tells patman to sort and/or uniq the change logs. It is This tells patman to sort and/or uniq the change logs. Changes may be
assumed that each change log entry is only a single line long. 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 Use 'sort' to sort the entries, and 'uniq' to include only
unique entries. If omitted, no change log processing is done. unique entries. If omitted, no change log processing is done.
Separate each tag with a comma. Separate each tag with a comma.

View File

@@ -45,6 +45,9 @@ re_commit = re.compile('^commit ([0-9a-f]*)$')
# We detect these since checkpatch doesn't always do it # We detect these since checkpatch doesn't always do it
re_space_before_tab = re.compile('^[+].* \t') 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? # States we can be in - can we use range() and still have comments?
STATE_MSG_HEADER = 0 # Still in the message header STATE_MSG_HEADER = 0 # Still in the message header
STATE_PATCH_SUBJECT = 1 # In patch subject (first line of log for a commit) 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.is_log = is_log # True if indent like git log
self.in_change = None # Name of the change list we are in 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_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.blank_count = 0 # Number of blank lines stored up
self.state = STATE_MSG_HEADER # What state are we in? self.state = STATE_MSG_HEADER # What state are we in?
self.signoff = [] # Contents of signoff line self.signoff = [] # Contents of signoff line
@@ -138,6 +142,20 @@ class PatchStream:
raise ValueError("%s: Cannot decode version info '%s'" % raise ValueError("%s: Cannot decode version info '%s'" %
(self.commit.hash, line)) (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): def ProcessLine(self, line):
"""Process a single line of a patch file or commit log """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) commit_tag_match = re_commit_tag.match(line)
cover_match = re_cover.match(line) cover_match = re_cover.match(line)
signoff_match = re_signoff.match(line) signoff_match = re_signoff.match(line)
leading_whitespace_match = re_leading_whitespace.match(line)
tag_match = None tag_match = None
if self.state == STATE_PATCH_HEADER: if self.state == STATE_PATCH_HEADER:
tag_match = re_tag.match(line) tag_match = re_tag.match(line)
@@ -218,6 +237,7 @@ class PatchStream:
# is missing, fix it up. # is missing, fix it up.
if self.in_change: if self.in_change:
self.warn.append("Missing 'blank line' in section '%s-changes'" % self.in_change) self.warn.append("Missing 'blank line' in section '%s-changes'" % self.in_change)
self.FinalizeChange()
self.in_change = None self.in_change = None
self.change_version = 0 self.change_version = 0
@@ -272,20 +292,18 @@ class PatchStream:
elif self.in_change: elif self.in_change:
if is_blank: if is_blank:
# Blank line ends this change list # Blank line ends this change list
self.FinalizeChange()
self.in_change = None self.in_change = None
self.change_version = 0 self.change_version = 0
elif line == '---': elif line == '---':
self.FinalizeChange()
self.in_change = None self.in_change = None
self.change_version = 0 self.change_version = 0
out = self.ProcessLine(line) out = self.ProcessLine(line)
else: elif self.is_log:
if self.is_log: if not leading_whitespace_match:
if self.in_change == 'Series': self.FinalizeChange()
self.series.AddChange(self.change_version, self.commit, line) self.change_lines.append(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)
self.skip_blank = False self.skip_blank = False
# Detect Series-xxx tags # Detect Series-xxx tags
@@ -378,6 +396,7 @@ class PatchStream:
def Finalize(self): def Finalize(self):
"""Close out processing of this patch stream""" """Close out processing of this patch stream"""
self.FinalizeChange()
self.CloseCommit() self.CloseCommit()
if self.lines_after_test: if self.lines_after_test:
self.warn.append('Found %d lines after TEST=' % self.warn.append('Found %d lines after TEST=' %