xref: /rk3399_rockchip-uboot/tools/patman/commit.py (revision ed9222752d148c6aa655cc189b623e73ede1b62d)
10d24de9dSSimon Glass# Copyright (c) 2011 The Chromium OS Authors.
20d24de9dSSimon Glass#
30d24de9dSSimon Glass# See file CREDITS for list of people who contributed to this
40d24de9dSSimon Glass# project.
50d24de9dSSimon Glass#
60d24de9dSSimon Glass# This program is free software; you can redistribute it and/or
70d24de9dSSimon Glass# modify it under the terms of the GNU General Public License as
80d24de9dSSimon Glass# published by the Free Software Foundation; either version 2 of
90d24de9dSSimon Glass# the License, or (at your option) any later version.
100d24de9dSSimon Glass#
110d24de9dSSimon Glass# This program is distributed in the hope that it will be useful,
120d24de9dSSimon Glass# but WITHOUT ANY WARRANTY; without even the implied warranty of
130d24de9dSSimon Glass# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
140d24de9dSSimon Glass# GNU General Public License for more details.
150d24de9dSSimon Glass#
160d24de9dSSimon Glass# You should have received a copy of the GNU General Public License
170d24de9dSSimon Glass# along with this program; if not, write to the Free Software
180d24de9dSSimon Glass# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
190d24de9dSSimon Glass# MA 02111-1307 USA
200d24de9dSSimon Glass#
210d24de9dSSimon Glass
220d24de9dSSimon Glassimport re
230d24de9dSSimon Glass
240d24de9dSSimon Glass# Separates a tag: at the beginning of the subject from the rest of it
25*ed922275SSimon Glassre_subject_tag = re.compile('([^:\s]*):\s*(.*)')
260d24de9dSSimon Glass
270d24de9dSSimon Glassclass Commit:
280d24de9dSSimon Glass    """Holds information about a single commit/patch in the series.
290d24de9dSSimon Glass
300d24de9dSSimon Glass    Args:
310d24de9dSSimon Glass        hash: Commit hash (as a string)
320d24de9dSSimon Glass
330d24de9dSSimon Glass    Variables:
340d24de9dSSimon Glass        hash: Commit hash
350d24de9dSSimon Glass        subject: Subject line
360d24de9dSSimon Glass        tags: List of maintainer tag strings
370d24de9dSSimon Glass        changes: Dict containing a list of changes (single line strings).
380d24de9dSSimon Glass            The dict is indexed by change version (an integer)
390d24de9dSSimon Glass        cc_list: List of people to aliases/emails to cc on this commit
400d24de9dSSimon Glass    """
410d24de9dSSimon Glass    def __init__(self, hash):
420d24de9dSSimon Glass        self.hash = hash
430d24de9dSSimon Glass        self.subject = None
440d24de9dSSimon Glass        self.tags = []
450d24de9dSSimon Glass        self.changes = {}
460d24de9dSSimon Glass        self.cc_list = []
470d24de9dSSimon Glass
480d24de9dSSimon Glass    def AddChange(self, version, info):
490d24de9dSSimon Glass        """Add a new change line to the change list for a version.
500d24de9dSSimon Glass
510d24de9dSSimon Glass        Args:
520d24de9dSSimon Glass            version: Patch set version (integer: 1, 2, 3)
530d24de9dSSimon Glass            info: Description of change in this version
540d24de9dSSimon Glass        """
550d24de9dSSimon Glass        if not self.changes.get(version):
560d24de9dSSimon Glass            self.changes[version] = []
570d24de9dSSimon Glass        self.changes[version].append(info)
580d24de9dSSimon Glass
590d24de9dSSimon Glass    def CheckTags(self):
600d24de9dSSimon Glass        """Create a list of subject tags in the commit
610d24de9dSSimon Glass
620d24de9dSSimon Glass        Subject tags look like this:
630d24de9dSSimon Glass
640d24de9dSSimon Glass            propounder: Change the widget to propound correctly
650d24de9dSSimon Glass
660d24de9dSSimon Glass        Multiple tags are supported. The list is updated in self.tag
670d24de9dSSimon Glass
680d24de9dSSimon Glass        Returns:
690d24de9dSSimon Glass            None if ok, else the name of a tag with no email alias
700d24de9dSSimon Glass        """
710d24de9dSSimon Glass        str = self.subject
720d24de9dSSimon Glass        m = True
730d24de9dSSimon Glass        while m:
740d24de9dSSimon Glass            m = re_subject_tag.match(str)
750d24de9dSSimon Glass            if m:
760d24de9dSSimon Glass                tag = m.group(1)
770d24de9dSSimon Glass                self.tags.append(tag)
780d24de9dSSimon Glass                str = m.group(2)
790d24de9dSSimon Glass        return None
800d24de9dSSimon Glass
810d24de9dSSimon Glass    def AddCc(self, cc_list):
820d24de9dSSimon Glass        """Add a list of people to Cc when we send this patch.
830d24de9dSSimon Glass
840d24de9dSSimon Glass        Args:
850d24de9dSSimon Glass            cc_list:    List of aliases or email addresses
860d24de9dSSimon Glass        """
870d24de9dSSimon Glass        self.cc_list += cc_list
88