xref: /openbmc/u-boot/tools/patman/commit.py (revision 1ace4022)
1# Copyright (c) 2011 The Chromium OS Authors.
2#
3# SPDX-License-Identifier:	GPL-2.0+
4#
5
6import re
7
8# Separates a tag: at the beginning of the subject from the rest of it
9re_subject_tag = re.compile('([^:\s]*):\s*(.*)')
10
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
24        notes: List of lines in the commit (not series) notes
25    """
26    def __init__(self, hash):
27        self.hash = hash
28        self.subject = None
29        self.tags = []
30        self.changes = {}
31        self.cc_list = []
32        self.notes = []
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
50            propounder: fort: Change the widget to propound correctly
51
52        Here the tags are propounder and fort. Multiple tags are supported.
53        The list is updated in self.tag.
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
75