gcc-changelog: Support 'Backported from master'.
authorMartin Liska <mliska@suse.cz>
Wed, 17 Jun 2020 08:41:17 +0000 (10:41 +0200)
committerMartin Liska <mliska@suse.cz>
Wed, 17 Jun 2020 09:37:34 +0000 (11:37 +0200)
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
contrib/gcc-changelog/git_email.py
contrib/gcc-changelog/git_repository.py
contrib/gcc-changelog/test_email.py
contrib/gcc-changelog/test_patches.txt

index e868e02822505896a9f4e3da5039ae01220b2514..ab9fdbd52fd7f94a312a8c244906c205ca1c51c7 100755 (executable)
@@ -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:
index bf74bd8b156945f0c2ec30f66b06db0357f3833a..2083d7b7ec9af3904b4f2ab3299ccac33b4933bf 100755 (executable)
@@ -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.
index e3b6c4d7a388eb80d59002e2d76d13e83a19ce82..a419bd97701b3598d792ef704b2c4dfd37c98312 100755 (executable)
@@ -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
index a185b85e8380c3b6dc6869c89e344a8bb2e60491..1c9f8847fe76ef6be21da8b64fae5773bf57c8fe 100755 (executable)
@@ -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  <mliska@suse.cz>')
+        assert '\tBackported from master:' in entry
+        assert '\t2020-06-11  Martin Liska  <mliska@suse.cz>' in entry
+        assert '\t\t    Jakub Jelinek  <jakub@redhat.com>' in entry
index 1dec932f78315764591b8c8632f7fbdc842ac553..1463fb94936142a930da37fc72ad9bf1ca6b0171 100644 (file)
@@ -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 <mliska@suse.cz>
+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 <jakub@redhat.com>
+(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
+