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-05-04 20:28:34 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
|
|
|
import collections
|
2012-12-03 14:40:43 +00:00
|
|
|
import itertools
|
2012-01-14 15:12:45 +00:00
|
|
|
import os
|
|
|
|
|
2020-04-18 00:09:04 +00:00
|
|
|
from patman import get_maintainer
|
|
|
|
from patman import gitutil
|
|
|
|
from patman import settings
|
|
|
|
from patman import terminal
|
|
|
|
from patman import tools
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# Series-xxx tags that we understand
|
2013-03-20 16:43:00 +00:00
|
|
|
valid_series = ['to', 'cc', 'version', 'changes', 'prefix', 'notes', 'name',
|
2021-10-22 23:07:04 +00:00
|
|
|
'cover_cc', 'process_log', 'links', 'patchwork_url', 'postfix']
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
class Series(dict):
|
|
|
|
"""Holds information about a patch series, including all tags.
|
|
|
|
|
|
|
|
Vars:
|
|
|
|
cc: List of aliases/emails to Cc all patches to
|
|
|
|
commits: List of Commit objects, one for each patch
|
|
|
|
cover: List of lines in the cover letter
|
|
|
|
notes: List of lines in the notes
|
|
|
|
changes: (dict) List of changes for each version, The key is
|
|
|
|
the integer version number
|
2013-05-02 14:46:02 +00:00
|
|
|
allow_overwrite: Allow tags to overwrite an existing tag
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
self.cc = []
|
|
|
|
self.to = []
|
2013-03-20 16:43:00 +00:00
|
|
|
self.cover_cc = []
|
2012-01-14 15:12:45 +00:00
|
|
|
self.commits = []
|
|
|
|
self.cover = None
|
|
|
|
self.notes = []
|
|
|
|
self.changes = {}
|
2013-05-02 14:46:02 +00:00
|
|
|
self.allow_overwrite = False
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2012-12-03 14:40:42 +00:00
|
|
|
# Written in MakeCcFile()
|
|
|
|
# key: name of patch file
|
|
|
|
# value: list of email addresses
|
|
|
|
self._generated_cc = {}
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
# These make us more like a dictionary
|
|
|
|
def __setattr__(self, name, value):
|
|
|
|
self[name] = value
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
return self[name]
|
|
|
|
|
|
|
|
def AddTag(self, commit, line, name, value):
|
|
|
|
"""Add a new Series-xxx tag along with its value.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
line: Source line containing tag (useful for debug/error messages)
|
|
|
|
name: Tag name (part after 'Series-')
|
|
|
|
value: Tag value (part after 'Series-xxx: ')
|
2020-10-30 03:46:25 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
String warning if something went wrong, else None
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
|
|
|
# If we already have it, then add to our list
|
2013-03-20 16:43:00 +00:00
|
|
|
name = name.replace('-', '_')
|
2013-05-02 14:46:02 +00:00
|
|
|
if name in self and not self.allow_overwrite:
|
2012-01-14 15:12:45 +00:00
|
|
|
values = value.split(',')
|
|
|
|
values = [str.strip() for str in values]
|
|
|
|
if type(self[name]) != type([]):
|
|
|
|
raise ValueError("In %s: line '%s': Cannot add another value "
|
|
|
|
"'%s' to series '%s'" %
|
|
|
|
(commit.hash, line, values, self[name]))
|
|
|
|
self[name] += values
|
|
|
|
|
|
|
|
# Otherwise just set the value
|
|
|
|
elif name in valid_series:
|
2016-02-02 09:24:53 +00:00
|
|
|
if name=="notes":
|
|
|
|
self[name] = [value]
|
|
|
|
else:
|
|
|
|
self[name] = value
|
2012-01-14 15:12:45 +00:00
|
|
|
else:
|
2020-10-30 03:46:25 +00:00
|
|
|
return ("In %s: line '%s': Unknown 'Series-%s': valid "
|
2012-09-27 15:06:02 +00:00
|
|
|
"options are %s" % (commit.hash, line, name,
|
2012-01-14 15:12:45 +00:00
|
|
|
', '.join(valid_series)))
|
2020-10-30 03:46:25 +00:00
|
|
|
return None
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
def AddCommit(self, commit):
|
|
|
|
"""Add a commit into our list of commits
|
|
|
|
|
|
|
|
We create a list of tags in the commit subject also.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
commit: Commit object to add
|
|
|
|
"""
|
2022-01-29 21:14:07 +00:00
|
|
|
commit.check_tags()
|
2012-01-14 15:12:45 +00:00
|
|
|
self.commits.append(commit)
|
|
|
|
|
|
|
|
def ShowActions(self, args, cmd, process_tags):
|
|
|
|
"""Show what actions we will/would perform
|
|
|
|
|
|
|
|
Args:
|
|
|
|
args: List of patch files we created
|
|
|
|
cmd: The git command we would have run
|
|
|
|
process_tags: Process tags as if they were aliases
|
|
|
|
"""
|
2022-01-29 21:14:11 +00:00
|
|
|
to_set = set(gitutil.build_email_list(self.to));
|
|
|
|
cc_set = set(gitutil.build_email_list(self.cc));
|
2015-01-26 17:42:21 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
col = terminal.Color()
|
2016-09-27 15:03:50 +00:00
|
|
|
print('Dry run, so not doing much. But I would do this:')
|
|
|
|
print()
|
|
|
|
print('Send a total of %d patch%s with %scover letter.' % (
|
2012-01-14 15:12:45 +00:00
|
|
|
len(args), '' if len(args) == 1 else 'es',
|
2016-09-27 15:03:50 +00:00
|
|
|
self.get('cover') and 'a ' or 'no '))
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
# TODO: Colour the patches according to whether they passed checks
|
|
|
|
for upto in range(len(args)):
|
|
|
|
commit = self.commits[upto]
|
2022-01-29 21:14:17 +00:00
|
|
|
print(col.build(col.GREEN, ' %s' % args[upto]))
|
2012-12-03 14:40:42 +00:00
|
|
|
cc_list = list(self._generated_cc[commit.patch])
|
2019-05-14 21:53:51 +00:00
|
|
|
for email in sorted(set(cc_list) - to_set - cc_set):
|
2012-01-14 15:12:45 +00:00
|
|
|
if email == None:
|
2022-02-11 20:23:18 +00:00
|
|
|
email = col.build(col.YELLOW, '<alias not found>')
|
2012-01-14 15:12:45 +00:00
|
|
|
if email:
|
2017-05-29 21:31:23 +00:00
|
|
|
print(' Cc: ', email)
|
2012-01-14 15:12:45 +00:00
|
|
|
print
|
2019-05-14 21:53:51 +00:00
|
|
|
for item in sorted(to_set):
|
2016-09-27 15:03:50 +00:00
|
|
|
print('To:\t ', item)
|
2019-05-14 21:53:51 +00:00
|
|
|
for item in sorted(cc_set - to_set):
|
2016-09-27 15:03:50 +00:00
|
|
|
print('Cc:\t ', item)
|
|
|
|
print('Version: ', self.get('version'))
|
|
|
|
print('Prefix:\t ', self.get('prefix'))
|
2021-10-22 23:07:04 +00:00
|
|
|
print('Postfix:\t ', self.get('postfix'))
|
2012-01-14 15:12:45 +00:00
|
|
|
if self.cover:
|
2016-09-27 15:03:50 +00:00
|
|
|
print('Cover: %d lines' % len(self.cover))
|
2022-01-29 21:14:11 +00:00
|
|
|
cover_cc = gitutil.build_email_list(self.get('cover_cc', ''))
|
2013-03-20 16:43:00 +00:00
|
|
|
all_ccs = itertools.chain(cover_cc, *self._generated_cc.values())
|
2019-05-14 21:53:51 +00:00
|
|
|
for email in sorted(set(all_ccs) - to_set - cc_set):
|
2016-09-27 15:03:50 +00:00
|
|
|
print(' Cc: ', email)
|
2012-01-14 15:12:45 +00:00
|
|
|
if cmd:
|
2016-09-27 15:03:50 +00:00
|
|
|
print('Git command: %s' % cmd)
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
def MakeChangeLog(self, commit):
|
|
|
|
"""Create a list of changes for each version.
|
|
|
|
|
|
|
|
Return:
|
|
|
|
The change log as a list of strings, one per line
|
|
|
|
|
2012-10-30 06:15:16 +00:00
|
|
|
Changes in v4:
|
2012-08-18 07:46:04 +00:00
|
|
|
- Jog the dial back closer to the widget
|
|
|
|
|
2012-10-30 06:15:16 +00:00
|
|
|
Changes in v2:
|
2012-01-14 15:12:45 +00:00
|
|
|
- Fix the widget
|
|
|
|
- Jog the dial
|
|
|
|
|
2020-05-04 20:28:33 +00:00
|
|
|
If there are no new changes in a patch, a note will be added
|
|
|
|
|
|
|
|
(no changes since v2)
|
|
|
|
|
|
|
|
Changes in v2:
|
|
|
|
- Fix the widget
|
|
|
|
- Jog the dial
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
2020-05-04 20:28:34 +00:00
|
|
|
# Collect changes from the series and this commit
|
|
|
|
changes = collections.defaultdict(list)
|
|
|
|
for version, changelist in self.changes.items():
|
|
|
|
changes[version] += changelist
|
|
|
|
if commit:
|
|
|
|
for version, changelist in commit.changes.items():
|
|
|
|
changes[version] += [[commit, text] for text in changelist]
|
|
|
|
|
|
|
|
versions = sorted(changes, reverse=True)
|
2020-05-04 20:28:33 +00:00
|
|
|
newest_version = 1
|
|
|
|
if 'version' in self:
|
|
|
|
newest_version = max(newest_version, int(self.version))
|
|
|
|
if versions:
|
|
|
|
newest_version = max(newest_version, versions[0])
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
final = []
|
2013-03-26 13:09:44 +00:00
|
|
|
process_it = self.get('process_log', '').split(',')
|
|
|
|
process_it = [item.strip() for item in process_it]
|
2012-01-14 15:12:45 +00:00
|
|
|
need_blank = False
|
2020-05-04 20:28:33 +00:00
|
|
|
for version in versions:
|
2012-01-14 15:12:45 +00:00
|
|
|
out = []
|
2020-05-04 20:28:34 +00:00
|
|
|
for this_commit, text in changes[version]:
|
2012-01-14 15:12:45 +00:00
|
|
|
if commit and this_commit != commit:
|
|
|
|
continue
|
2013-03-26 13:09:44 +00:00
|
|
|
if 'uniq' not in process_it or text not in out:
|
|
|
|
out.append(text)
|
|
|
|
if 'sort' in process_it:
|
|
|
|
out = sorted(out)
|
2020-05-04 20:28:33 +00:00
|
|
|
have_changes = len(out) > 0
|
|
|
|
line = 'Changes in v%d:' % version
|
2012-10-30 06:15:16 +00:00
|
|
|
if have_changes:
|
|
|
|
out.insert(0, line)
|
2020-05-04 20:28:33 +00:00
|
|
|
if version < newest_version and len(final) == 0:
|
|
|
|
out.insert(0, '')
|
|
|
|
out.insert(0, '(no changes since v%d)' % version)
|
|
|
|
newest_version = 0
|
|
|
|
# Only add a new line if we output something
|
|
|
|
if need_blank:
|
|
|
|
out.insert(0, '')
|
|
|
|
need_blank = False
|
2012-10-30 06:15:16 +00:00
|
|
|
final += out
|
2020-05-04 20:28:33 +00:00
|
|
|
need_blank = need_blank or have_changes
|
|
|
|
|
|
|
|
if len(final) > 0:
|
2012-01-14 15:12:45 +00:00
|
|
|
final.append('')
|
2020-05-04 20:28:33 +00:00
|
|
|
elif newest_version != 1:
|
|
|
|
final = ['(no changes since v1)', '']
|
2012-01-14 15:12:45 +00:00
|
|
|
return final
|
|
|
|
|
|
|
|
def DoChecks(self):
|
|
|
|
"""Check that each version has a change log
|
|
|
|
|
|
|
|
Print an error if something is wrong.
|
|
|
|
"""
|
|
|
|
col = terminal.Color()
|
|
|
|
if self.get('version'):
|
|
|
|
changes_copy = dict(self.changes)
|
2012-08-13 10:08:22 +00:00
|
|
|
for version in range(1, int(self.version) + 1):
|
2012-01-14 15:12:45 +00:00
|
|
|
if self.changes.get(version):
|
|
|
|
del changes_copy[version]
|
|
|
|
else:
|
2012-08-13 10:08:22 +00:00
|
|
|
if version > 1:
|
|
|
|
str = 'Change log missing for v%d' % version
|
2022-01-29 21:14:17 +00:00
|
|
|
print(col.build(col.RED, str))
|
2012-01-14 15:12:45 +00:00
|
|
|
for version in changes_copy:
|
|
|
|
str = 'Change log for unknown version v%d' % version
|
2022-01-29 21:14:17 +00:00
|
|
|
print(col.build(col.RED, str))
|
2012-01-14 15:12:45 +00:00
|
|
|
elif self.changes:
|
|
|
|
str = 'Change log exists, but no version is set'
|
2022-01-29 21:14:17 +00:00
|
|
|
print(col.build(col.RED, str))
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2021-01-23 15:56:15 +00:00
|
|
|
def MakeCcFile(self, process_tags, cover_fname, warn_on_error,
|
2022-12-20 05:28:46 +00:00
|
|
|
add_maintainers, limit, get_maintainer_script):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Make a cc file for us to use for per-commit Cc automation
|
|
|
|
|
2012-12-03 14:40:42 +00:00
|
|
|
Also stores in self._generated_cc to make ShowActions() faster.
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
Args:
|
|
|
|
process_tags: Process tags as if they were aliases
|
2012-12-03 14:40:43 +00:00
|
|
|
cover_fname: If non-None the name of the cover letter.
|
2021-01-23 15:56:15 +00:00
|
|
|
warn_on_error: True to print a warning when an alias fails to match,
|
|
|
|
False to ignore it.
|
2017-05-29 21:31:29 +00:00
|
|
|
add_maintainers: Either:
|
|
|
|
True/False to call the get_maintainers to CC maintainers
|
|
|
|
List of maintainers to include (for testing)
|
2020-07-06 03:41:49 +00:00
|
|
|
limit: Limit the length of the Cc list (None if no limit)
|
2022-12-20 05:28:46 +00:00
|
|
|
get_maintainer_script: The file name of the get_maintainer.pl
|
|
|
|
script (or compatible).
|
2012-01-14 15:12:45 +00:00
|
|
|
Return:
|
|
|
|
Filename of temp file created
|
|
|
|
"""
|
2017-09-01 08:57:53 +00:00
|
|
|
col = terminal.Color()
|
2012-01-14 15:12:45 +00:00
|
|
|
# Look for commit tags (of the form 'xxx:' at the start of the subject)
|
|
|
|
fname = '/tmp/patman.%d' % os.getpid()
|
2019-10-31 13:42:51 +00:00
|
|
|
fd = open(fname, 'w', encoding='utf-8')
|
2012-12-03 14:40:43 +00:00
|
|
|
all_ccs = []
|
2012-01-14 15:12:45 +00:00
|
|
|
for commit in self.commits:
|
2017-05-29 21:31:30 +00:00
|
|
|
cc = []
|
2012-01-14 15:12:45 +00:00
|
|
|
if process_tags:
|
2022-01-29 21:14:11 +00:00
|
|
|
cc += gitutil.build_email_list(commit.tags,
|
2021-01-23 15:56:15 +00:00
|
|
|
warn_on_error=warn_on_error)
|
2022-01-29 21:14:11 +00:00
|
|
|
cc += gitutil.build_email_list(commit.cc_list,
|
2021-01-23 15:56:15 +00:00
|
|
|
warn_on_error=warn_on_error)
|
2017-05-29 21:31:30 +00:00
|
|
|
if type(add_maintainers) == type(cc):
|
|
|
|
cc += add_maintainers
|
2017-05-29 21:31:29 +00:00
|
|
|
elif add_maintainers:
|
2022-12-20 05:28:46 +00:00
|
|
|
|
|
|
|
cc += get_maintainer.get_maintainer(get_maintainer_script,
|
|
|
|
commit.patch)
|
2017-09-01 08:57:53 +00:00
|
|
|
for x in set(cc) & set(settings.bounces):
|
2022-01-29 21:14:17 +00:00
|
|
|
print(col.build(col.YELLOW, 'Skipping "%s"' % x))
|
2021-01-29 14:10:08 +00:00
|
|
|
cc = list(set(cc) - set(settings.bounces))
|
2018-06-07 08:45:06 +00:00
|
|
|
if limit is not None:
|
|
|
|
cc = cc[:limit]
|
2017-05-29 21:31:30 +00:00
|
|
|
all_ccs += cc
|
2019-10-22 03:09:56 +00:00
|
|
|
print(commit.patch, '\0'.join(sorted(set(cc))), file=fd)
|
2017-05-29 21:31:30 +00:00
|
|
|
self._generated_cc[commit.patch] = cc
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2012-12-03 14:40:43 +00:00
|
|
|
if cover_fname:
|
2022-01-29 21:14:11 +00:00
|
|
|
cover_cc = gitutil.build_email_list(self.get('cover_cc', ''))
|
2020-02-28 01:49:23 +00:00
|
|
|
cover_cc = list(set(cover_cc + all_ccs))
|
|
|
|
if limit is not None:
|
|
|
|
cover_cc = cover_cc[:limit]
|
2020-11-09 03:36:18 +00:00
|
|
|
cc_list = '\0'.join([x for x in sorted(cover_cc)])
|
2019-11-13 18:39:45 +00:00
|
|
|
print(cover_fname, cc_list, file=fd)
|
2012-12-03 14:40:43 +00:00
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
fd.close()
|
|
|
|
return fname
|
|
|
|
|
|
|
|
def AddChange(self, version, commit, info):
|
|
|
|
"""Add a new change line to a version.
|
|
|
|
|
|
|
|
This will later appear in the change log.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
version: version number to add change list to
|
|
|
|
info: change line for this version
|
|
|
|
"""
|
|
|
|
if not self.changes.get(version):
|
|
|
|
self.changes[version] = []
|
|
|
|
self.changes[version].append([commit, info])
|
|
|
|
|
|
|
|
def GetPatchPrefix(self):
|
|
|
|
"""Get the patch version string
|
|
|
|
|
|
|
|
Return:
|
|
|
|
Patch string, like 'RFC PATCH v5' or just 'PATCH'
|
|
|
|
"""
|
2022-01-29 21:14:11 +00:00
|
|
|
git_prefix = gitutil.get_default_subject_prefix()
|
2015-04-15 02:25:18 +00:00
|
|
|
if git_prefix:
|
2016-09-27 15:03:49 +00:00
|
|
|
git_prefix = '%s][' % git_prefix
|
2015-04-15 02:25:18 +00:00
|
|
|
else:
|
|
|
|
git_prefix = ''
|
|
|
|
|
2012-01-14 15:12:45 +00:00
|
|
|
version = ''
|
|
|
|
if self.get('version'):
|
|
|
|
version = ' v%s' % self['version']
|
|
|
|
|
|
|
|
# Get patch name prefix
|
|
|
|
prefix = ''
|
|
|
|
if self.get('prefix'):
|
|
|
|
prefix = '%s ' % self['prefix']
|
2021-10-22 23:07:04 +00:00
|
|
|
|
|
|
|
postfix = ''
|
|
|
|
if self.get('postfix'):
|
|
|
|
postfix = ' %s' % self['postfix']
|
|
|
|
return '%s%sPATCH%s%s' % (git_prefix, prefix, postfix, version)
|