summaryrefslogtreecommitdiff
path: root/tools/patman/patchstream.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/patman/patchstream.py')
-rw-r--r--tools/patman/patchstream.py44
1 files changed, 33 insertions, 11 deletions
diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py
index 7a695c37c27..45040877f8c 100644
--- a/tools/patman/patchstream.py
+++ b/tools/patman/patchstream.py
@@ -109,6 +109,8 @@ class PatchStream:
self.recent_unquoted = queue.Queue()
self.was_quoted = None
self.insert_base_commit = insert_base_commit
+ self.lines = [] # All lines in a commit message
+ self.msg = None # Full commit message including subject
@staticmethod
def process_text(text, is_comment=False):
@@ -190,11 +192,22 @@ class PatchStream:
"""
self.commit.add_rtag(rtag_type, who)
- def _close_commit(self):
- """Save the current commit into our commit list, and reset our state"""
+ def _close_commit(self, skip_last_line):
+ """Save the current commit into our commit list, and reset our state
+
+ Args:
+ skip_last_line (bool): True to omit the final line of self.lines
+ when building the commit message. This is normally the blank
+ line between two commits, except at the end of the log, where
+ there is no blank line
+ """
if self.commit and self.is_log:
+ # Skip the blank line before the subject
+ lines = self.lines[:-1] if skip_last_line else self.lines
+ self.commit.msg = '\n'.join(lines[1:]) + '\n'
self.series.AddCommit(self.commit)
self.commit = None
+ self.lines = []
# If 'END' is missing in a 'Cover-letter' section, and that section
# happens to show up at the very end of the commit message, this is
# the chance for us to fix it up.
@@ -345,6 +358,8 @@ class PatchStream:
self.state += 1
elif commit_match:
self.state = STATE_MSG_HEADER
+ if self.state != STATE_MSG_HEADER:
+ self.lines.append(line)
# If a tag is detected, or a new commit starts
if series_tag_match or commit_tag_match or change_id_match or \
@@ -499,7 +514,7 @@ class PatchStream:
# Detect the start of a new commit
elif commit_match:
- self._close_commit()
+ self._close_commit(True)
self.commit = commit.Commit(commit_match.group(1))
# Detect tags in the commit message
@@ -579,7 +594,7 @@ class PatchStream:
"""Close out processing of this patch stream"""
self._finalise_snippet()
self._finalise_change()
- self._close_commit()
+ self._close_commit(False)
if self.lines_after_test:
self._add_warn('Found %d lines after TEST=' % self.lines_after_test)
@@ -754,7 +769,7 @@ def get_metadata_for_list(commit_range, git_dir=None, count=None,
pst.finalise()
return series
-def get_metadata(branch, start, count):
+def get_metadata(branch, start, count, git_dir=None):
"""Reads out patch series metadata from the commits
This does a 'git log' on the relevant commits and pulls out the tags we
@@ -769,8 +784,9 @@ def get_metadata(branch, start, count):
Series: Object containing information about the commits.
"""
top = f"{branch if branch else 'HEAD'}~{start}"
- series = get_metadata_for_list(top, None, count)
- series.base_commit = commit.Commit(gitutil.get_hash(f'{top}~{count}'))
+ series = get_metadata_for_list(top, git_dir, count)
+ series.base_commit = commit.Commit(
+ gitutil.get_hash(f'{top}~{count}', git_dir))
series.branch = branch or gitutil.get_branch()
series.top = top
return series
@@ -792,7 +808,7 @@ def get_metadata_for_test(text):
return series
def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False,
- insert_base_commit=False):
+ insert_base_commit=False, cwd=None):
"""Fix up a patch file, by adding/removing as required.
We remove our tags from the patch file, insert changes lists, etc.
@@ -807,10 +823,12 @@ def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False,
cmt (Commit): Commit object for this patch file
keep_change_id (bool): Keep the Change-Id tag.
insert_base_commit (bool): True to add the base commit to the end
+ cwd (str): Directory containing filename, or None for current
Return:
list: A list of errors, each str, or [] if all ok.
"""
+ fname = os.path.join(cwd or '', fname)
handle, tmpname = tempfile.mkstemp()
outfd = os.fdopen(handle, 'w', encoding='utf-8')
infd = open(fname, 'r', encoding='utf-8')
@@ -827,7 +845,8 @@ def fix_patch(backup_dir, fname, series, cmt, keep_change_id=False,
shutil.move(tmpname, fname)
return cmt.warn
-def fix_patches(series, fnames, keep_change_id=False, insert_base_commit=False):
+def fix_patches(series, fnames, keep_change_id=False, insert_base_commit=False,
+ cwd=None):
"""Fix up a list of patches identified by filenames
The patch files are processed in place, and overwritten.
@@ -837,6 +856,7 @@ def fix_patches(series, fnames, keep_change_id=False, insert_base_commit=False):
fnames (:type: list of str): List of patch files to process
keep_change_id (bool): Keep the Change-Id tag.
insert_base_commit (bool): True to add the base commit to the end
+ cwd (str): Directory containing the patch files, or None for current
"""
# Current workflow creates patches, so we shouldn't need a backup
backup_dir = None #tempfile.mkdtemp('clean-patch')
@@ -847,7 +867,7 @@ def fix_patches(series, fnames, keep_change_id=False, insert_base_commit=False):
cmt.count = count
result = fix_patch(backup_dir, fname, series, cmt,
keep_change_id=keep_change_id,
- insert_base_commit=insert_base_commit)
+ insert_base_commit=insert_base_commit, cwd=cwd)
if result:
print('%d warning%s for %s:' %
(len(result), 's' if len(result) > 1 else '', fname))
@@ -857,14 +877,16 @@ def fix_patches(series, fnames, keep_change_id=False, insert_base_commit=False):
count += 1
print('Cleaned %d patch%s' % (count, 'es' if count > 1 else ''))
-def insert_cover_letter(fname, series, count):
+def insert_cover_letter(fname, series, count, cwd=None):
"""Inserts a cover letter with the required info into patch 0
Args:
fname (str): Input / output filename of the cover letter file
series (Series): Series object
count (int): Number of patches in the series
+ cwd (str): Directory containing filename, or None for current
"""
+ fname = os.path.join(cwd or '', fname)
fil = open(fname, 'r')
lines = fil.readlines()
fil.close()