Simon Glass | 0d24de9 | 2012-01-14 15:12:45 +0000 | [diff] [blame] | 1 | # Copyright (c) 2011 The Chromium OS Authors. |
| 2 | # |
| 3 | # See file CREDITS for list of people who contributed to this |
| 4 | # project. |
| 5 | # |
| 6 | # This program is free software; you can redistribute it and/or |
| 7 | # modify it under the terms of the GNU General Public License as |
| 8 | # published by the Free Software Foundation; either version 2 of |
| 9 | # the License, or (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program; if not, write to the Free Software |
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 19 | # MA 02111-1307 USA |
| 20 | # |
| 21 | |
| 22 | import re |
| 23 | |
| 24 | # Separates a tag: at the beginning of the subject from the rest of it |
| 25 | re_subject_tag = re.compile('([^:]*):\s*(.*)') |
| 26 | |
| 27 | class Commit: |
| 28 | """Holds information about a single commit/patch in the series. |
| 29 | |
| 30 | Args: |
| 31 | hash: Commit hash (as a string) |
| 32 | |
| 33 | Variables: |
| 34 | hash: Commit hash |
| 35 | subject: Subject line |
| 36 | tags: List of maintainer tag strings |
| 37 | changes: Dict containing a list of changes (single line strings). |
| 38 | The dict is indexed by change version (an integer) |
| 39 | cc_list: List of people to aliases/emails to cc on this commit |
| 40 | """ |
| 41 | def __init__(self, hash): |
| 42 | self.hash = hash |
| 43 | self.subject = None |
| 44 | self.tags = [] |
| 45 | self.changes = {} |
| 46 | self.cc_list = [] |
| 47 | |
| 48 | def AddChange(self, version, info): |
| 49 | """Add a new change line to the change list for a version. |
| 50 | |
| 51 | Args: |
| 52 | version: Patch set version (integer: 1, 2, 3) |
| 53 | info: Description of change in this version |
| 54 | """ |
| 55 | if not self.changes.get(version): |
| 56 | self.changes[version] = [] |
| 57 | self.changes[version].append(info) |
| 58 | |
| 59 | def CheckTags(self): |
| 60 | """Create a list of subject tags in the commit |
| 61 | |
| 62 | Subject tags look like this: |
| 63 | |
| 64 | propounder: Change the widget to propound correctly |
| 65 | |
| 66 | Multiple tags are supported. The list is updated in self.tag |
| 67 | |
| 68 | Returns: |
| 69 | None if ok, else the name of a tag with no email alias |
| 70 | """ |
| 71 | str = self.subject |
| 72 | m = True |
| 73 | while m: |
| 74 | m = re_subject_tag.match(str) |
| 75 | if m: |
| 76 | tag = m.group(1) |
| 77 | self.tags.append(tag) |
| 78 | str = m.group(2) |
| 79 | return None |
| 80 | |
| 81 | def AddCc(self, cc_list): |
| 82 | """Add a list of people to Cc when we send this patch. |
| 83 | |
| 84 | Args: |
| 85 | cc_list: List of aliases or email addresses |
| 86 | """ |
| 87 | self.cc_list += cc_list |