Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 2 | # Copyright (c) 2011 The Chromium OS Authors. |
| 3 | # |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 4 | |
Sean Anderson | 48f46d6 | 2020-05-04 16:28:34 -0400 | [diff] [blame] | 5 | from __future__ import print_function |
| 6 | |
| 7 | import collections |
Simon Glass | 620639c | 2023-03-08 10:52:54 -0800 | [diff] [blame] | 8 | import concurrent.futures |
Doug Anderson | 05416af | 2012-12-03 14:40:43 +0000 | [diff] [blame] | 9 | import itertools |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 10 | import os |
Simon Glass | 620639c | 2023-03-08 10:52:54 -0800 | [diff] [blame] | 11 | import sys |
| 12 | import time |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 13 | |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 14 | from patman import get_maintainer |
Simon Glass | a997ea5 | 2020-04-17 18:09:04 -0600 | [diff] [blame] | 15 | from patman import settings |
Simon Glass | ba1b3b9 | 2025-02-09 14:26:00 -0700 | [diff] [blame] | 16 | from u_boot_pylib import gitutil |
Simon Glass | 131444f | 2023-02-23 18:18:04 -0700 | [diff] [blame] | 17 | from u_boot_pylib import terminal |
| 18 | from u_boot_pylib import tools |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 19 | |
| 20 | # Series-xxx tags that we understand |
Simon Glass | c72f3da | 2013-03-20 16:43:00 +0000 | [diff] [blame] | 21 | valid_series = ['to', 'cc', 'version', 'changes', 'prefix', 'notes', 'name', |
Sean Anderson | dc1cd13 | 2021-10-22 19:07:04 -0400 | [diff] [blame] | 22 | 'cover_cc', 'process_log', 'links', 'patchwork_url', 'postfix'] |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 23 | |
| 24 | class Series(dict): |
| 25 | """Holds information about a patch series, including all tags. |
| 26 | |
| 27 | Vars: |
Simon Glass | 27d6f0f | 2025-05-08 06:35:42 +0200 | [diff] [blame] | 28 | cc (list of str): Aliases/emails to Cc all patches to |
| 29 | to (list of str): Aliases/emails to send patches to |
| 30 | commits (list of Commit): Commit objects, one for each patch |
| 31 | cover (list of str): Lines in the cover letter |
| 32 | notes (list of str): Lines in the notes |
| 33 | changes: (dict) List of changes for each version: |
| 34 | key (int): version number |
| 35 | value: tuple: |
| 36 | commit (Commit): Commit this relates to, or None if related to a |
| 37 | cover letter |
| 38 | info (str): change lines for this version (separated by \n) |
| 39 | allow_overwrite (bool): Allow tags to overwrite an existing tag |
| 40 | base_commit (Commit): Commit object at the base of this series |
| 41 | branch (str): Branch name of this series |
Simon Glass | 985f72a | 2025-05-10 13:05:10 +0200 | [diff] [blame] | 42 | desc (str): Description of the series (cover-letter title) |
| 43 | idnum (int or None): Database rowid |
| 44 | name (str): Series name, typically the branch name without any numeric |
| 45 | suffix |
Simon Glass | 27d6f0f | 2025-05-08 06:35:42 +0200 | [diff] [blame] | 46 | _generated_cc (dict) written in MakeCcFile() |
| 47 | key: name of patch file |
| 48 | value: list of email addresses |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 49 | """ |
| 50 | def __init__(self): |
| 51 | self.cc = [] |
| 52 | self.to = [] |
Simon Glass | c72f3da | 2013-03-20 16:43:00 +0000 | [diff] [blame] | 53 | self.cover_cc = [] |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 54 | self.commits = [] |
| 55 | self.cover = None |
| 56 | self.notes = [] |
| 57 | self.changes = {} |
Simon Glass | 29c5abc | 2013-05-02 14:46:02 +0000 | [diff] [blame] | 58 | self.allow_overwrite = False |
Simon Glass | 414f1e0 | 2025-02-27 12:27:30 -0700 | [diff] [blame] | 59 | self.base_commit = None |
| 60 | self.branch = None |
Simon Glass | 985f72a | 2025-05-10 13:05:10 +0200 | [diff] [blame] | 61 | self.desc = '' |
| 62 | self.idnum = None |
| 63 | self.name = None |
Doug Anderson | 507e8e8 | 2012-12-03 14:40:42 +0000 | [diff] [blame] | 64 | self._generated_cc = {} |
| 65 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 66 | # These make us more like a dictionary |
| 67 | def __setattr__(self, name, value): |
| 68 | self[name] = value |
| 69 | |
| 70 | def __getattr__(self, name): |
| 71 | return self[name] |
| 72 | |
Simon Glass | 985f72a | 2025-05-10 13:05:10 +0200 | [diff] [blame] | 73 | @staticmethod |
| 74 | def from_fields(idnum, name, desc): |
| 75 | ser = Series() |
| 76 | ser.idnum = idnum |
| 77 | ser.name = name |
| 78 | ser.desc = desc |
| 79 | return ser |
| 80 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 81 | def AddTag(self, commit, line, name, value): |
| 82 | """Add a new Series-xxx tag along with its value. |
| 83 | |
| 84 | Args: |
| 85 | line: Source line containing tag (useful for debug/error messages) |
| 86 | name: Tag name (part after 'Series-') |
| 87 | value: Tag value (part after 'Series-xxx: ') |
Simon Glass | 8093a8f | 2020-10-29 21:46:25 -0600 | [diff] [blame] | 88 | |
| 89 | Returns: |
| 90 | String warning if something went wrong, else None |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 91 | """ |
| 92 | # If we already have it, then add to our list |
Simon Glass | c72f3da | 2013-03-20 16:43:00 +0000 | [diff] [blame] | 93 | name = name.replace('-', '_') |
Simon Glass | 29c5abc | 2013-05-02 14:46:02 +0000 | [diff] [blame] | 94 | if name in self and not self.allow_overwrite: |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 95 | values = value.split(',') |
| 96 | values = [str.strip() for str in values] |
| 97 | if type(self[name]) != type([]): |
| 98 | raise ValueError("In %s: line '%s': Cannot add another value " |
| 99 | "'%s' to series '%s'" % |
| 100 | (commit.hash, line, values, self[name])) |
| 101 | self[name] += values |
| 102 | |
| 103 | # Otherwise just set the value |
| 104 | elif name in valid_series: |
Albert ARIBAUD | 77ec8bc | 2016-02-02 10:24:53 +0100 | [diff] [blame] | 105 | if name=="notes": |
| 106 | self[name] = [value] |
| 107 | else: |
| 108 | self[name] = value |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 109 | else: |
Simon Glass | 8093a8f | 2020-10-29 21:46:25 -0600 | [diff] [blame] | 110 | return ("In %s: line '%s': Unknown 'Series-%s': valid " |
Simon Glass | e7ecd3f | 2012-09-27 15:06:02 +0000 | [diff] [blame] | 111 | "options are %s" % (commit.hash, line, name, |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 112 | ', '.join(valid_series))) |
Simon Glass | 8093a8f | 2020-10-29 21:46:25 -0600 | [diff] [blame] | 113 | return None |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 114 | |
| 115 | def AddCommit(self, commit): |
| 116 | """Add a commit into our list of commits |
| 117 | |
| 118 | We create a list of tags in the commit subject also. |
| 119 | |
| 120 | Args: |
| 121 | commit: Commit object to add |
| 122 | """ |
Simon Glass | 530ac27 | 2022-01-29 14:14:07 -0700 | [diff] [blame] | 123 | commit.check_tags() |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 124 | self.commits.append(commit) |
| 125 | |
Simon Glass | 32f12a7e | 2025-04-07 22:51:47 +1200 | [diff] [blame] | 126 | def ShowActions(self, args, cmd, process_tags, alias): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 127 | """Show what actions we will/would perform |
| 128 | |
| 129 | Args: |
| 130 | args: List of patch files we created |
| 131 | cmd: The git command we would have run |
| 132 | process_tags: Process tags as if they were aliases |
Simon Glass | 32f12a7e | 2025-04-07 22:51:47 +1200 | [diff] [blame] | 133 | alias (dict): Alias dictionary |
| 134 | key: alias |
| 135 | value: list of aliases or email addresses |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 136 | """ |
Simon Glass | 32f12a7e | 2025-04-07 22:51:47 +1200 | [diff] [blame] | 137 | to_set = set(gitutil.build_email_list(self.to, alias)); |
| 138 | cc_set = set(gitutil.build_email_list(self.cc, alias)); |
Peter Tyser | c6af802 | 2015-01-26 11:42:21 -0600 | [diff] [blame] | 139 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 140 | col = terminal.Color() |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 141 | print('Dry run, so not doing much. But I would do this:') |
| 142 | print() |
| 143 | print('Send a total of %d patch%s with %scover letter.' % ( |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 144 | len(args), '' if len(args) == 1 else 'es', |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 145 | self.get('cover') and 'a ' or 'no ')) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 146 | |
| 147 | # TODO: Colour the patches according to whether they passed checks |
| 148 | for upto in range(len(args)): |
| 149 | commit = self.commits[upto] |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 150 | print(col.build(col.GREEN, ' %s' % args[upto])) |
Doug Anderson | 507e8e8 | 2012-12-03 14:40:42 +0000 | [diff] [blame] | 151 | cc_list = list(self._generated_cc[commit.patch]) |
Simon Glass | 3ab178f | 2019-05-14 15:53:51 -0600 | [diff] [blame] | 152 | for email in sorted(set(cc_list) - to_set - cc_set): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 153 | if email == None: |
Simon Glass | 547cba6 | 2022-02-11 13:23:18 -0700 | [diff] [blame] | 154 | email = col.build(col.YELLOW, '<alias not found>') |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 155 | if email: |
Simon Glass | 22c5834 | 2017-05-29 15:31:23 -0600 | [diff] [blame] | 156 | print(' Cc: ', email) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 157 | print |
Simon Glass | 3ab178f | 2019-05-14 15:53:51 -0600 | [diff] [blame] | 158 | for item in sorted(to_set): |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 159 | print('To:\t ', item) |
Simon Glass | 3ab178f | 2019-05-14 15:53:51 -0600 | [diff] [blame] | 160 | for item in sorted(cc_set - to_set): |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 161 | print('Cc:\t ', item) |
| 162 | print('Version: ', self.get('version')) |
| 163 | print('Prefix:\t ', self.get('prefix')) |
Sean Anderson | dc1cd13 | 2021-10-22 19:07:04 -0400 | [diff] [blame] | 164 | print('Postfix:\t ', self.get('postfix')) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 165 | if self.cover: |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 166 | print('Cover: %d lines' % len(self.cover)) |
Simon Glass | dea1ddf | 2025-04-07 22:51:44 +1200 | [diff] [blame] | 167 | cover_cc = gitutil.build_email_list(self.get('cover_cc', ''), |
Simon Glass | 32f12a7e | 2025-04-07 22:51:47 +1200 | [diff] [blame] | 168 | alias) |
Simon Glass | c72f3da | 2013-03-20 16:43:00 +0000 | [diff] [blame] | 169 | all_ccs = itertools.chain(cover_cc, *self._generated_cc.values()) |
Simon Glass | 3ab178f | 2019-05-14 15:53:51 -0600 | [diff] [blame] | 170 | for email in sorted(set(all_ccs) - to_set - cc_set): |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 171 | print(' Cc: ', email) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 172 | if cmd: |
Paul Burton | c393134 | 2016-09-27 16:03:50 +0100 | [diff] [blame] | 173 | print('Git command: %s' % cmd) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 174 | |
| 175 | def MakeChangeLog(self, commit): |
| 176 | """Create a list of changes for each version. |
| 177 | |
| 178 | Return: |
| 179 | The change log as a list of strings, one per line |
| 180 | |
Simon Glass | aa912af | 2012-10-30 06:15:16 +0000 | [diff] [blame] | 181 | Changes in v4: |
Otavio Salvador | cc1fbaa | 2012-08-18 07:46:04 +0000 | [diff] [blame] | 182 | - Jog the dial back closer to the widget |
| 183 | |
Simon Glass | aa912af | 2012-10-30 06:15:16 +0000 | [diff] [blame] | 184 | Changes in v2: |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 185 | - Fix the widget |
| 186 | - Jog the dial |
| 187 | |
Sean Anderson | 5ae4e8d | 2020-05-04 16:28:33 -0400 | [diff] [blame] | 188 | If there are no new changes in a patch, a note will be added |
| 189 | |
| 190 | (no changes since v2) |
| 191 | |
| 192 | Changes in v2: |
| 193 | - Fix the widget |
| 194 | - Jog the dial |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 195 | """ |
Sean Anderson | 48f46d6 | 2020-05-04 16:28:34 -0400 | [diff] [blame] | 196 | # Collect changes from the series and this commit |
| 197 | changes = collections.defaultdict(list) |
| 198 | for version, changelist in self.changes.items(): |
| 199 | changes[version] += changelist |
| 200 | if commit: |
| 201 | for version, changelist in commit.changes.items(): |
| 202 | changes[version] += [[commit, text] for text in changelist] |
| 203 | |
| 204 | versions = sorted(changes, reverse=True) |
Sean Anderson | 5ae4e8d | 2020-05-04 16:28:33 -0400 | [diff] [blame] | 205 | newest_version = 1 |
| 206 | if 'version' in self: |
| 207 | newest_version = max(newest_version, int(self.version)) |
| 208 | if versions: |
| 209 | newest_version = max(newest_version, versions[0]) |
| 210 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 211 | final = [] |
Simon Glass | ec1d042 | 2013-03-26 13:09:44 +0000 | [diff] [blame] | 212 | process_it = self.get('process_log', '').split(',') |
| 213 | process_it = [item.strip() for item in process_it] |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 214 | need_blank = False |
Sean Anderson | 5ae4e8d | 2020-05-04 16:28:33 -0400 | [diff] [blame] | 215 | for version in versions: |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 216 | out = [] |
Sean Anderson | 48f46d6 | 2020-05-04 16:28:34 -0400 | [diff] [blame] | 217 | for this_commit, text in changes[version]: |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 218 | if commit and this_commit != commit: |
| 219 | continue |
Simon Glass | ec1d042 | 2013-03-26 13:09:44 +0000 | [diff] [blame] | 220 | if 'uniq' not in process_it or text not in out: |
| 221 | out.append(text) |
Simon Glass | ec1d042 | 2013-03-26 13:09:44 +0000 | [diff] [blame] | 222 | if 'sort' in process_it: |
| 223 | out = sorted(out) |
Sean Anderson | 5ae4e8d | 2020-05-04 16:28:33 -0400 | [diff] [blame] | 224 | have_changes = len(out) > 0 |
| 225 | line = 'Changes in v%d:' % version |
Simon Glass | aa912af | 2012-10-30 06:15:16 +0000 | [diff] [blame] | 226 | if have_changes: |
| 227 | out.insert(0, line) |
Sean Anderson | 5ae4e8d | 2020-05-04 16:28:33 -0400 | [diff] [blame] | 228 | if version < newest_version and len(final) == 0: |
| 229 | out.insert(0, '') |
| 230 | out.insert(0, '(no changes since v%d)' % version) |
| 231 | newest_version = 0 |
| 232 | # Only add a new line if we output something |
| 233 | if need_blank: |
| 234 | out.insert(0, '') |
| 235 | need_blank = False |
Simon Glass | aa912af | 2012-10-30 06:15:16 +0000 | [diff] [blame] | 236 | final += out |
Sean Anderson | 5ae4e8d | 2020-05-04 16:28:33 -0400 | [diff] [blame] | 237 | need_blank = need_blank or have_changes |
| 238 | |
| 239 | if len(final) > 0: |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 240 | final.append('') |
Sean Anderson | 5ae4e8d | 2020-05-04 16:28:33 -0400 | [diff] [blame] | 241 | elif newest_version != 1: |
| 242 | final = ['(no changes since v1)', ''] |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 243 | return final |
| 244 | |
| 245 | def DoChecks(self): |
| 246 | """Check that each version has a change log |
| 247 | |
| 248 | Print an error if something is wrong. |
| 249 | """ |
| 250 | col = terminal.Color() |
| 251 | if self.get('version'): |
| 252 | changes_copy = dict(self.changes) |
Otavio Salvador | fe07d07 | 2012-08-13 10:08:22 +0000 | [diff] [blame] | 253 | for version in range(1, int(self.version) + 1): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 254 | if self.changes.get(version): |
| 255 | del changes_copy[version] |
| 256 | else: |
Otavio Salvador | fe07d07 | 2012-08-13 10:08:22 +0000 | [diff] [blame] | 257 | if version > 1: |
| 258 | str = 'Change log missing for v%d' % version |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 259 | print(col.build(col.RED, str)) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 260 | for version in changes_copy: |
| 261 | str = 'Change log for unknown version v%d' % version |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 262 | print(col.build(col.RED, str)) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 263 | elif self.changes: |
| 264 | str = 'Change log exists, but no version is set' |
Simon Glass | f45d374 | 2022-01-29 14:14:17 -0700 | [diff] [blame] | 265 | print(col.build(col.RED, str)) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 266 | |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 267 | def GetCcForCommit(self, commit, process_tags, warn_on_error, |
| 268 | add_maintainers, limit, get_maintainer_script, |
Simon Glass | 5750cc2 | 2025-05-07 18:02:47 +0200 | [diff] [blame] | 269 | all_skips, alias, cwd): |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 270 | """Get the email CCs to use with a particular commit |
| 271 | |
| 272 | Uses subject tags and get_maintainers.pl script to find people to cc |
| 273 | on a patch |
| 274 | |
| 275 | Args: |
| 276 | commit (Commit): Commit to process |
| 277 | process_tags (bool): Process tags as if they were aliases |
| 278 | warn_on_error (bool): True to print a warning when an alias fails to |
| 279 | match, False to ignore it. |
| 280 | add_maintainers (bool or list of str): Either: |
| 281 | True/False to call the get_maintainers to CC maintainers |
| 282 | List of maintainers to include (for testing) |
| 283 | limit (int): Limit the length of the Cc list (None if no limit) |
| 284 | get_maintainer_script (str): The file name of the get_maintainer.pl |
| 285 | script (or compatible). |
| 286 | all_skips (set of str): Updated to include the set of bouncing email |
| 287 | addresses that were dropped from the output. This is essentially |
| 288 | a return value from this function. |
Simon Glass | 9938b7b | 2025-04-07 22:51:46 +1200 | [diff] [blame] | 289 | alias (dict): Alias dictionary |
| 290 | key: alias |
| 291 | value: list of aliases or email addresses |
Simon Glass | 5750cc2 | 2025-05-07 18:02:47 +0200 | [diff] [blame] | 292 | cwd (str): Path to use for patch filenames (None to use current dir) |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 293 | |
| 294 | Returns: |
| 295 | list of str: List of email addresses to cc |
| 296 | """ |
| 297 | cc = [] |
| 298 | if process_tags: |
Simon Glass | 32f12a7e | 2025-04-07 22:51:47 +1200 | [diff] [blame] | 299 | cc += gitutil.build_email_list(commit.tags, alias, |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 300 | warn_on_error=warn_on_error) |
Simon Glass | 32f12a7e | 2025-04-07 22:51:47 +1200 | [diff] [blame] | 301 | cc += gitutil.build_email_list(commit.cc_list, alias, |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 302 | warn_on_error=warn_on_error) |
| 303 | if type(add_maintainers) == type(cc): |
| 304 | cc += add_maintainers |
| 305 | elif add_maintainers: |
Simon Glass | 5750cc2 | 2025-05-07 18:02:47 +0200 | [diff] [blame] | 306 | fname = os.path.join(cwd or '', commit.patch) |
| 307 | cc += get_maintainer.get_maintainer(get_maintainer_script, fname) |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 308 | all_skips |= set(cc) & set(settings.bounces) |
| 309 | cc = list(set(cc) - set(settings.bounces)) |
| 310 | if limit is not None: |
| 311 | cc = cc[:limit] |
| 312 | return cc |
| 313 | |
Simon Glass | 1f975b9 | 2021-01-23 08:56:15 -0700 | [diff] [blame] | 314 | def MakeCcFile(self, process_tags, cover_fname, warn_on_error, |
Simon Glass | 5750cc2 | 2025-05-07 18:02:47 +0200 | [diff] [blame] | 315 | add_maintainers, limit, get_maintainer_script, alias, |
| 316 | cwd=None): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 317 | """Make a cc file for us to use for per-commit Cc automation |
| 318 | |
Doug Anderson | 507e8e8 | 2012-12-03 14:40:42 +0000 | [diff] [blame] | 319 | Also stores in self._generated_cc to make ShowActions() faster. |
| 320 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 321 | Args: |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 322 | process_tags (bool): Process tags as if they were aliases |
| 323 | cover_fname (str): If non-None the name of the cover letter. |
| 324 | warn_on_error (bool): True to print a warning when an alias fails to |
| 325 | match, False to ignore it. |
| 326 | add_maintainers (bool or list of str): Either: |
Simon Glass | b712eed | 2017-05-29 15:31:29 -0600 | [diff] [blame] | 327 | True/False to call the get_maintainers to CC maintainers |
| 328 | List of maintainers to include (for testing) |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 329 | limit (int): Limit the length of the Cc list (None if no limit) |
| 330 | get_maintainer_script (str): The file name of the get_maintainer.pl |
Maxim Cournoyer | 3ef23e9 | 2022-12-20 00:28:46 -0500 | [diff] [blame] | 331 | script (or compatible). |
Simon Glass | 9938b7b | 2025-04-07 22:51:46 +1200 | [diff] [blame] | 332 | alias (dict): Alias dictionary |
| 333 | key: alias |
| 334 | value: list of aliases or email addresses |
Simon Glass | 5750cc2 | 2025-05-07 18:02:47 +0200 | [diff] [blame] | 335 | cwd (str): Path to use for patch filenames (None to use current dir) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 336 | Return: |
| 337 | Filename of temp file created |
| 338 | """ |
Chris Packham | e8d2a12 | 2017-09-01 20:57:53 +1200 | [diff] [blame] | 339 | col = terminal.Color() |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 340 | # Look for commit tags (of the form 'xxx:' at the start of the subject) |
| 341 | fname = '/tmp/patman.%d' % os.getpid() |
Simon Glass | f544a2d | 2019-10-31 07:42:51 -0600 | [diff] [blame] | 342 | fd = open(fname, 'w', encoding='utf-8') |
Doug Anderson | 05416af | 2012-12-03 14:40:43 +0000 | [diff] [blame] | 343 | all_ccs = [] |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 344 | all_skips = set() |
Simon Glass | 620639c | 2023-03-08 10:52:54 -0800 | [diff] [blame] | 345 | with concurrent.futures.ThreadPoolExecutor(max_workers=16) as executor: |
| 346 | for i, commit in enumerate(self.commits): |
| 347 | commit.seq = i |
| 348 | commit.future = executor.submit( |
| 349 | self.GetCcForCommit, commit, process_tags, warn_on_error, |
Simon Glass | 9938b7b | 2025-04-07 22:51:46 +1200 | [diff] [blame] | 350 | add_maintainers, limit, get_maintainer_script, all_skips, |
Simon Glass | 5750cc2 | 2025-05-07 18:02:47 +0200 | [diff] [blame] | 351 | alias, cwd) |
Simon Glass | 620639c | 2023-03-08 10:52:54 -0800 | [diff] [blame] | 352 | |
| 353 | # Show progress any commits that are taking forever |
| 354 | lastlen = 0 |
| 355 | while True: |
| 356 | left = [commit for commit in self.commits |
| 357 | if not commit.future.done()] |
| 358 | if not left: |
| 359 | break |
| 360 | names = ', '.join(f'{c.seq + 1}:{c.subject}' |
| 361 | for c in left[:2]) |
| 362 | out = f'\r{len(left)} remaining: {names}'[:79] |
| 363 | spaces = ' ' * (lastlen - len(out)) |
| 364 | if lastlen: # Don't print anything the first time |
| 365 | print(out, spaces, end='') |
| 366 | sys.stdout.flush() |
| 367 | lastlen = len(out) |
| 368 | time.sleep(.25) |
| 369 | print(f'\rdone{" " * lastlen}\r', end='') |
| 370 | print('Cc processing complete') |
| 371 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 372 | for commit in self.commits: |
Simon Glass | 620639c | 2023-03-08 10:52:54 -0800 | [diff] [blame] | 373 | cc = commit.future.result() |
Simon Glass | 0f94fa7 | 2017-05-29 15:31:30 -0600 | [diff] [blame] | 374 | all_ccs += cc |
Dmitry Torokhov | ef7f67d | 2019-10-21 20:09:56 -0700 | [diff] [blame] | 375 | print(commit.patch, '\0'.join(sorted(set(cc))), file=fd) |
Simon Glass | 0f94fa7 | 2017-05-29 15:31:30 -0600 | [diff] [blame] | 376 | self._generated_cc[commit.patch] = cc |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 377 | |
Simon Glass | 77f57df | 2023-03-08 10:52:53 -0800 | [diff] [blame] | 378 | for x in sorted(all_skips): |
| 379 | print(col.build(col.YELLOW, f'Skipping "{x}"')) |
| 380 | |
Doug Anderson | 05416af | 2012-12-03 14:40:43 +0000 | [diff] [blame] | 381 | if cover_fname: |
Simon Glass | dea1ddf | 2025-04-07 22:51:44 +1200 | [diff] [blame] | 382 | cover_cc = gitutil.build_email_list( |
Simon Glass | 32f12a7e | 2025-04-07 22:51:47 +1200 | [diff] [blame] | 383 | self.get('cover_cc', ''), alias) |
Simon Glass | 39ed6bb | 2020-02-27 18:49:23 -0700 | [diff] [blame] | 384 | cover_cc = list(set(cover_cc + all_ccs)) |
| 385 | if limit is not None: |
| 386 | cover_cc = cover_cc[:limit] |
Simon Glass | 9dfb311 | 2020-11-08 20:36:18 -0700 | [diff] [blame] | 387 | cc_list = '\0'.join([x for x in sorted(cover_cc)]) |
Robert Beckett | 3356f2c | 2019-11-13 18:39:45 +0000 | [diff] [blame] | 388 | print(cover_fname, cc_list, file=fd) |
Doug Anderson | 05416af | 2012-12-03 14:40:43 +0000 | [diff] [blame] | 389 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 390 | fd.close() |
| 391 | return fname |
| 392 | |
| 393 | def AddChange(self, version, commit, info): |
| 394 | """Add a new change line to a version. |
| 395 | |
| 396 | This will later appear in the change log. |
| 397 | |
| 398 | Args: |
Simon Glass | 27d6f0f | 2025-05-08 06:35:42 +0200 | [diff] [blame] | 399 | version (int): version number to add change list to |
| 400 | commit (Commit): Commit this relates to, or None if related to a |
| 401 | cover letter |
| 402 | info (str): change lines for this version (separated by \n) |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 403 | """ |
| 404 | if not self.changes.get(version): |
| 405 | self.changes[version] = [] |
| 406 | self.changes[version].append([commit, info]) |
| 407 | |
| 408 | def GetPatchPrefix(self): |
| 409 | """Get the patch version string |
| 410 | |
| 411 | Return: |
| 412 | Patch string, like 'RFC PATCH v5' or just 'PATCH' |
| 413 | """ |
Simon Glass | 761648b | 2022-01-29 14:14:11 -0700 | [diff] [blame] | 414 | git_prefix = gitutil.get_default_subject_prefix() |
Wu, Josh | 9873b91 | 2015-04-15 10:25:18 +0800 | [diff] [blame] | 415 | if git_prefix: |
Paul Burton | a5edb44 | 2016-09-27 16:03:49 +0100 | [diff] [blame] | 416 | git_prefix = '%s][' % git_prefix |
Wu, Josh | 9873b91 | 2015-04-15 10:25:18 +0800 | [diff] [blame] | 417 | else: |
| 418 | git_prefix = '' |
| 419 | |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 420 | version = '' |
| 421 | if self.get('version'): |
| 422 | version = ' v%s' % self['version'] |
| 423 | |
| 424 | # Get patch name prefix |
| 425 | prefix = '' |
| 426 | if self.get('prefix'): |
| 427 | prefix = '%s ' % self['prefix'] |
Sean Anderson | dc1cd13 | 2021-10-22 19:07:04 -0400 | [diff] [blame] | 428 | |
| 429 | postfix = '' |
| 430 | if self.get('postfix'): |
| 431 | postfix = ' %s' % self['postfix'] |
| 432 | return '%s%sPATCH%s%s' % (git_prefix, prefix, postfix, version) |
Simon Glass | 6dfb4dd | 2025-05-10 13:05:11 +0200 | [diff] [blame^] | 433 | |
| 434 | def get_links(self, links_str=None, cur_version=None): |
| 435 | """Look up the patchwork links for each version |
| 436 | |
| 437 | Args: |
| 438 | links_str (str): Links string to parse, or None to use self.links |
| 439 | cur_version (int): Default version to assume for un-versioned links, |
| 440 | or None to use self.version |
| 441 | |
| 442 | Return: |
| 443 | dict: |
| 444 | key (int): Version number |
| 445 | value (str): Link string |
| 446 | """ |
| 447 | if links_str is None: |
| 448 | links_str = self.links if 'links' in self else '' |
| 449 | if cur_version is None: |
| 450 | cur_version = int(self.version) if 'version' in self else 1 |
| 451 | assert isinstance(cur_version, int) |
| 452 | links = {} |
| 453 | for item in links_str.split(): |
| 454 | if ':' in item: |
| 455 | version, link = item.split(':') |
| 456 | links[int(version)] = link |
| 457 | else: |
| 458 | links[cur_version] = item |
| 459 | return links |
| 460 | |
| 461 | def build_links(self, links): |
| 462 | """Build a string containing the links |
| 463 | |
| 464 | Args: |
| 465 | links (dict): |
| 466 | key (int): Version number |
| 467 | value (str): Link string |
| 468 | |
| 469 | Return: |
| 470 | str: Link string, e.g. '2:4433 1:2872' |
| 471 | """ |
| 472 | out = '' |
| 473 | for vers in sorted(links.keys(), reverse=True): |
| 474 | out += f' {vers}:{links[vers]}' |
| 475 | return out[1:] |
| 476 | |
| 477 | def get_link_for_version(self, find_vers, links_str=None): |
| 478 | """Look up the patchwork link for a particular version |
| 479 | |
| 480 | Args: |
| 481 | find_vers (int): Version to find |
| 482 | links_str (str): Links string to parse, or None to use self.links |
| 483 | |
| 484 | Return: |
| 485 | str: Series-links entry for that version, or None if not found |
| 486 | """ |
| 487 | return self.get_links(links_str).get(find_vers) |