Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 1 | # Copyright (c) 2011 The Chromium OS Authors. |
| 2 | # |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 4 | # |
| 5 | |
| 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 |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 25 | """ |
| 26 | def __init__(self, hash): |
| 27 | self.hash = hash |
| 28 | self.subject = None |
| 29 | self.tags = [] |
| 30 | self.changes = {} |
| 31 | self.cc_list = [] |
Simon Glass | 46b3421 | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 32 | self.signoff_set = set() |
Albert ARIBAUD | d880efd | 2013-11-12 11:14:41 +0100 | [diff] [blame] | 33 | self.notes = [] |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 34 | |
| 35 | def AddChange(self, version, info): |
| 36 | """Add a new change line to the change list for a version. |
| 37 | |
| 38 | Args: |
| 39 | version: Patch set version (integer: 1, 2, 3) |
| 40 | info: Description of change in this version |
| 41 | """ |
| 42 | if not self.changes.get(version): |
| 43 | self.changes[version] = [] |
| 44 | self.changes[version].append(info) |
| 45 | |
| 46 | def CheckTags(self): |
| 47 | """Create a list of subject tags in the commit |
| 48 | |
| 49 | Subject tags look like this: |
| 50 | |
Simon Glass | 14ab6aa | 2013-03-26 13:09:41 +0000 | [diff] [blame] | 51 | propounder: fort: Change the widget to propound correctly |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 52 | |
Simon Glass | 14ab6aa | 2013-03-26 13:09:41 +0000 | [diff] [blame] | 53 | Here the tags are propounder and fort. Multiple tags are supported. |
| 54 | The list is updated in self.tag. |
Simon Glass | 2613288 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 55 | |
| 56 | Returns: |
| 57 | None if ok, else the name of a tag with no email alias |
| 58 | """ |
| 59 | str = self.subject |
| 60 | m = True |
| 61 | while m: |
| 62 | m = re_subject_tag.match(str) |
| 63 | if m: |
| 64 | tag = m.group(1) |
| 65 | self.tags.append(tag) |
| 66 | str = m.group(2) |
| 67 | return None |
| 68 | |
| 69 | def AddCc(self, cc_list): |
| 70 | """Add a list of people to Cc when we send this patch. |
| 71 | |
| 72 | Args: |
| 73 | cc_list: List of aliases or email addresses |
| 74 | """ |
| 75 | self.cc_list += cc_list |
Simon Glass | 46b3421 | 2014-04-20 10:50:14 -0600 | [diff] [blame] | 76 | |
| 77 | def CheckDuplicateSignoff(self, signoff): |
| 78 | """Check a list of signoffs we have send for this patch |
| 79 | |
| 80 | Args: |
| 81 | signoff: Signoff line |
| 82 | Returns: |
| 83 | True if this signoff is new, False if we have already seen it. |
| 84 | """ |
| 85 | if signoff in self.signoff_set: |
| 86 | return False |
| 87 | self.signoff_set.add(signoff) |
| 88 | return True |