gcc-changelog: support 'This revert commit' prefix.
authorMartin Liska <mliska@suse.cz>
Tue, 30 Jun 2020 08:32:34 +0000 (10:32 +0200)
committerMartin Liska <mliska@suse.cz>
Tue, 30 Jun 2020 08:56:06 +0000 (10:56 +0200)
contrib/ChangeLog:

* gcc-changelog/git_check_commit.py: Print revision
of original_info.
* gcc-changelog/git_commit.py: Support Revert commits.

contrib/gcc-changelog/git_check_commit.py
contrib/gcc-changelog/git_commit.py

index ab6da05744a7f3bbbf1e03cef521429668d77ba5..935425ef8132153e002298e2e9edb1fbf78305e3 100755 (executable)
@@ -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()
index 9d821a8940dd28e77cab8bab9a7a830e2c493319..4d003ccf496a433108f2b345cc8bfb61fbeda0c5 100755 (executable)
@@ -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: