blob: 9537de43d391e803d09ade7c7c620d61c1253ed0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0+
Simon Glass0d24de92012-01-14 15:12:45 +00002# Copyright (c) 2011 The Chromium OS Authors.
3#
Simon Glass0d24de92012-01-14 15:12:45 +00004
Simon Glass7207e2b2020-07-05 21:41:57 -06005import collections
Simon Glass0d24de92012-01-14 15:12:45 +00006import re
7
8# Separates a tag: at the beginning of the subject from the rest of it
Simon Glassed922272013-03-26 13:09:40 +00009re_subject_tag = re.compile('([^:\s]*):\s*(.*)')
Simon Glass0d24de92012-01-14 15:12:45 +000010
11class 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 ARIBAUD5c8fdd92013-11-12 11:14:41 +010024 notes: List of lines in the commit (not series) notes
Douglas Anderson833e4192019-09-27 09:23:56 -070025 change_id: the Change-Id: tag that was stripped from this commit
26 and can be used to generate the Message-Id.
Simon Glass7207e2b2020-07-05 21:41:57 -060027 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 Glass313ef5f2020-10-29 21:46:24 -060030 warn: List of warnings for this commit, each a str
Simon Glassfc6c6632022-03-02 19:12:24 -070031 patch (str): Filename of the patch file for this commit
Simon Glass0d24de92012-01-14 15:12:45 +000032 """
33 def __init__(self, hash):
34 self.hash = hash
Simon Glass32cc6ae2022-02-11 13:23:18 -070035 self.subject = ''
Simon Glass0d24de92012-01-14 15:12:45 +000036 self.tags = []
37 self.changes = {}
38 self.cc_list = []
Simon Glass102061b2014-04-20 10:50:14 -060039 self.signoff_set = set()
Albert ARIBAUD5c8fdd92013-11-12 11:14:41 +010040 self.notes = []
Douglas Anderson833e4192019-09-27 09:23:56 -070041 self.change_id = None
Simon Glass7207e2b2020-07-05 21:41:57 -060042 self.rtags = collections.defaultdict(set)
Simon Glass313ef5f2020-10-29 21:46:24 -060043 self.warn = []
Simon Glassfc6c6632022-03-02 19:12:24 -070044 self.patch = ''
Simon Glass0d24de92012-01-14 15:12:45 +000045
Simon Glassa12ad7c2020-10-29 21:46:32 -060046 def __str__(self):
47 return self.subject
48
Simon Glassa3eeadf2022-01-29 14:14:07 -070049 def add_change(self, version, info):
Simon Glass0d24de92012-01-14 15:12:45 +000050 """Add a new change line to the change list for a version.
51
52 Args:
53 version: Patch set version (integer: 1, 2, 3)
54 info: Description of change in this version
55 """
56 if not self.changes.get(version):
57 self.changes[version] = []
58 self.changes[version].append(info)
59
Simon Glassa3eeadf2022-01-29 14:14:07 -070060 def check_tags(self):
Simon Glass0d24de92012-01-14 15:12:45 +000061 """Create a list of subject tags in the commit
62
63 Subject tags look like this:
64
Simon Glass0d99fe02013-03-26 13:09:41 +000065 propounder: fort: Change the widget to propound correctly
Simon Glass0d24de92012-01-14 15:12:45 +000066
Simon Glass0d99fe02013-03-26 13:09:41 +000067 Here the tags are propounder and fort. Multiple tags are supported.
68 The list is updated in self.tag.
Simon Glass0d24de92012-01-14 15:12:45 +000069
70 Returns:
71 None if ok, else the name of a tag with no email alias
72 """
73 str = self.subject
74 m = True
75 while m:
76 m = re_subject_tag.match(str)
77 if m:
78 tag = m.group(1)
79 self.tags.append(tag)
80 str = m.group(2)
81 return None
82
Simon Glassa3eeadf2022-01-29 14:14:07 -070083 def add_cc(self, cc_list):
Simon Glass0d24de92012-01-14 15:12:45 +000084 """Add a list of people to Cc when we send this patch.
85
86 Args:
87 cc_list: List of aliases or email addresses
88 """
89 self.cc_list += cc_list
Simon Glass102061b2014-04-20 10:50:14 -060090
Simon Glassa3eeadf2022-01-29 14:14:07 -070091 def check_duplicate_signoff(self, signoff):
Simon Glass102061b2014-04-20 10:50:14 -060092 """Check a list of signoffs we have send for this patch
93
94 Args:
95 signoff: Signoff line
96 Returns:
97 True if this signoff is new, False if we have already seen it.
98 """
99 if signoff in self.signoff_set:
100 return False
101 self.signoff_set.add(signoff)
102 return True
Simon Glass7207e2b2020-07-05 21:41:57 -0600103
Simon Glassa3eeadf2022-01-29 14:14:07 -0700104 def add_rtag(self, rtag_type, who):
Simon Glass7207e2b2020-07-05 21:41:57 -0600105 """Add a response tag to a commit
106
107 Args:
108 key: rtag type (e.g. 'Reviewed-by')
109 who: Person who gave that rtag, e.g. 'Fred Bloggs <fred@bloggs.org>'
110 """
111 self.rtags[rtag_type].add(who)