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