diff options
author | Tobias Burnus <tobias@codesourcery.com> | 2021-06-13 07:46:54 +0200 |
---|---|---|
committer | Tobias Burnus <tobias@codesourcery.com> | 2021-06-13 07:46:54 +0200 |
commit | d554f43c98eb07f222afef5e90b5582d65519f7e (patch) | |
tree | 5263bc35f2684032790aa17f8fc70f94f323cc87 /contrib/gcc-changelog/git_email.py | |
parent | 8b8c391279fd3d85286b918c45171b825b44b74c (diff) | |
download | gcc-d554f43c98eb07f222afef5e90b5582d65519f7e.zip gcc-d554f43c98eb07f222afef5e90b5582d65519f7e.tar.gz gcc-d554f43c98eb07f222afef5e90b5582d65519f7e.tar.bz2 |
contrib/gcc-changelog: Check that PR in subject is in changelog
This patch checks that a '[PRnnnn]' and '(PRnnnn)' also appears as PR in the
changelog part of the commit message. And it does likewise for 'PR comp/nnnn'
except that then also the component name is checked. (Note that the reverse
is permitted, i.e. PR(s) only appearing in the changelog.)
To avoid false positives, PR numbers in the subject line are ignored,
if 'revert' appears.
Additionally, reject commits with a nonempty second line.
contrib/ChangeLog:
* gcc-changelog/git_commit.py (pr_regex): Add ?P<pr> for group('pr').
(subject_pr_regex, subject_pr2_regex): New.
(GitInfo.__init__, GitCommit.parse_changelog): Check subject PRs.
* gcc-changelog/git_email.py (SUBJECT_PREFIX, subject_patch_regex): New.
(GitEmail.__init__): Parse 'Subject:' and pass it to GitInfo.
* gcc-changelog/test_email.py (test_pr_only_in_subject,
test_wrong_pr_comp_in_subject, test_copyright_years): New.
* gcc-changelog/test_patches.txt (0030-PR-c-92746, pr-check1.patch):
Update to avoid triggering the new check.
(0001-rs6000-Support-doubleword, pr-wrong-comp.patch,
copyright-years.patch): New.
Diffstat (limited to 'contrib/gcc-changelog/git_email.py')
-rwxr-xr-x | contrib/gcc-changelog/git_email.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/contrib/gcc-changelog/git_email.py b/contrib/gcc-changelog/git_email.py index fa62e3a..87b419c 100755 --- a/contrib/gcc-changelog/git_email.py +++ b/contrib/gcc-changelog/git_email.py @@ -17,6 +17,7 @@ # <http://www.gnu.org/licenses/>. */ import os +import re import sys from itertools import takewhile @@ -28,6 +29,8 @@ from unidiff import PatchSet, PatchedFile DATE_PREFIX = 'Date: ' FROM_PREFIX = 'From: ' +SUBJECT_PREFIX = 'Subject: ' +subject_patch_regex = re.compile(r'^\[PATCH( \d+/\d+)?\] ') unidiff_supports_renaming = hasattr(PatchedFile(), 'is_rename') @@ -37,7 +40,9 @@ class GitEmail(GitCommit): diff = PatchSet.from_filename(filename) date = None author = None + subject = '' + subject_last = False with open(self.filename, 'r') as f: lines = f.read().splitlines() lines = list(takewhile(lambda line: line != '---', lines)) @@ -46,8 +51,21 @@ class GitEmail(GitCommit): date = parse(line[len(DATE_PREFIX):]) elif line.startswith(FROM_PREFIX): author = GitCommit.format_git_author(line[len(FROM_PREFIX):]) + elif line.startswith(SUBJECT_PREFIX): + subject = line[len(SUBJECT_PREFIX):] + subject_last = True + elif subject_last and line.startswith(' '): + subject += line + elif line == '': + break + else: + subject_last = False + + if subject: + subject = subject_patch_regex.sub('', subject) header = list(takewhile(lambda line: line != '', lines)) - body = lines[len(header) + 1:] + # Note: commit message consists of email subject, empty line, email body + message = [subject] + lines[len(header):] modified_files = [] for f in diff: @@ -67,7 +85,7 @@ class GitEmail(GitCommit): else: t = 'M' modified_files.append((target if t != 'D' else source, t)) - git_info = GitInfo(None, date, author, body, modified_files) + git_info = GitInfo(None, date, author, message, modified_files) super().__init__(git_info, commit_to_info_hook=lambda x: None) |