2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2012-01-14 15:12:45 +00:00
|
|
|
# Copyright (c) 2011 The Chromium OS Authors.
|
|
|
|
#
|
|
|
|
|
2020-10-30 03:46:17 +00:00
|
|
|
"""Handles parsing a stream of commits/emails from 'git log' or other source"""
|
|
|
|
|
2020-10-30 03:46:37 +00:00
|
|
|
import collections
|
2019-09-27 16:23:56 +00:00
|
|
|
import datetime
|
2020-10-30 03:46:27 +00:00
|
|
|
import io
|
2015-04-03 02:51:17 +00:00
|
|
|
import math
|
2012-01-14 15:12:45 +00:00
|
|
|
import os
|
|
|
|
import re
|
2020-10-30 03:46:37 +00:00
|
|
|
import queue
|
2012-01-14 15:12:45 +00:00
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
|
2020-04-18 00:09:04 +00:00
|
|
|
from patman import command
|
|
|
|
from patman import commit
|
|
|
|
from patman import gitutil
|
|
|
|
from patman.series import Series
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# Tags that we detect and remove
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_REMOVE = re.compile(r'^BUG=|^TEST=|^BRANCH=|^Review URL:'
|
2020-10-30 03:46:17 +00:00
|
|
|
r'|Reviewed-on:|Commit-\w*:')
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# Lines which are allowed after a TEST= line
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_ALLOWED_AFTER_TEST = re.compile('^Signed-off-by:')
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2012-08-06 23:46:05 +00:00
|
|
|
# Signoffs
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_SIGNOFF = re.compile('^Signed-off-by: *(.*)')
|
2012-08-06 23:46:05 +00:00
|
|
|
|
2020-05-04 20:28:34 +00:00
|
|
|
# Cover letter tag
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_COVER = re.compile('^Cover-([a-z-]*): *(.*)')
|
2013-03-20 16:43:00 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# Patch series tag
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_SERIES_TAG = re.compile('^Series-([a-z-]*): *(.*)')
|
2013-11-12 10:14:41 +00:00
|
|
|
|
2019-09-27 16:23:56 +00:00
|
|
|
# Change-Id will be used to generate the Message-Id and then be stripped
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_CHANGE_ID = re.compile('^Change-Id: *(.*)')
|
2019-09-27 16:23:56 +00:00
|
|
|
|
2013-11-12 10:14:41 +00:00
|
|
|
# Commit series tag
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_COMMIT_TAG = re.compile('^Commit-([a-z-]*): *(.*)')
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# Commit tags that we want to collect and keep
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_TAG = re.compile('^(Tested-by|Acked-by|Reviewed-by|Patch-cc|Fixes): (.*)')
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# The start of a new commit in the git log
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_COMMIT = re.compile('^commit ([0-9a-f]*)$')
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# We detect these since checkpatch doesn't always do it
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_SPACE_BEFORE_TAB = re.compile('^[+].* \t')
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-05-04 20:28:35 +00:00
|
|
|
# Match indented lines for changes
|
2020-10-30 03:46:18 +00:00
|
|
|
RE_LEADING_WHITESPACE = re.compile(r'^\s')
|
2020-05-04 20:28:35 +00:00
|
|
|
|
2020-10-30 03:46:37 +00:00
|
|
|
# Detect a 'diff' line
|
|
|
|
RE_DIFF = re.compile(r'^>.*diff --git a/(.*) b/(.*)$')
|
|
|
|
|
|
|
|
# Detect a context line, like '> @@ -153,8 +153,13 @@ CheckPatch
|
|
|
|
RE_LINE = re.compile(r'>.*@@ \-(\d+),\d+ \+(\d+),\d+ @@ *(.*)')
|
|
|
|
|
2021-07-22 14:51:42 +00:00
|
|
|
# Detect line with invalid TAG
|
|
|
|
RE_INV_TAG = re.compile('^Serie-([a-z-]*): *(.*)')
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# 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)
|
|
|
|
STATE_PATCH_HEADER = 2 # In patch header (after the subject)
|
|
|
|
STATE_DIFFS = 3 # In the diff part (past --- line)
|
|
|
|
|
|
|
|
class PatchStream:
|
|
|
|
"""Class for detecting/injecting tags in a patch or series of patches
|
|
|
|
|
|
|
|
We support processing the output of 'git log' to read out the tags we
|
|
|
|
are interested in. We can also process a patch file in order to remove
|
|
|
|
unwanted tags or inject additional ones. These correspond to the two
|
|
|
|
phases of processing.
|
|
|
|
"""
|
2020-10-30 03:46:21 +00:00
|
|
|
def __init__(self, series, is_log=False):
|
2012-01-14 15:12:45 +00:00
|
|
|
self.skip_blank = False # True to skip a single blank line
|
|
|
|
self.found_test = False # Found a TEST= line
|
2020-05-04 20:28:34 +00:00
|
|
|
self.lines_after_test = 0 # Number of lines found after TEST=
|
2012-01-14 15:12:45 +00:00
|
|
|
self.linenum = 1 # Output line number we are up to
|
|
|
|
self.in_section = None # Name of start...END section we are in
|
|
|
|
self.notes = [] # Series notes
|
|
|
|
self.section = [] # The current section...END section
|
|
|
|
self.series = series # Info about the patch series
|
|
|
|
self.is_log = is_log # True if indent like git log
|
2020-05-04 20:28:34 +00:00
|
|
|
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
|
2020-05-04 20:28:35 +00:00
|
|
|
self.change_lines = [] # Lines of the current change
|
2012-01-14 15:12:45 +00:00
|
|
|
self.blank_count = 0 # Number of blank lines stored up
|
|
|
|
self.state = STATE_MSG_HEADER # What state are we in?
|
|
|
|
self.commit = None # Current commit
|
2020-10-30 03:46:38 +00:00
|
|
|
# List of unquoted test blocks, each a list of str lines
|
|
|
|
self.snippets = []
|
2020-10-30 03:46:37 +00:00
|
|
|
self.cur_diff = None # Last 'diff' line seen (str)
|
|
|
|
self.cur_line = None # Last context (@@) line seen (str)
|
2020-10-30 03:46:38 +00:00
|
|
|
self.recent_diff = None # 'diff' line for current snippet (str)
|
|
|
|
self.recent_line = None # '@@' line for current snippet (str)
|
2020-10-30 03:46:37 +00:00
|
|
|
self.recent_quoted = collections.deque([], 5)
|
|
|
|
self.recent_unquoted = queue.Queue()
|
|
|
|
self.was_quoted = None
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:27 +00:00
|
|
|
@staticmethod
|
|
|
|
def process_text(text, is_comment=False):
|
|
|
|
"""Process some text through this class using a default Commit/Series
|
|
|
|
|
|
|
|
Args:
|
|
|
|
text (str): Text to parse
|
|
|
|
is_comment (bool): True if this is a comment rather than a patch.
|
|
|
|
If True, PatchStream doesn't expect a patch subject at the
|
|
|
|
start, but jumps straight into the body
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
PatchStream: object with results
|
|
|
|
"""
|
|
|
|
pstrm = PatchStream(Series())
|
|
|
|
pstrm.commit = commit.Commit(None)
|
|
|
|
infd = io.StringIO(text)
|
|
|
|
outfd = io.StringIO()
|
|
|
|
if is_comment:
|
|
|
|
pstrm.state = STATE_PATCH_HEADER
|
|
|
|
pstrm.process_stream(infd, outfd)
|
|
|
|
return pstrm
|
|
|
|
|
2020-10-30 03:46:23 +00:00
|
|
|
def _add_warn(self, warn):
|
2020-10-30 03:46:24 +00:00
|
|
|
"""Add a new warning to report to the user about the current commit
|
|
|
|
|
|
|
|
The new warning is added to the current commit if not already present.
|
2020-10-30 03:46:23 +00:00
|
|
|
|
|
|
|
Args:
|
|
|
|
warn (str): Warning to report
|
2020-10-30 03:46:24 +00:00
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError: Warning is generated with no commit associated
|
2020-10-30 03:46:23 +00:00
|
|
|
"""
|
2020-10-30 03:46:24 +00:00
|
|
|
if not self.commit:
|
2021-03-22 05:01:42 +00:00
|
|
|
print('Warning outside commit: %s' % warn)
|
|
|
|
elif warn not in self.commit.warn:
|
2020-10-30 03:46:24 +00:00
|
|
|
self.commit.warn.append(warn)
|
2020-10-30 03:46:23 +00:00
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def _add_to_series(self, line, name, value):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Add a new Series-xxx tag.
|
|
|
|
|
|
|
|
When a Series-xxx tag is detected, we come here to record it, if we
|
|
|
|
are scanning a 'git log'.
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
line (str): Source line containing tag (useful for debug/error
|
|
|
|
messages)
|
|
|
|
name (str): Tag name (part after 'Series-')
|
|
|
|
value (str): Tag value (part after 'Series-xxx: ')
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
|
|
|
if name == 'notes':
|
|
|
|
self.in_section = name
|
|
|
|
self.skip_blank = False
|
|
|
|
if self.is_log:
|
2020-10-30 03:46:25 +00:00
|
|
|
warn = self.series.AddTag(self.commit, line, name, value)
|
|
|
|
if warn:
|
|
|
|
self.commit.warn.append(warn)
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:21 +00:00
|
|
|
def _add_to_commit(self, name):
|
2013-11-12 10:14:41 +00:00
|
|
|
"""Add a new Commit-xxx tag.
|
|
|
|
|
|
|
|
When a Commit-xxx tag is detected, we come here to record it.
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
name (str): Tag name (part after 'Commit-')
|
2013-11-12 10:14:41 +00:00
|
|
|
"""
|
|
|
|
if name == 'notes':
|
|
|
|
self.in_section = 'commit-' + name
|
|
|
|
self.skip_blank = False
|
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def _add_commit_rtag(self, rtag_type, who):
|
2020-07-06 03:41:57 +00:00
|
|
|
"""Add a response tag to the current commit
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
rtag_type (str): rtag type (e.g. 'Reviewed-by')
|
|
|
|
who (str): Person who gave that rtag, e.g.
|
|
|
|
'Fred Bloggs <fred@bloggs.org>'
|
2020-07-06 03:41:57 +00:00
|
|
|
"""
|
|
|
|
self.commit.AddRtag(rtag_type, who)
|
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def _close_commit(self):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Save the current commit into our commit list, and reset our state"""
|
|
|
|
if self.commit and self.is_log:
|
|
|
|
self.series.AddCommit(self.commit)
|
|
|
|
self.commit = None
|
2016-06-27 06:24:30 +00:00
|
|
|
# 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.
|
|
|
|
if self.in_section == 'cover' and self.is_log:
|
|
|
|
self.series.cover = self.section
|
|
|
|
self.in_section = None
|
|
|
|
self.skip_blank = True
|
|
|
|
self.section = []
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:37 +00:00
|
|
|
self.cur_diff = None
|
|
|
|
self.recent_diff = None
|
|
|
|
self.recent_line = None
|
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def _parse_version(self, value, line):
|
2020-05-04 20:28:34 +00:00
|
|
|
"""Parse a version from a *-changes tag
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
value (str): Tag value (part after 'xxx-changes: '
|
|
|
|
line (str): Source line containing tag
|
2020-05-04 20:28:34 +00:00
|
|
|
|
|
|
|
Returns:
|
2020-10-30 03:46:22 +00:00
|
|
|
int: The version as an integer
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError: the value cannot be converted
|
2020-05-04 20:28:34 +00:00
|
|
|
"""
|
|
|
|
try:
|
|
|
|
return int(value)
|
2020-10-30 03:46:20 +00:00
|
|
|
except ValueError:
|
2020-05-04 20:28:34 +00:00
|
|
|
raise ValueError("%s: Cannot decode version info '%s'" %
|
2020-10-30 03:46:17 +00:00
|
|
|
(self.commit.hash, line))
|
2020-05-04 20:28:34 +00:00
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def _finalise_change(self):
|
|
|
|
"""_finalise a (multi-line) change and add it to the series or commit"""
|
2020-05-04 20:28:35 +00:00
|
|
|
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 = []
|
|
|
|
|
2020-10-30 03:46:37 +00:00
|
|
|
def _finalise_snippet(self):
|
|
|
|
"""Finish off a snippet and add it to the list
|
|
|
|
|
|
|
|
This is called when we get to the end of a snippet, i.e. the we enter
|
|
|
|
the next block of quoted text:
|
|
|
|
|
|
|
|
This is a comment from someone.
|
|
|
|
|
|
|
|
Something else
|
|
|
|
|
|
|
|
> Now we have some code <----- end of snippet
|
|
|
|
> more code
|
|
|
|
|
|
|
|
Now a comment about the above code
|
|
|
|
|
|
|
|
This adds the snippet to our list
|
|
|
|
"""
|
|
|
|
quoted_lines = []
|
|
|
|
while self.recent_quoted:
|
|
|
|
quoted_lines.append(self.recent_quoted.popleft())
|
|
|
|
unquoted_lines = []
|
|
|
|
valid = False
|
|
|
|
while not self.recent_unquoted.empty():
|
|
|
|
text = self.recent_unquoted.get()
|
|
|
|
if not (text.startswith('On ') and text.endswith('wrote:')):
|
|
|
|
unquoted_lines.append(text)
|
|
|
|
if text:
|
|
|
|
valid = True
|
|
|
|
if valid:
|
|
|
|
lines = []
|
|
|
|
if self.recent_diff:
|
|
|
|
lines.append('> File: %s' % self.recent_diff)
|
|
|
|
if self.recent_line:
|
|
|
|
out = '> Line: %s / %s' % self.recent_line[:2]
|
|
|
|
if self.recent_line[2]:
|
|
|
|
out += ': %s' % self.recent_line[2]
|
|
|
|
lines.append(out)
|
|
|
|
lines += quoted_lines + unquoted_lines
|
|
|
|
if lines:
|
|
|
|
self.snippets.append(lines)
|
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def process_line(self, line):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Process a single line of a patch file or commit log
|
|
|
|
|
|
|
|
This process a line and returns a list of lines to output. The list
|
|
|
|
may be empty or may contain multiple output lines.
|
|
|
|
|
|
|
|
This is where all the complicated logic is located. The class's
|
|
|
|
state is used to move between different states and detect things
|
|
|
|
properly.
|
|
|
|
|
|
|
|
We can be in one of two modes:
|
|
|
|
self.is_log == True: This is 'git log' mode, where most output is
|
|
|
|
indented by 4 characters and we are scanning for tags
|
|
|
|
|
|
|
|
self.is_log == False: This is 'patch' mode, where we already have
|
|
|
|
all the tags, and are processing patches to remove junk we
|
|
|
|
don't want, and add things we think are required.
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
line (str): text line to process
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
Returns:
|
2020-10-30 03:46:22 +00:00
|
|
|
list: list of output lines, or [] if nothing should be output
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
ValueError: a fatal error occurred while parsing, e.g. an END
|
|
|
|
without a starting tag, or two commits with two change IDs
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
|
|
|
# Initially we have no output. Prepare the input line string
|
|
|
|
out = []
|
|
|
|
line = line.rstrip('\n')
|
2014-09-25 19:30:46 +00:00
|
|
|
|
2020-10-30 03:46:18 +00:00
|
|
|
commit_match = RE_COMMIT.match(line) if self.is_log else None
|
2014-09-25 19:30:46 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
if self.is_log:
|
|
|
|
if line[:4] == ' ':
|
|
|
|
line = line[4:]
|
|
|
|
|
|
|
|
# Handle state transition and skipping blank lines
|
2020-10-30 03:46:18 +00:00
|
|
|
series_tag_match = RE_SERIES_TAG.match(line)
|
|
|
|
change_id_match = RE_CHANGE_ID.match(line)
|
|
|
|
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)
|
2020-10-30 03:46:37 +00:00
|
|
|
diff_match = RE_DIFF.match(line)
|
|
|
|
line_match = RE_LINE.match(line)
|
2021-07-22 14:51:42 +00:00
|
|
|
invalid_match = RE_INV_TAG.match(line)
|
2012-01-14 15:12:45 +00:00
|
|
|
tag_match = None
|
|
|
|
if self.state == STATE_PATCH_HEADER:
|
2020-10-30 03:46:18 +00:00
|
|
|
tag_match = RE_TAG.match(line)
|
2012-01-14 15:12:45 +00:00
|
|
|
is_blank = not line.strip()
|
|
|
|
if is_blank:
|
|
|
|
if (self.state == STATE_MSG_HEADER
|
|
|
|
or self.state == STATE_PATCH_SUBJECT):
|
|
|
|
self.state += 1
|
|
|
|
|
|
|
|
# We don't have a subject in the text stream of patch files
|
|
|
|
# It has its own line with a Subject: tag
|
|
|
|
if not self.is_log and self.state == STATE_PATCH_SUBJECT:
|
|
|
|
self.state += 1
|
|
|
|
elif commit_match:
|
|
|
|
self.state = STATE_MSG_HEADER
|
|
|
|
|
2016-06-27 06:24:32 +00:00
|
|
|
# If a tag is detected, or a new commit starts
|
2019-09-27 16:23:56 +00:00
|
|
|
if series_tag_match or commit_tag_match or change_id_match or \
|
2020-05-04 20:28:34 +00:00
|
|
|
cover_match or signoff_match or self.state == STATE_MSG_HEADER:
|
2016-06-27 06:24:31 +00:00
|
|
|
# but we are already in a section, this means 'END' is missing
|
|
|
|
# for that section, fix it up.
|
2016-06-27 06:24:29 +00:00
|
|
|
if self.in_section:
|
2020-10-30 03:46:23 +00:00
|
|
|
self._add_warn("Missing 'END' in section '%s'" % self.in_section)
|
2016-06-27 06:24:29 +00:00
|
|
|
if self.in_section == 'cover':
|
|
|
|
self.series.cover = self.section
|
|
|
|
elif self.in_section == 'notes':
|
|
|
|
if self.is_log:
|
|
|
|
self.series.notes += self.section
|
|
|
|
elif self.in_section == 'commit-notes':
|
|
|
|
if self.is_log:
|
|
|
|
self.commit.notes += self.section
|
|
|
|
else:
|
2020-10-30 03:46:23 +00:00
|
|
|
# This should not happen
|
|
|
|
raise ValueError("Unknown section '%s'" % self.in_section)
|
2016-06-27 06:24:29 +00:00
|
|
|
self.in_section = None
|
|
|
|
self.skip_blank = True
|
|
|
|
self.section = []
|
2016-06-27 06:24:31 +00:00
|
|
|
# but we are already in a change list, that means a blank line
|
|
|
|
# is missing, fix it up.
|
|
|
|
if self.in_change:
|
2020-10-30 03:46:23 +00:00
|
|
|
self._add_warn("Missing 'blank line' in section '%s-changes'" %
|
|
|
|
self.in_change)
|
2020-10-30 03:46:19 +00:00
|
|
|
self._finalise_change()
|
2020-05-04 20:28:34 +00:00
|
|
|
self.in_change = None
|
|
|
|
self.change_version = 0
|
2016-06-27 06:24:29 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# If we are in a section, keep collecting lines until we see END
|
|
|
|
if self.in_section:
|
|
|
|
if line == 'END':
|
|
|
|
if self.in_section == 'cover':
|
|
|
|
self.series.cover = self.section
|
|
|
|
elif self.in_section == 'notes':
|
|
|
|
if self.is_log:
|
|
|
|
self.series.notes += self.section
|
2013-11-12 10:14:41 +00:00
|
|
|
elif self.in_section == 'commit-notes':
|
|
|
|
if self.is_log:
|
|
|
|
self.commit.notes += self.section
|
2012-01-14 15:12:45 +00:00
|
|
|
else:
|
2020-10-30 03:46:23 +00:00
|
|
|
# This should not happen
|
|
|
|
raise ValueError("Unknown section '%s'" % self.in_section)
|
2012-01-14 15:12:45 +00:00
|
|
|
self.in_section = None
|
|
|
|
self.skip_blank = True
|
|
|
|
self.section = []
|
|
|
|
else:
|
|
|
|
self.section.append(line)
|
|
|
|
|
2020-07-02 17:08:24 +00:00
|
|
|
# If we are not in a section, it is an unexpected END
|
|
|
|
elif line == 'END':
|
2020-10-30 03:46:17 +00:00
|
|
|
raise ValueError("'END' wihout section")
|
2020-07-02 17:08:24 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# Detect the commit subject
|
|
|
|
elif not is_blank and self.state == STATE_PATCH_SUBJECT:
|
|
|
|
self.commit.subject = line
|
|
|
|
|
|
|
|
# Detect the tags we want to remove, and skip blank lines
|
2020-10-30 03:46:18 +00:00
|
|
|
elif RE_REMOVE.match(line) and not commit_tag_match:
|
2012-01-14 15:12:45 +00:00
|
|
|
self.skip_blank = True
|
|
|
|
|
|
|
|
# TEST= should be the last thing in the commit, so remove
|
|
|
|
# everything after it
|
|
|
|
if line.startswith('TEST='):
|
|
|
|
self.found_test = True
|
|
|
|
elif self.skip_blank and is_blank:
|
|
|
|
self.skip_blank = False
|
|
|
|
|
2020-05-04 20:28:34 +00:00
|
|
|
# Detect Cover-xxx tags
|
2016-06-27 06:24:28 +00:00
|
|
|
elif cover_match:
|
2020-05-04 20:28:34 +00:00
|
|
|
name = cover_match.group(1)
|
|
|
|
value = cover_match.group(2)
|
|
|
|
if name == 'letter':
|
|
|
|
self.in_section = 'cover'
|
|
|
|
self.skip_blank = False
|
|
|
|
elif name == 'letter-cc':
|
2020-10-30 03:46:19 +00:00
|
|
|
self._add_to_series(line, 'cover-cc', value)
|
2020-05-04 20:28:34 +00:00
|
|
|
elif name == 'changes':
|
|
|
|
self.in_change = 'Cover'
|
2020-10-30 03:46:19 +00:00
|
|
|
self.change_version = self._parse_version(value, line)
|
2013-03-20 16:43:00 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# If we are in a change list, key collected lines until a blank one
|
|
|
|
elif self.in_change:
|
|
|
|
if is_blank:
|
|
|
|
# Blank line ends this change list
|
2020-10-30 03:46:19 +00:00
|
|
|
self._finalise_change()
|
2020-05-04 20:28:34 +00:00
|
|
|
self.in_change = None
|
|
|
|
self.change_version = 0
|
2014-04-20 16:50:14 +00:00
|
|
|
elif line == '---':
|
2020-10-30 03:46:19 +00:00
|
|
|
self._finalise_change()
|
2020-05-04 20:28:34 +00:00
|
|
|
self.in_change = None
|
|
|
|
self.change_version = 0
|
2020-10-30 03:46:19 +00:00
|
|
|
out = self.process_line(line)
|
2020-05-04 20:28:35 +00:00
|
|
|
elif self.is_log:
|
|
|
|
if not leading_whitespace_match:
|
2020-10-30 03:46:19 +00:00
|
|
|
self._finalise_change()
|
2020-05-04 20:28:35 +00:00
|
|
|
self.change_lines.append(line)
|
2012-01-14 15:12:45 +00:00
|
|
|
self.skip_blank = False
|
|
|
|
|
|
|
|
# Detect Series-xxx tags
|
2013-11-12 10:14:41 +00:00
|
|
|
elif series_tag_match:
|
|
|
|
name = series_tag_match.group(1)
|
|
|
|
value = series_tag_match.group(2)
|
2012-01-14 15:12:45 +00:00
|
|
|
if name == 'changes':
|
|
|
|
# value is the version number: e.g. 1, or 2
|
2020-05-04 20:28:34 +00:00
|
|
|
self.in_change = 'Series'
|
2020-10-30 03:46:19 +00:00
|
|
|
self.change_version = self._parse_version(value, line)
|
2012-01-14 15:12:45 +00:00
|
|
|
else:
|
2020-10-30 03:46:19 +00:00
|
|
|
self._add_to_series(line, name, value)
|
2012-01-14 15:12:45 +00:00
|
|
|
self.skip_blank = True
|
|
|
|
|
2019-09-27 16:23:56 +00:00
|
|
|
# Detect Change-Id tags
|
|
|
|
elif change_id_match:
|
|
|
|
value = change_id_match.group(1)
|
|
|
|
if self.is_log:
|
|
|
|
if self.commit.change_id:
|
2020-10-30 03:46:17 +00:00
|
|
|
raise ValueError(
|
2020-11-03 20:54:11 +00:00
|
|
|
"%s: Two Change-Ids: '%s' vs. '%s'" %
|
|
|
|
(self.commit.hash, self.commit.change_id, value))
|
2019-09-27 16:23:56 +00:00
|
|
|
self.commit.change_id = value
|
|
|
|
self.skip_blank = True
|
|
|
|
|
2013-11-12 10:14:41 +00:00
|
|
|
# Detect Commit-xxx tags
|
|
|
|
elif commit_tag_match:
|
|
|
|
name = commit_tag_match.group(1)
|
|
|
|
value = commit_tag_match.group(2)
|
|
|
|
if name == 'notes':
|
2020-10-30 03:46:21 +00:00
|
|
|
self._add_to_commit(name)
|
2013-11-12 10:14:41 +00:00
|
|
|
self.skip_blank = True
|
2020-05-04 20:28:34 +00:00
|
|
|
elif name == 'changes':
|
|
|
|
self.in_change = 'Commit'
|
2020-10-30 03:46:19 +00:00
|
|
|
self.change_version = self._parse_version(value, line)
|
2020-07-02 17:52:54 +00:00
|
|
|
else:
|
2020-10-30 03:46:23 +00:00
|
|
|
self._add_warn('Line %d: Ignoring Commit-%s' %
|
|
|
|
(self.linenum, name))
|
2013-11-12 10:14:41 +00:00
|
|
|
|
2021-07-22 14:51:42 +00:00
|
|
|
# Detect invalid tags
|
|
|
|
elif invalid_match:
|
|
|
|
raise ValueError("Line %d: Invalid tag = '%s'" %
|
|
|
|
(self.linenum, line))
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# Detect the start of a new commit
|
|
|
|
elif commit_match:
|
2020-10-30 03:46:19 +00:00
|
|
|
self._close_commit()
|
2014-10-15 08:27:00 +00:00
|
|
|
self.commit = commit.Commit(commit_match.group(1))
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# Detect tags in the commit message
|
|
|
|
elif tag_match:
|
2020-07-06 03:41:57 +00:00
|
|
|
rtag_type, who = tag_match.groups()
|
2020-10-30 03:46:19 +00:00
|
|
|
self._add_commit_rtag(rtag_type, who)
|
2012-01-14 15:12:45 +00:00
|
|
|
# Remove Tested-by self, since few will take much notice
|
2020-07-06 03:41:57 +00:00
|
|
|
if (rtag_type == 'Tested-by' and
|
|
|
|
who.find(os.getenv('USER') + '@') != -1):
|
2020-10-30 03:46:28 +00:00
|
|
|
self._add_warn("Ignoring '%s'" % line)
|
2020-07-06 03:41:57 +00:00
|
|
|
elif rtag_type == 'Patch-cc':
|
|
|
|
self.commit.AddCc(who.split(','))
|
2012-01-14 15:12:45 +00:00
|
|
|
else:
|
2014-08-28 15:43:38 +00:00
|
|
|
out = [line]
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2014-04-20 16:50:14 +00:00
|
|
|
# Suppress duplicate signoffs
|
|
|
|
elif signoff_match:
|
2014-08-28 15:43:35 +00:00
|
|
|
if (self.is_log or not self.commit or
|
2020-10-30 03:46:17 +00:00
|
|
|
self.commit.CheckDuplicateSignoff(signoff_match.group(1))):
|
2014-04-20 16:50:14 +00:00
|
|
|
out = [line]
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# Well that means this is an ordinary line
|
|
|
|
else:
|
|
|
|
# Look for space before tab
|
2020-10-30 03:46:20 +00:00
|
|
|
mat = RE_SPACE_BEFORE_TAB.match(line)
|
|
|
|
if mat:
|
2020-10-30 03:46:23 +00:00
|
|
|
self._add_warn('Line %d/%d has space before tab' %
|
|
|
|
(self.linenum, mat.start()))
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# OK, we have a valid non-blank line
|
|
|
|
out = [line]
|
|
|
|
self.linenum += 1
|
|
|
|
self.skip_blank = False
|
2020-10-30 03:46:37 +00:00
|
|
|
|
|
|
|
if diff_match:
|
|
|
|
self.cur_diff = diff_match.group(1)
|
|
|
|
|
|
|
|
# If this is quoted, keep recent lines
|
|
|
|
if not diff_match and self.linenum > 1 and line:
|
|
|
|
if line.startswith('>'):
|
|
|
|
if not self.was_quoted:
|
|
|
|
self._finalise_snippet()
|
|
|
|
self.recent_line = None
|
|
|
|
if not line_match:
|
|
|
|
self.recent_quoted.append(line)
|
|
|
|
self.was_quoted = True
|
|
|
|
self.recent_diff = self.cur_diff
|
|
|
|
else:
|
|
|
|
self.recent_unquoted.put(line)
|
|
|
|
self.was_quoted = False
|
|
|
|
|
|
|
|
if line_match:
|
|
|
|
self.recent_line = line_match.groups()
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
if self.state == STATE_DIFFS:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# If this is the start of the diffs section, emit our tags and
|
|
|
|
# change log
|
|
|
|
elif line == '---':
|
|
|
|
self.state = STATE_DIFFS
|
|
|
|
|
2020-05-04 20:28:34 +00:00
|
|
|
# Output the tags (signoff first), then change list
|
2012-01-14 15:12:45 +00:00
|
|
|
out = []
|
|
|
|
log = self.series.MakeChangeLog(self.commit)
|
2014-08-28 15:43:35 +00:00
|
|
|
out += [line]
|
|
|
|
if self.commit:
|
|
|
|
out += self.commit.notes
|
|
|
|
out += [''] + log
|
2012-01-14 15:12:45 +00:00
|
|
|
elif self.found_test:
|
2020-10-30 03:46:18 +00:00
|
|
|
if not RE_ALLOWED_AFTER_TEST.match(line):
|
2012-01-14 15:12:45 +00:00
|
|
|
self.lines_after_test += 1
|
|
|
|
|
|
|
|
return out
|
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def finalise(self):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Close out processing of this patch stream"""
|
2020-10-30 03:46:37 +00:00
|
|
|
self._finalise_snippet()
|
2020-10-30 03:46:19 +00:00
|
|
|
self._finalise_change()
|
|
|
|
self._close_commit()
|
2012-01-14 15:12:45 +00:00
|
|
|
if self.lines_after_test:
|
2020-10-30 03:46:23 +00:00
|
|
|
self._add_warn('Found %d lines after TEST=' % self.lines_after_test)
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def _write_message_id(self, outfd):
|
2019-09-27 16:23:56 +00:00
|
|
|
"""Write the Message-Id into the output.
|
|
|
|
|
|
|
|
This is based on the Change-Id in the original patch, the version,
|
|
|
|
and the prefix.
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
outfd (io.IOBase): Output stream file object
|
2019-09-27 16:23:56 +00:00
|
|
|
"""
|
|
|
|
if not self.commit.change_id:
|
|
|
|
return
|
|
|
|
|
|
|
|
# If the count is -1 we're testing, so use a fixed time
|
|
|
|
if self.commit.count == -1:
|
|
|
|
time_now = datetime.datetime(1999, 12, 31, 23, 59, 59)
|
|
|
|
else:
|
|
|
|
time_now = datetime.datetime.now()
|
|
|
|
|
|
|
|
# In theory there is email.utils.make_msgid() which would be nice
|
|
|
|
# to use, but it already produces something way too long and thus
|
|
|
|
# will produce ugly commit lines if someone throws this into
|
|
|
|
# a "Link:" tag in the final commit. So (sigh) roll our own.
|
|
|
|
|
|
|
|
# Start with the time; presumably we wouldn't send the same series
|
|
|
|
# with the same Change-Id at the exact same second.
|
|
|
|
parts = [time_now.strftime("%Y%m%d%H%M%S")]
|
|
|
|
|
|
|
|
# These seem like they would be nice to include.
|
|
|
|
if 'prefix' in self.series:
|
|
|
|
parts.append(self.series['prefix'])
|
|
|
|
if 'version' in self.series:
|
|
|
|
parts.append("v%s" % self.series['version'])
|
|
|
|
|
|
|
|
parts.append(str(self.commit.count + 1))
|
|
|
|
|
|
|
|
# The Change-Id must be last, right before the @
|
|
|
|
parts.append(self.commit.change_id)
|
|
|
|
|
|
|
|
# Join parts together with "." and write it out.
|
|
|
|
outfd.write('Message-Id: <%s@changeid>\n' % '.'.join(parts))
|
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def process_stream(self, infd, outfd):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Copy a stream from infd to outfd, filtering out unwanting things.
|
|
|
|
|
|
|
|
This is used to process patch files one at a time.
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
infd (io.IOBase): Input stream file object
|
|
|
|
outfd (io.IOBase): Output stream file object
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
|
|
|
# Extract the filename from each diff, for nice warnings
|
|
|
|
fname = None
|
|
|
|
last_fname = None
|
|
|
|
re_fname = re.compile('diff --git a/(.*) b/.*')
|
2019-09-27 16:23:56 +00:00
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
self._write_message_id(outfd)
|
2019-09-27 16:23:56 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
while True:
|
|
|
|
line = infd.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
2020-10-30 03:46:19 +00:00
|
|
|
out = self.process_line(line)
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# Try to detect blank lines at EOF
|
|
|
|
for line in out:
|
|
|
|
match = re_fname.match(line)
|
|
|
|
if match:
|
|
|
|
last_fname = fname
|
|
|
|
fname = match.group(1)
|
|
|
|
if line == '+':
|
|
|
|
self.blank_count += 1
|
|
|
|
else:
|
|
|
|
if self.blank_count and (line == '-- ' or match):
|
2020-10-30 03:46:23 +00:00
|
|
|
self._add_warn("Found possible blank line(s) at end of file '%s'" %
|
|
|
|
last_fname)
|
2012-01-14 15:12:45 +00:00
|
|
|
outfd.write('+\n' * self.blank_count)
|
|
|
|
outfd.write(line + '\n')
|
|
|
|
self.blank_count = 0
|
2020-10-30 03:46:19 +00:00
|
|
|
self.finalise()
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:36 +00:00
|
|
|
def insert_tags(msg, tags_to_emit):
|
|
|
|
"""Add extra tags to a commit message
|
|
|
|
|
|
|
|
The tags are added after an existing block of tags if found, otherwise at
|
|
|
|
the end.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
msg (str): Commit message
|
|
|
|
tags_to_emit (list): List of tags to emit, each a str
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
(str) new message
|
|
|
|
"""
|
|
|
|
out = []
|
|
|
|
done = False
|
|
|
|
emit_tags = False
|
|
|
|
for line in msg.splitlines():
|
|
|
|
if not done:
|
|
|
|
signoff_match = RE_SIGNOFF.match(line)
|
|
|
|
tag_match = RE_TAG.match(line)
|
|
|
|
if tag_match or signoff_match:
|
|
|
|
emit_tags = True
|
|
|
|
if emit_tags and not tag_match and not signoff_match:
|
|
|
|
out += tags_to_emit
|
|
|
|
emit_tags = False
|
|
|
|
done = True
|
|
|
|
out.append(line)
|
|
|
|
if not done:
|
|
|
|
out.append('')
|
|
|
|
out += tags_to_emit
|
|
|
|
return '\n'.join(out)
|
|
|
|
|
|
|
|
def get_list(commit_range, git_dir=None, count=None):
|
|
|
|
"""Get a log of a list of comments
|
|
|
|
|
|
|
|
This returns the output of 'git log' for the selected commits
|
|
|
|
|
|
|
|
Args:
|
|
|
|
commit_range (str): Range of commits to count (e.g. 'HEAD..base')
|
|
|
|
git_dir (str): Path to git repositiory (None to use default)
|
|
|
|
count (int): Number of commits to list, or None for no limit
|
|
|
|
|
|
|
|
Returns
|
|
|
|
str: String containing the contents of the git log
|
|
|
|
"""
|
|
|
|
params = gitutil.LogCmd(commit_range, reverse=True, count=count,
|
|
|
|
git_dir=git_dir)
|
|
|
|
return command.RunPipe([params], capture=True).stdout
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def get_metadata_for_list(commit_range, git_dir=None, count=None,
|
|
|
|
series=None, allow_overwrite=False):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Reads out patch series metadata from the commits
|
|
|
|
|
|
|
|
This does a 'git log' on the relevant commits and pulls out the tags we
|
|
|
|
are interested in.
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
commit_range (str): Range of commits to count (e.g. 'HEAD..base')
|
|
|
|
git_dir (str): Path to git repositiory (None to use default)
|
|
|
|
count (int): Number of commits to list, or None for no limit
|
|
|
|
series (Series): Object to add information into. By default a new series
|
2012-12-15 10:42:06 +00:00
|
|
|
is started.
|
2020-10-30 03:46:22 +00:00
|
|
|
allow_overwrite (bool): Allow tags to overwrite an existing tag
|
|
|
|
|
2012-12-15 10:42:06 +00:00
|
|
|
Returns:
|
2020-10-30 03:46:22 +00:00
|
|
|
Series: Object containing information about the commits.
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
2014-09-06 01:00:19 +00:00
|
|
|
if not series:
|
|
|
|
series = Series()
|
2014-09-06 01:00:23 +00:00
|
|
|
series.allow_overwrite = allow_overwrite
|
2020-10-30 03:46:36 +00:00
|
|
|
stdout = get_list(commit_range, git_dir, count)
|
2020-10-30 03:46:20 +00:00
|
|
|
pst = PatchStream(series, is_log=True)
|
2012-01-14 15:12:45 +00:00
|
|
|
for line in stdout.splitlines():
|
2020-10-30 03:46:20 +00:00
|
|
|
pst.process_line(line)
|
|
|
|
pst.finalise()
|
2012-01-14 15:12:45 +00:00
|
|
|
return series
|
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def get_metadata(branch, start, count):
|
2012-12-15 10:42:06 +00:00
|
|
|
"""Reads out patch series metadata from the commits
|
|
|
|
|
|
|
|
This does a 'git log' on the relevant commits and pulls out the tags we
|
|
|
|
are interested in.
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
branch (str): Branch to use (None for current branch)
|
|
|
|
start (int): Commit to start from: 0=branch HEAD, 1=next one, etc.
|
|
|
|
count (int): Number of commits to list
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Series: Object containing information about the commits.
|
2012-12-15 10:42:06 +00:00
|
|
|
"""
|
2020-10-30 03:46:19 +00:00
|
|
|
return get_metadata_for_list(
|
|
|
|
'%s~%d' % (branch if branch else 'HEAD', start), None, count)
|
2012-12-15 10:42:06 +00:00
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def get_metadata_for_test(text):
|
2017-05-29 21:31:31 +00:00
|
|
|
"""Process metadata from a file containing a git log. Used for tests
|
|
|
|
|
|
|
|
Args:
|
|
|
|
text:
|
2020-10-30 03:46:22 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
Series: Object containing information about the commits.
|
2017-05-29 21:31:31 +00:00
|
|
|
"""
|
|
|
|
series = Series()
|
2020-10-30 03:46:20 +00:00
|
|
|
pst = PatchStream(series, is_log=True)
|
2017-05-29 21:31:31 +00:00
|
|
|
for line in text.splitlines():
|
2020-10-30 03:46:20 +00:00
|
|
|
pst.process_line(line)
|
|
|
|
pst.finalise()
|
2017-05-29 21:31:31 +00:00
|
|
|
return series
|
|
|
|
|
2020-10-30 03:46:20 +00:00
|
|
|
def fix_patch(backup_dir, fname, series, cmt):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Fix up a patch file, by adding/removing as required.
|
|
|
|
|
|
|
|
We remove our tags from the patch file, insert changes lists, etc.
|
|
|
|
The patch file is processed in place, and overwritten.
|
|
|
|
|
|
|
|
A backup file is put into backup_dir (if not None).
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
backup_dir (str): Path to directory to use to backup the file
|
|
|
|
fname (str): Filename to patch file to process
|
|
|
|
series (Series): Series information about this patch set
|
|
|
|
cmt (Commit): Commit object for this patch file
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
Return:
|
2020-10-30 03:46:22 +00:00
|
|
|
list: A list of errors, each str, or [] if all ok.
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
|
|
|
handle, tmpname = tempfile.mkstemp()
|
2019-10-31 13:42:51 +00:00
|
|
|
outfd = os.fdopen(handle, 'w', encoding='utf-8')
|
|
|
|
infd = open(fname, 'r', encoding='utf-8')
|
2020-10-30 03:46:20 +00:00
|
|
|
pst = PatchStream(series)
|
|
|
|
pst.commit = cmt
|
|
|
|
pst.process_stream(infd, outfd)
|
2012-01-14 15:12:45 +00:00
|
|
|
infd.close()
|
|
|
|
outfd.close()
|
|
|
|
|
|
|
|
# Create a backup file if required
|
|
|
|
if backup_dir:
|
|
|
|
shutil.copy(fname, os.path.join(backup_dir, os.path.basename(fname)))
|
|
|
|
shutil.move(tmpname, fname)
|
2020-10-30 03:46:24 +00:00
|
|
|
return cmt.warn
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def fix_patches(series, fnames):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Fix up a list of patches identified by filenames
|
|
|
|
|
|
|
|
The patch files are processed in place, and overwritten.
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
series (Series): The Series object
|
|
|
|
fnames (:type: list of str): List of patch files to process
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
|
|
|
# Current workflow creates patches, so we shouldn't need a backup
|
|
|
|
backup_dir = None #tempfile.mkdtemp('clean-patch')
|
|
|
|
count = 0
|
|
|
|
for fname in fnames:
|
2020-10-30 03:46:20 +00:00
|
|
|
cmt = series.commits[count]
|
|
|
|
cmt.patch = fname
|
|
|
|
cmt.count = count
|
|
|
|
result = fix_patch(backup_dir, fname, series, cmt)
|
2012-01-14 15:12:45 +00:00
|
|
|
if result:
|
2020-10-30 03:46:30 +00:00
|
|
|
print('%d warning%s for %s:' %
|
|
|
|
(len(result), 's' if len(result) > 1 else '', fname))
|
2012-01-14 15:12:45 +00:00
|
|
|
for warn in result:
|
2020-10-30 03:46:30 +00:00
|
|
|
print('\t%s' % warn)
|
|
|
|
print()
|
2012-01-14 15:12:45 +00:00
|
|
|
count += 1
|
2020-10-30 03:46:30 +00:00
|
|
|
print('Cleaned %d patch%s' % (count, 'es' if count > 1 else ''))
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:19 +00:00
|
|
|
def insert_cover_letter(fname, series, count):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Inserts a cover letter with the required info into patch 0
|
|
|
|
|
|
|
|
Args:
|
2020-10-30 03:46:22 +00:00
|
|
|
fname (str): Input / output filename of the cover letter file
|
|
|
|
series (Series): Series object
|
|
|
|
count (int): Number of patches in the series
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
2020-10-30 03:46:20 +00:00
|
|
|
fil = open(fname, 'r')
|
|
|
|
lines = fil.readlines()
|
|
|
|
fil.close()
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:20 +00:00
|
|
|
fil = open(fname, 'w')
|
2012-01-14 15:12:45 +00:00
|
|
|
text = series.cover
|
|
|
|
prefix = series.GetPatchPrefix()
|
|
|
|
for line in lines:
|
|
|
|
if line.startswith('Subject:'):
|
2015-04-03 02:51:17 +00:00
|
|
|
# if more than 10 or 100 patches, it should say 00/xx, 000/xxx, etc
|
|
|
|
zero_repeat = int(math.log10(count)) + 1
|
|
|
|
zero = '0' * zero_repeat
|
|
|
|
line = 'Subject: [%s %s/%d] %s\n' % (prefix, zero, count, text[0])
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# Insert our cover letter
|
|
|
|
elif line.startswith('*** BLURB HERE ***'):
|
|
|
|
# First the blurb test
|
|
|
|
line = '\n'.join(text[1:]) + '\n'
|
|
|
|
if series.get('notes'):
|
|
|
|
line += '\n'.join(series.notes) + '\n'
|
|
|
|
|
|
|
|
# Now the change list
|
|
|
|
out = series.MakeChangeLog(None)
|
|
|
|
line += '\n' + '\n'.join(out)
|
2020-10-30 03:46:20 +00:00
|
|
|
fil.write(line)
|
|
|
|
fil.close()
|