2018-05-06 21:58:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2012-01-14 15:12:45 +00:00
|
|
|
# Copyright (c) 2011 The Chromium OS Authors.
|
|
|
|
#
|
|
|
|
|
2020-07-06 03:41:57 +00:00
|
|
|
import collections
|
2012-01-14 15:12:45 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
# Separates a tag: at the beginning of the subject from the rest of it
|
2013-03-26 13:09:40 +00:00
|
|
|
re_subject_tag = re.compile('([^:\s]*):\s*(.*)')
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
class Commit:
|
|
|
|
"""Holds information about a single commit/patch in the series.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
hash: Commit hash (as a string)
|
|
|
|
|
|
|
|
Variables:
|
|
|
|
hash: Commit hash
|
|
|
|
subject: Subject line
|
|
|
|
tags: List of maintainer tag strings
|
|
|
|
changes: Dict containing a list of changes (single line strings).
|
|
|
|
The dict is indexed by change version (an integer)
|
|
|
|
cc_list: List of people to aliases/emails to cc on this commit
|
2013-11-12 10:14:41 +00:00
|
|
|
notes: List of lines in the commit (not series) notes
|
2019-09-27 16:23:56 +00:00
|
|
|
change_id: the Change-Id: tag that was stripped from this commit
|
|
|
|
and can be used to generate the Message-Id.
|
2020-07-06 03:41:57 +00:00
|
|
|
rtags: Response tags (e.g. Reviewed-by) collected by the commit, dict:
|
|
|
|
key: rtag type (e.g. 'Reviewed-by')
|
|
|
|
value: Set of people who gave that rtag, each a name/email string
|
2020-10-30 03:46:24 +00:00
|
|
|
warn: List of warnings for this commit, each a str
|
2022-03-03 02:12:24 +00:00
|
|
|
patch (str): Filename of the patch file for this commit
|
2012-01-14 15:12:45 +00:00
|
|
|
"""
|
|
|
|
def __init__(self, hash):
|
|
|
|
self.hash = hash
|
2022-02-11 20:23:18 +00:00
|
|
|
self.subject = ''
|
2012-01-14 15:12:45 +00:00
|
|
|
self.tags = []
|
|
|
|
self.changes = {}
|
|
|
|
self.cc_list = []
|
2014-04-20 16:50:14 +00:00
|
|
|
self.signoff_set = set()
|
2013-11-12 10:14:41 +00:00
|
|
|
self.notes = []
|
2019-09-27 16:23:56 +00:00
|
|
|
self.change_id = None
|
2020-07-06 03:41:57 +00:00
|
|
|
self.rtags = collections.defaultdict(set)
|
2020-10-30 03:46:24 +00:00
|
|
|
self.warn = []
|
2022-03-03 02:12:24 +00:00
|
|
|
self.patch = ''
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2020-10-30 03:46:32 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.subject
|
|
|
|
|
2022-01-29 21:14:07 +00:00
|
|
|
def add_change(self, version, info):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Add a new change line to the change list for a version.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
version: Patch set version (integer: 1, 2, 3)
|
|
|
|
info: Description of change in this version
|
|
|
|
"""
|
|
|
|
if not self.changes.get(version):
|
|
|
|
self.changes[version] = []
|
|
|
|
self.changes[version].append(info)
|
|
|
|
|
2022-01-29 21:14:07 +00:00
|
|
|
def check_tags(self):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Create a list of subject tags in the commit
|
|
|
|
|
|
|
|
Subject tags look like this:
|
|
|
|
|
2013-03-26 13:09:41 +00:00
|
|
|
propounder: fort: Change the widget to propound correctly
|
2012-01-14 15:12:45 +00:00
|
|
|
|
2013-03-26 13:09:41 +00:00
|
|
|
Here the tags are propounder and fort. Multiple tags are supported.
|
|
|
|
The list is updated in self.tag.
|
2012-01-14 15:12:45 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
None if ok, else the name of a tag with no email alias
|
|
|
|
"""
|
|
|
|
str = self.subject
|
|
|
|
m = True
|
|
|
|
while m:
|
|
|
|
m = re_subject_tag.match(str)
|
|
|
|
if m:
|
|
|
|
tag = m.group(1)
|
|
|
|
self.tags.append(tag)
|
|
|
|
str = m.group(2)
|
|
|
|
return None
|
|
|
|
|
2022-01-29 21:14:07 +00:00
|
|
|
def add_cc(self, cc_list):
|
2012-01-14 15:12:45 +00:00
|
|
|
"""Add a list of people to Cc when we send this patch.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
cc_list: List of aliases or email addresses
|
|
|
|
"""
|
|
|
|
self.cc_list += cc_list
|
2014-04-20 16:50:14 +00:00
|
|
|
|
2022-01-29 21:14:07 +00:00
|
|
|
def check_duplicate_signoff(self, signoff):
|
2014-04-20 16:50:14 +00:00
|
|
|
"""Check a list of signoffs we have send for this patch
|
|
|
|
|
|
|
|
Args:
|
|
|
|
signoff: Signoff line
|
|
|
|
Returns:
|
|
|
|
True if this signoff is new, False if we have already seen it.
|
|
|
|
"""
|
|
|
|
if signoff in self.signoff_set:
|
|
|
|
return False
|
|
|
|
self.signoff_set.add(signoff)
|
|
|
|
return True
|
2020-07-06 03:41:57 +00:00
|
|
|
|
2022-01-29 21:14:07 +00:00
|
|
|
def add_rtag(self, rtag_type, who):
|
2020-07-06 03:41:57 +00:00
|
|
|
"""Add a response tag to a commit
|
|
|
|
|
|
|
|
Args:
|
|
|
|
key: rtag type (e.g. 'Reviewed-by')
|
|
|
|
who: Person who gave that rtag, e.g. 'Fred Bloggs <fred@bloggs.org>'
|
|
|
|
"""
|
|
|
|
self.rtags[rtag_type].add(who)
|