From 2021af0c23acaa827b5a8c5c5ba82b713f9cff1e Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 17 Jun 2020 10:41:17 +0200 Subject: [PATCH] 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. --- contrib/gcc-changelog/git_commit.py | 39 ++++++++++++++++++++----- contrib/gcc-changelog/git_email.py | 2 +- contrib/gcc-changelog/git_repository.py | 10 ++++++- contrib/gcc-changelog/test_email.py | 10 +++++++ contrib/gcc-changelog/test_patches.txt | 29 ++++++++++++++++++ 5 files changed, 80 insertions(+), 10 deletions(-) diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index e868e028225..ab9fdbd52fd 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -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: diff --git a/contrib/gcc-changelog/git_email.py b/contrib/gcc-changelog/git_email.py index bf74bd8b156..2083d7b7ec9 100755 --- a/contrib/gcc-changelog/git_email.py +++ b/contrib/gcc-changelog/git_email.py @@ -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. diff --git a/contrib/gcc-changelog/git_repository.py b/contrib/gcc-changelog/git_repository.py index e3b6c4d7a38..a419bd97701 100755 --- a/contrib/gcc-changelog/git_repository.py +++ b/contrib/gcc-changelog/git_repository.py @@ -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 diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py index a185b85e838..1c9f8847fe7 100755 --- a/contrib/gcc-changelog/test_email.py +++ b/contrib/gcc-changelog/test_email.py @@ -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 ') + assert '\tBackported from master:' in entry + assert '\t2020-06-11 Martin Liska ' in entry + assert '\t\t Jakub Jelinek ' in entry diff --git a/contrib/gcc-changelog/test_patches.txt b/contrib/gcc-changelog/test_patches.txt index 1dec932f783..1463fb94936 100644 --- a/contrib/gcc-changelog/test_patches.txt +++ b/contrib/gcc-changelog/test_patches.txt @@ -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 +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 +(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 + -- 2.30.2