gcc-changelog: Support 'Backported from master'.

contrib/ChangeLog:

	* gcc-changelog/git_commit.py: Print 'Backported from master'
	heading to backported commits.
	* gcc-changelog/test_email.py: Test it.
	* gcc-changelog/test_patches.txt: Add new patch.
	* gcc-changelog/git_repository.py: Add commit_to_date hook.
	* gcc-changelog/git_email.py: Add fuzzy implementation
	of commit_to_date_hook.
This commit is contained in:
Martin Liska 2020-06-17 10:41:17 +02:00
parent f062c3f115
commit 2021af0c23
No known key found for this signature in database
GPG key ID: 4DC182DC0FA73785
5 changed files with 80 additions and 10 deletions

View file

@ -163,6 +163,7 @@ CHERRY_PICK_PREFIX = '(cherry picked from commit '
REVIEW_PREFIXES = ('reviewed-by: ', 'reviewed-on: ', 'signed-off-by: ',
'acked-by: ', 'tested-by: ', 'reported-by: ',
'suggested-by: ')
DATE_FORMAT = '%Y-%m-%d'
class Error:
@ -246,7 +247,7 @@ class ChangeLogEntry:
class GitCommit:
def __init__(self, hexsha, date, author, body, modified_files,
strict=True):
strict=True, commit_to_date_hook=None):
self.hexsha = hexsha
self.lines = body
self.modified_files = modified_files
@ -259,6 +260,8 @@ class GitCommit:
self.top_level_authors = []
self.co_authors = []
self.top_level_prs = []
self.cherry_pick_commit = None
self.commit_to_date_hook = commit_to_date_hook
project_files = [f for f in self.modified_files
if self.is_changelog_filename(f[0])
@ -402,6 +405,8 @@ class GitCommit:
elif lowered_line.startswith(REVIEW_PREFIXES):
continue
elif line.startswith(CHERRY_PICK_PREFIX):
commit = line[len(CHERRY_PICK_PREFIX):].rstrip(')')
self.cherry_pick_commit = commit
continue
# ChangeLog name will be deduced later
@ -592,24 +597,42 @@ class GitCommit:
err = Error(msg % (entry.folder, changelog_location), file)
self.errors.append(err)
@classmethod
def format_authors_in_changelog(cls, authors, timestamp, prefix=''):
output = ''
for i, author in enumerate(authors):
if i == 0:
output += '%s%s %s\n' % (prefix, timestamp, author)
else:
output += '%s\t %s\n' % (prefix, author)
output += '\n'
return output
def to_changelog_entries(self, use_commit_ts=False):
current_timestamp = self.date.strftime(DATE_FORMAT)
for entry in self.changelog_entries:
output = ''
timestamp = entry.datetime
if self.cherry_pick_commit:
timestamp = self.commit_to_date_hook(self.cherry_pick_commit)
if timestamp:
timestamp = timestamp.strftime(DATE_FORMAT)
if not timestamp or use_commit_ts:
timestamp = self.date.strftime('%Y-%m-%d')
timestamp = current_timestamp
authors = entry.authors if entry.authors else [self.author]
# add Co-Authored-By authors to all ChangeLog entries
for author in self.co_authors:
if author not in authors:
authors.append(author)
for i, author in enumerate(authors):
if i == 0:
output += '%s %s\n' % (timestamp, author)
else:
output += '\t %s\n' % author
output += '\n'
if self.cherry_pick_commit:
output += self.format_authors_in_changelog([self.author],
current_timestamp)
output += '\tBackported from master:\n'
output += self.format_authors_in_changelog(authors,
timestamp, '\t')
else:
output += self.format_authors_in_changelog(authors, timestamp)
for pr in entry.prs:
output += '\t%s\n' % pr
for line in entry.lines:

View file

@ -67,7 +67,7 @@ class GitEmail(GitCommit):
t = 'M'
modified_files.append((target, t))
super().__init__(None, date, author, body, modified_files,
strict=strict)
strict=strict, commit_to_date_hook=lambda x: date)
# With zero arguments, process every patch file in the ./patches directory.

View file

@ -32,6 +32,13 @@ from git_commit import GitCommit
def parse_git_revisions(repo_path, revisions, strict=False):
repo = Repo(repo_path)
def commit_to_date(commit):
try:
c = repo.commit(commit)
return datetime.utcfromtimestamp(c.committed_date)
except ValueError:
return None
parsed_commits = []
if '..' in revisions:
commits = list(repo.iter_commits(revisions))
@ -60,6 +67,7 @@ def parse_git_revisions(repo_path, revisions, strict=False):
author = '%s <%s>' % (commit.author.name, commit.author.email)
git_commit = GitCommit(commit.hexsha, date, author,
commit.message.split('\n'), modified_files,
strict=strict)
strict=strict,
commit_to_date_hook=commit_to_date)
parsed_commits.append(git_commit)
return parsed_commits

View file

@ -351,3 +351,13 @@ class TestGccChangelog(unittest.TestCase):
assert len(modified_files) == 3
assert modified_files[1] == ('gcc/ada/libgnat/s-atopar.adb', 'D')
assert modified_files[2] == ('gcc/ada/libgnat/s-aoinar.adb', 'A')
def test_backport(self):
email = self.from_patch_glob('0001-asan-fix-RTX-emission.patch')
assert not email.errors
assert len(email.changelog_entries) == 1
entry = list(email.to_changelog_entries())[0][1]
assert entry.startswith('2020-06-11 Martin Liska <mliska@suse.cz>')
assert '\tBackported from master:' in entry
assert '\t2020-06-11 Martin Liska <mliska@suse.cz>' in entry
assert '\t\t Jakub Jelinek <jakub@redhat.com>' in entry

View file

@ -3131,3 +3131,32 @@ index 60d83c30771..9e7efd13ecc 100644
+
--
2.26.2
=== 0001-asan-fix-RTX-emission.patch ===
From e1d68582022cfa2b1dc76646724b397ba2739439 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 11 Jun 2020 09:34:41 +0200
Subject: [PATCH] asan: fix RTX emission for ilp32
gcc/ChangeLog:
PR sanitizer/95634
* asan.c (asan_emit_stack_protection): Fix emission for ilp32
by using Pmode instead of ptr_mode.
Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
(cherry picked from commit 8cff672cb9a132d3d3158c2edfc9a64b55292b80)
---
gcc/asan.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/gcc/asan.c b/gcc/asan.c
index 823eb539993..4ec22162c12 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1 +1,2 @@
+
--
2.27.0