From: Martin Liska Date: Tue, 30 Jun 2020 08:32:34 +0000 (+0200) Subject: gcc-changelog: support 'This revert commit' prefix. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b05c4c2c5da55afb76c429453bd340fad692f195;p=gcc.git 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. --- diff --git a/contrib/gcc-changelog/git_check_commit.py b/contrib/gcc-changelog/git_check_commit.py index ab6da05744a..935425ef813 100755 --- a/contrib/gcc-changelog/git_check_commit.py +++ b/contrib/gcc-changelog/git_check_commit.py @@ -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() diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py index 9d821a8940d..4d003ccf496 100755 --- a/contrib/gcc-changelog/git_commit.py +++ b/contrib/gcc-changelog/git_commit.py @@ -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: