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 | |
Simon Glass | 08e91be | 2020-07-05 21:41:57 -0600 | [diff] [blame] | 5 | import collections |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 6 | import re |
| 7 | |
| 8 | # Separates a tag: at the beginning of the subject from the rest of it |
Simon Glass | 4e77468 | 2013-03-26 13:09:40 +0000 | [diff] [blame] | 9 | re_subject_tag = re.compile('([^:\s]*):\s*(.*)') |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 10 | |
| 11 | class Commit: |
| 12 | """Holds information about a single commit/patch in the series. |
| 13 | |
| 14 | Args: |
| 15 | hash: Commit hash (as a string) |
| 16 | |
| 17 | Variables: |
| 18 | hash: Commit hash |
| 19 | subject: Subject line |
| 20 | tags: List of maintainer tag strings |
| 21 | changes: Dict containing a list of changes (single line strings). |
| 22 | The dict is indexed by change version (an integer) |
| 23 | cc_list: List of people to aliases/emails to cc on this commit |
Albert ARIBAUD | d880efd | 2013-11-12 11:14:41 +0100 | [diff] [blame] | 24 | notes: List of lines in the commit (not series) notes |
Douglas Anderson | 52b5ee8 | 2019-09-27 09:23:56 -0700 | [diff] [blame] | 25 | change_id: the Change-Id: tag that was stripped from this commit |
| 26 | and can be used to generate the Message-Id. |
Simon Glass | 08e91be | 2020-07-05 21:41:57 -0600 | [diff] [blame] | 27 | rtags: Response tags (e.g. Reviewed-by) collected by the commit, dict: |
| 28 | key: rtag type (e.g. 'Reviewed-by') |
| 29 | value: Set of people who gave that rtag, each a name/email string |
Simon Glass | 6d00f6c | 2020-10-29 21:46:24 -0600 | [diff] [blame] | 30 | warn: List of warnings for this commit, each a str |
Simon Glass | 259b64f | 2022-03-02 19:12:24 -0700 | [diff] [blame] | 31 | patch (str): Filename of the patch file for this commit |
Simon Glass | 61521ca | 2023-04-24 06:16:00 +1200 | [diff] [blame] | 32 | future (concurrent.futures.Future): Future object for processing this |
| 33 | commit, or None |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 34 | """ |
| 35 | def __init__(self, hash): |
| 36 | self.hash = hash |
Simon Glass | 547cba6 | 2022-02-11 13:23:18 -0700 | [diff] [blame] | 37 | self.subject = '' |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 38 | self.tags = [] |
| 39 | self.changes = {} |
| 40 | self.cc_list = [] |
Simon Glass | 46b3421 | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 41 | self.signoff_set = set() |
Albert ARIBAUD | d880efd | 2013-11-12 11:14:41 +0100 | [diff] [blame] | 42 | self.notes = [] |
Douglas Anderson | 52b5ee8 | 2019-09-27 09:23:56 -0700 | [diff] [blame] | 43 | self.change_id = None |
Simon Glass | 08e91be | 2020-07-05 21:41:57 -0600 | [diff] [blame] | 44 | self.rtags = collections.defaultdict(set) |
Simon Glass | 6d00f6c | 2020-10-29 21:46:24 -0600 | [diff] [blame] | 45 | self.warn = [] |
Simon Glass | 259b64f | 2022-03-02 19:12:24 -0700 | [diff] [blame] | 46 | self.patch = '' |
Simon Glass | 61521ca | 2023-04-24 06:16:00 +1200 | [diff] [blame] | 47 | self.future = None |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 48 | |
Simon Glass | 5387de3 | 2020-10-29 21:46:32 -0600 | [diff] [blame] | 49 | def __str__(self): |
| 50 | return self.subject |
| 51 | |
Simon Glass | 530ac27 | 2022-01-29 14:14:07 -0700 | [diff] [blame] | 52 | def add_change(self, version, info): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 53 | """Add a new change line to the change list for a version. |
| 54 | |
| 55 | Args: |
| 56 | version: Patch set version (integer: 1, 2, 3) |
| 57 | info: Description of change in this version |
| 58 | """ |
| 59 | if not self.changes.get(version): |
| 60 | self.changes[version] = [] |
| 61 | self.changes[version].append(info) |
| 62 | |
Simon Glass | 530ac27 | 2022-01-29 14:14:07 -0700 | [diff] [blame] | 63 | def check_tags(self): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 64 | """Create a list of subject tags in the commit |
| 65 | |
| 66 | Subject tags look like this: |
| 67 | |
Simon Glass | 14ab6aa | 2013-03-26 13:09:41 +0000 | [diff] [blame] | 68 | propounder: fort: Change the widget to propound correctly |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 69 | |
Simon Glass | 14ab6aa | 2013-03-26 13:09:41 +0000 | [diff] [blame] | 70 | Here the tags are propounder and fort. Multiple tags are supported. |
| 71 | The list is updated in self.tag. |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 72 | |
| 73 | Returns: |
| 74 | None if ok, else the name of a tag with no email alias |
| 75 | """ |
| 76 | str = self.subject |
| 77 | m = True |
| 78 | while m: |
| 79 | m = re_subject_tag.match(str) |
| 80 | if m: |
| 81 | tag = m.group(1) |
| 82 | self.tags.append(tag) |
| 83 | str = m.group(2) |
| 84 | return None |
| 85 | |
Simon Glass | 530ac27 | 2022-01-29 14:14:07 -0700 | [diff] [blame] | 86 | def add_cc(self, cc_list): |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 87 | """Add a list of people to Cc when we send this patch. |
| 88 | |
| 89 | Args: |
| 90 | cc_list: List of aliases or email addresses |
| 91 | """ |
| 92 | self.cc_list += cc_list |
Simon Glass | 46b3421 | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 93 | |
Simon Glass | 530ac27 | 2022-01-29 14:14:07 -0700 | [diff] [blame] | 94 | def check_duplicate_signoff(self, signoff): |
Simon Glass | 46b3421 | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 95 | """Check a list of signoffs we have send for this patch |
| 96 | |
| 97 | Args: |
| 98 | signoff: Signoff line |
| 99 | Returns: |
| 100 | True if this signoff is new, False if we have already seen it. |
| 101 | """ |
| 102 | if signoff in self.signoff_set: |
| 103 | return False |
| 104 | self.signoff_set.add(signoff) |
| 105 | return True |
Simon Glass | 08e91be | 2020-07-05 21:41:57 -0600 | [diff] [blame] | 106 | |
Simon Glass | 530ac27 | 2022-01-29 14:14:07 -0700 | [diff] [blame] | 107 | def add_rtag(self, rtag_type, who): |
Simon Glass | 08e91be | 2020-07-05 21:41:57 -0600 | [diff] [blame] | 108 | """Add a response tag to a commit |
| 109 | |
| 110 | Args: |
| 111 | key: rtag type (e.g. 'Reviewed-by') |
| 112 | who: Person who gave that rtag, e.g. 'Fred Bloggs <fred@bloggs.org>' |
| 113 | """ |
| 114 | self.rtags[rtag_type].add(who) |