aboutsummaryrefslogtreecommitdiff
path: root/contrib/gcc-changelog/git_commit.py
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-06-17 10:41:17 +0200
committerMartin Liska <mliska@suse.cz>2020-06-17 11:37:34 +0200
commit2021af0c23acaa827b5a8c5c5ba82b713f9cff1e (patch)
tree334125cdf41c3dc8c1b707c56e390270deb54673 /contrib/gcc-changelog/git_commit.py
parentf062c3f11505b70c5275e5bc0e52f3e441f8afbc (diff)
downloadgcc-2021af0c23acaa827b5a8c5c5ba82b713f9cff1e.zip
gcc-2021af0c23acaa827b5a8c5c5ba82b713f9cff1e.tar.gz
gcc-2021af0c23acaa827b5a8c5c5ba82b713f9cff1e.tar.bz2
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.
Diffstat (limited to 'contrib/gcc-changelog/git_commit.py')
-rwxr-xr-xcontrib/gcc-changelog/git_commit.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index e868e02..ab9fdbd 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: