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 | |
| 5 | import re |
| 6 | |
| 7 | # 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] | 8 | re_subject_tag = re.compile('([^:\s]*):\s*(.*)') |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 9 | |
| 10 | class Commit: |
| 11 | """Holds information about a single commit/patch in the series. |
| 12 | |
| 13 | Args: |
| 14 | hash: Commit hash (as a string) |
| 15 | |
| 16 | Variables: |
| 17 | hash: Commit hash |
| 18 | subject: Subject line |
| 19 | tags: List of maintainer tag strings |
| 20 | changes: Dict containing a list of changes (single line strings). |
| 21 | The dict is indexed by change version (an integer) |
| 22 | 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] | 23 | notes: List of lines in the commit (not series) notes |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 24 | """ |
| 25 | def __init__(self, hash): |
| 26 | self.hash = hash |
| 27 | self.subject = None |
| 28 | self.tags = [] |
| 29 | self.changes = {} |
| 30 | self.cc_list = [] |
Simon Glass | 102061b | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 31 | self.signoff_set = set() |
Albert ARIBAUD | 5c8fdd9 | 2013-11-12 11:14:41 +0100 | [diff] [blame] | 32 | self.notes = [] |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 33 | |
| 34 | def AddChange(self, version, info): |
| 35 | """Add a new change line to the change list for a version. |
| 36 | |
| 37 | Args: |
| 38 | version: Patch set version (integer: 1, 2, 3) |
| 39 | info: Description of change in this version |
| 40 | """ |
| 41 | if not self.changes.get(version): |
| 42 | self.changes[version] = [] |
| 43 | self.changes[version].append(info) |
| 44 | |
| 45 | def CheckTags(self): |
| 46 | """Create a list of subject tags in the commit |
| 47 | |
| 48 | Subject tags look like this: |
| 49 | |
Simon Glass | 0d99fe0 | 2013-03-26 13:09:41 +0000 | [diff] [blame] | 50 | propounder: fort: Change the widget to propound correctly |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 51 | |
Simon Glass | 0d99fe0 | 2013-03-26 13:09:41 +0000 | [diff] [blame] | 52 | Here the tags are propounder and fort. Multiple tags are supported. |
| 53 | The list is updated in self.tag. |
Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 54 | |
| 55 | Returns: |
| 56 | None if ok, else the name of a tag with no email alias |
| 57 | """ |
| 58 | str = self.subject |
| 59 | m = True |
| 60 | while m: |
| 61 | m = re_subject_tag.match(str) |
| 62 | if m: |
| 63 | tag = m.group(1) |
| 64 | self.tags.append(tag) |
| 65 | str = m.group(2) |
| 66 | return None |
| 67 | |
| 68 | def AddCc(self, cc_list): |
| 69 | """Add a list of people to Cc when we send this patch. |
| 70 | |
| 71 | Args: |
| 72 | cc_list: List of aliases or email addresses |
| 73 | """ |
| 74 | self.cc_list += cc_list |
Simon Glass | 102061b | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 75 | |
| 76 | def CheckDuplicateSignoff(self, signoff): |
| 77 | """Check a list of signoffs we have send for this patch |
| 78 | |
| 79 | Args: |
| 80 | signoff: Signoff line |
| 81 | Returns: |
| 82 | True if this signoff is new, False if we have already seen it. |
| 83 | """ |
| 84 | if signoff in self.signoff_set: |
| 85 | return False |
| 86 | self.signoff_set.add(signoff) |
| 87 | return True |