Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 2 | # Copyright (c) 2011 The Chromium OS Authors. |
| 3 | # |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 4 | |
Simon Glass | 7207e2b | 2020-07-05 21:41:57 -0600 | [diff] [blame] | 5 | import collections |
Simon Glass | 0d24de9 | 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 | ed92227 | 2013-03-26 13:09:40 +0000 | [diff] [blame] | 9 | re_subject_tag = re.compile('([^:\s]*):\s*(.*)') |
Simon Glass | 0d24de9 | 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 | 5c8fdd9 | 2013-11-12 11:14:41 +0100 | [diff] [blame] | 24 | notes: List of lines in the commit (not series) notes |
Douglas Anderson | 833e419 | 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 | 7207e2b | 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 | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 30 | """ |
| 31 | def __init__(self, hash): |
| 32 | self.hash = hash |
| 33 | self.subject = None |
| 34 | self.tags = [] |
| 35 | self.changes = {} |
| 36 | self.cc_list = [] |
Simon Glass | 102061b | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 37 | self.signoff_set = set() |
Albert ARIBAUD | 5c8fdd9 | 2013-11-12 11:14:41 +0100 | [diff] [blame] | 38 | self.notes = [] |
Douglas Anderson | 833e419 | 2019-09-27 09:23:56 -0700 | [diff] [blame] | 39 | self.change_id = None |
Simon Glass | 7207e2b | 2020-07-05 21:41:57 -0600 | [diff] [blame] | 40 | self.rtags = collections.defaultdict(set) |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 41 | |
| 42 | def AddChange(self, version, info): |
| 43 | """Add a new change line to the change list for a version. |
| 44 | |
| 45 | Args: |
| 46 | version: Patch set version (integer: 1, 2, 3) |
| 47 | info: Description of change in this version |
| 48 | """ |
| 49 | if not self.changes.get(version): |
| 50 | self.changes[version] = [] |
| 51 | self.changes[version].append(info) |
| 52 | |
| 53 | def CheckTags(self): |
| 54 | """Create a list of subject tags in the commit |
| 55 | |
| 56 | Subject tags look like this: |
| 57 | |
Simon Glass | 0d99fe0 | 2013-03-26 13:09:41 +0000 | [diff] [blame] | 58 | propounder: fort: Change the widget to propound correctly |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 59 | |
Simon Glass | 0d99fe0 | 2013-03-26 13:09:41 +0000 | [diff] [blame] | 60 | Here the tags are propounder and fort. Multiple tags are supported. |
| 61 | The list is updated in self.tag. |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 62 | |
| 63 | Returns: |
| 64 | None if ok, else the name of a tag with no email alias |
| 65 | """ |
| 66 | str = self.subject |
| 67 | m = True |
| 68 | while m: |
| 69 | m = re_subject_tag.match(str) |
| 70 | if m: |
| 71 | tag = m.group(1) |
| 72 | self.tags.append(tag) |
| 73 | str = m.group(2) |
| 74 | return None |
| 75 | |
| 76 | def AddCc(self, cc_list): |
| 77 | """Add a list of people to Cc when we send this patch. |
| 78 | |
| 79 | Args: |
| 80 | cc_list: List of aliases or email addresses |
| 81 | """ |
| 82 | self.cc_list += cc_list |
Simon Glass | 102061b | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 83 | |
| 84 | def CheckDuplicateSignoff(self, signoff): |
| 85 | """Check a list of signoffs we have send for this patch |
| 86 | |
| 87 | Args: |
| 88 | signoff: Signoff line |
| 89 | Returns: |
| 90 | True if this signoff is new, False if we have already seen it. |
| 91 | """ |
| 92 | if signoff in self.signoff_set: |
| 93 | return False |
| 94 | self.signoff_set.add(signoff) |
| 95 | return True |
Simon Glass | 7207e2b | 2020-07-05 21:41:57 -0600 | [diff] [blame] | 96 | |
| 97 | def AddRtag(self, rtag_type, who): |
| 98 | """Add a response tag to a commit |
| 99 | |
| 100 | Args: |
| 101 | key: rtag type (e.g. 'Reviewed-by') |
| 102 | who: Person who gave that rtag, e.g. 'Fred Bloggs <fred@bloggs.org>' |
| 103 | """ |
| 104 | self.rtags[rtag_type].add(who) |