gcc-changelog: support 'This revert commit' prefix.

contrib/ChangeLog:

	* gcc-changelog/git_check_commit.py: Print revision
	of original_info.
	* gcc-changelog/git_commit.py: Support Revert commits.
This commit is contained in:
Martin Liska 2020-06-30 10:32:34 +02:00
parent de4676c923
commit b05c4c2c5d
No known key found for this signature in database
GPG Key ID: 4DC182DC0FA73785
2 changed files with 21 additions and 3 deletions

View File

@ -37,7 +37,7 @@ retval = 0
for git_commit in parse_git_revisions(args.git_path, args.revisions,
not args.non_strict_mode):
res = 'OK' if git_commit.success else 'FAILED'
print('Checking %s: %s' % (git_commit.info.hexsha, res))
print('Checking %s: %s' % (git_commit.original_info.hexsha, res))
if git_commit.success:
if args.print_changelog:
git_commit.print_output()

View File

@ -159,6 +159,7 @@ LINE_LIMIT = 100
TAB_WIDTH = 8
CO_AUTHORED_BY_PREFIX = 'co-authored-by: '
CHERRY_PICK_PREFIX = '(cherry picked from commit '
REVERT_PREFIX = 'This reverts commit '
REVIEW_PREFIXES = ('reviewed-by: ', 'reviewed-on: ', 'signed-off-by: ',
'acked-by: ', 'tested-by: ', 'reported-by: ',
@ -256,6 +257,7 @@ class GitInfo:
class GitCommit:
def __init__(self, info, strict=True, commit_to_info_hook=None):
self.original_info = info
self.info = info
self.message = None
self.changes = None
@ -265,8 +267,17 @@ class GitCommit:
self.co_authors = []
self.top_level_prs = []
self.cherry_pick_commit = None
self.revert_commit = None
self.commit_to_info_hook = commit_to_info_hook
# Identify first if the commit is a Revert commit
for line in self.info.lines:
if line.startswith(REVERT_PREFIX):
self.revert_commit = line[len(REVERT_PREFIX):].rstrip('.')
break
if self.revert_commit:
self.info = self.commit_to_info_hook(self.revert_commit)
project_files = [f for f in self.info.modified_files
if self.is_changelog_filename(f[0])
or f[0] in misc_files]
@ -625,6 +636,10 @@ class GitCommit:
timestamp = info.date.strftime(DATE_FORMAT)
else:
timestamp = current_timestamp
elif self.revert_commit:
timestamp = current_timestamp
orig_date = self.original_info.date
current_timestamp = orig_date.strftime(DATE_FORMAT)
elif not timestamp or use_commit_ts:
timestamp = current_timestamp
authors = entry.authors if entry.authors else [self.info.author]
@ -633,10 +648,13 @@ class GitCommit:
if author not in authors:
authors.append(author)
if self.cherry_pick_commit:
if self.cherry_pick_commit or self.revert_commit:
output += self.format_authors_in_changelog([self.info.author],
current_timestamp)
output += '\tBackported from master:\n'
if self.cherry_pick_commit:
output += '\tBackported from master:\n'
else:
output += '\tRevert:\n'
output += self.format_authors_in_changelog(authors,
timestamp, '\t')
else: