Hello.

I'm sending patch candidate that adds 2 new git aliases:
- gcc-backport - simple alias to 'git cherry-pick -x'
- gcc-revert - it similarly appends '(this reverts commit 
365e3cde4978c6a7dbfa50865720226254c016be)'
to a reverted commit message

The script normally parses content of a git message and adds corresponding 
'Revert:' or
'Backport from master:' lines. Right now, there's missing date of the original 
commit and
author. I hope it's acceptable.

Thoughts?
Martin
>From fd916394f66831ebe8f5cadb455d559aa3917fc3 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Thu, 14 May 2020 14:34:18 +0200
Subject: [PATCH] gcc-changelog: introduce gcc-revert and gcc-backport.

contrib/ChangeLog:

2020-05-14  Martin Liska  <mli...@suse.cz>

	* gcc-changelog/git_commit.py: Add support
	for CHERRY_PICK_PREFIX and REVERT_PREFIX.
	* gcc-changelog/test_email.py: Add 2 new tests.
	* gcc-changelog/test_patches.txt: Add 2 patches.
	* gcc-git-customization.sh: Add gcc-backport and
	gcc-revert aliases.
---
 contrib/gcc-changelog/git_commit.py    | 46 ++++++++++----
 contrib/gcc-changelog/test_email.py    | 14 ++++
 contrib/gcc-changelog/test_patches.txt | 88 ++++++++++++++++++++++++++
 contrib/gcc-git-customization.sh       |  3 +
 4 files changed, 140 insertions(+), 11 deletions(-)

diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index 5214cc36538..bf82f6206b6 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -150,6 +150,8 @@ star_prefix_regex = re.compile(r'\t\*(?P<spaces>\ *)(?P<content>.*)')
 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 '
 
 
 class Error:
@@ -221,6 +223,8 @@ class GitCommit:
         self.top_level_authors = []
         self.co_authors = []
         self.top_level_prs = []
+        self.cherry_pick = False
+        self.revert = False
 
         project_files = [f for f in self.modified_files
                          if self.is_changelog_filename(f[0])
@@ -372,7 +376,11 @@ class GitCommit:
                     last_entry.author_lines.append(author_tuple)
                     continue
 
-                if not line.startswith('\t'):
+                if line.startswith(CHERRY_PICK_PREFIX):
+                    self.cherry_pick = True
+                elif line.startswith(REVERT_PREFIX):
+                    self.revert = True
+                elif not line.startswith('\t'):
                     err = Error('line should start with a tab', line)
                     self.errors.append(err)
                 elif pr_line:
@@ -500,24 +508,40 @@ 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):
+        current_timestamp = self.date.strftime('%Y-%m-%d')
         for entry in self.changelog_entries:
             output = ''
             timestamp = entry.datetime
             if not timestamp:
                 timestamp = self.date.strftime('%Y-%m-%d')
             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)
+            if self.cherry_pick or self.revert:
+                output += self.format_authors_in_changelog(authors,
+                                                           current_timestamp)
+                if self.cherry_pick:
+                    header = 'Backport from master'
                 else:
-                    output += '\t    %s\n' % author
-            output += '\n'
+                    header = 'Revert'
+                output += '\t%s:\n' % header
+            else:
+                # add Co-Authored-By authors to all ChangeLog entries
+                for author in self.co_authors:
+                    if author not in authors:
+                        authors.append(author)
+
+                output += self.format_authors_in_changelog(authors, timestamp)
             for pr in entry.prs:
                 output += '\t%s\n' % pr
             for line in entry.lines:
diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py
index 03abc763212..e1d955a9c21 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -258,3 +258,17 @@ class TestGccChangelog(unittest.TestCase):
         email = self.from_patch_glob('0020-IPA-Avoid')
         assert (email.errors[0].message
                 == 'first line should start with a tab, asterisk and space')
+
+    def test_backport(self):
+        email = self.get_git_email('0001-Test-tree.h.patch')
+        assert len(email.changelog_entries) == 1
+        entry, output = list(email.to_changelog_entries())[0]
+        assert entry == 'gcc'
+        assert '2020-05-13  Martin Liska  <mli...@suse.cz>' in output
+        assert '\tBackport from master:' in output
+
+    def test_revert(self):
+        email = self.get_git_email('0001-Revert-i386-Add-V2DFmode.patch')
+        assert len(email.changelog_entries) == 2
+        entry, output = list(email.to_changelog_entries())[0]
+        assert 'Revert:' in output
diff --git a/contrib/gcc-changelog/test_patches.txt b/contrib/gcc-changelog/test_patches.txt
index 39e4753c0ab..991dd5440a4 100644
--- a/contrib/gcc-changelog/test_patches.txt
+++ b/contrib/gcc-changelog/test_patches.txt
@@ -2381,4 +2381,92 @@ index 00000000000..66c87d48694
 +
 -- 
 2.26.1
+=== 0001-Test-tree.h.patch ===
+From a71eeba28ffa2427d24d5b2654e93b261980b9e3 Mon Sep 17 00:00:00 2001
+From: Martin Liska <mli...@suse.cz>
+Date: Wed, 13 May 2020 13:19:22 +0200
+Subject: [PATCH] Test tree.h.
+
+gcc/ChangeLog:
+
+2020-01-03  Martin Liska  <mli...@suse.cz>
+
+	PR ipa/12345
+	* tree.h: Just test it.
+
+(cherry picked from commit a2bdf56b15b51c3a7bd988943bdbc42aa156f133)
+---
+ gcc/tree.h | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/gcc/tree.h b/gcc/tree.h
+index 9ca9ab58ec0..99a9e1a73d9 100644
+--- a/gcc/tree.h
++++ b/gcc/tree.h
+@@ -1,6 +1,8 @@
+ /* Definitions for the ubiquitous 'tree' type for GNU compilers.
+    Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ 
++
++
+ This file is part of GCC.
+ 
+ GCC is free software; you can redistribute it and/or modify it under
+-- 
+2.26.2
+
+=== 0001-Revert-i386-Add-V2DFmode.patch ===
+
+From 3bb5665870ddba0a4c6aaf264d4efb44dc6438fe Mon Sep 17 00:00:00 2001
+From: Martin Liska <mli...@suse.cz>
+Date: Thu, 14 May 2020 14:16:12 +0200
+Subject: [PATCH] Revert "i386: Add V2DFmode conversion functions [PR95046]"
+
+gcc/ChangeLog:
+
+	PR target/95046
+	* config/i386/sse.md (sse2_cvtpi2pd): Add memory to alternative 1.
+
+	(floatv2siv2df2): New expander.
+	(floatunsv2siv2df2): New insn pattern.
 
+	(fix_truncv2dfv2si2): New expander.
+	(fixuns_truncv2dfv2si2): New insn pattern.
+
+gcc/testsuite/ChangeLog:
+
+	PR target/95046
+	* gcc.target/i386/pr95046-6.c: New test.
+
+(this reverts commit 365e3cde4978c6a7dbfa50865720226254c016be)
+---
+ gcc/ChangeLog                             | 19 +++-------
+ gcc/config/i386/sse.md                    | 34 ++----------------
+ gcc/testsuite/ChangeLog                   |  5 ---
+ gcc/testsuite/gcc.target/i386/pr95046-6.c | 44 -----------------------
+ 4 files changed, 6 insertions(+), 96 deletions(-)
+ delete mode 100644 gcc/testsuite/gcc.target/i386/pr95046-6.c
+
+diff --git a/gcc/ChangeLog b/gcc/ChangeLog
+index 072ad082852..125f7c7c389 100644
+--- a/gcc/ChangeLog
++++ b/gcc/ChangeLog
+@@ -1 +1,2 @@
+
++
+diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
+index dc0ecbc182e..7a7ecd4be87 100644
+--- a/gcc/config/i386/sse.md
++++ b/gcc/config/i386/sse.md
+@@ -1 +1,2 @@
+
++
+diff --git a/gcc/testsuite/gcc.target/i386/pr95046-6.c b/gcc/testsuite/gcc.target/i386/pr95046-6.c
+deleted file mode 100644
+index dcc8999c446..00000000000
+--- a/gcc/testsuite/gcc.target/i386/pr95046-6.c
++++ /dev/null
+@@ -1 +0,0 @@
+-
+-- 
+2.26.2
diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index a932bf8c06a..7d5451a29df 100755
--- a/contrib/gcc-git-customization.sh
+++ b/contrib/gcc-git-customization.sh
@@ -25,6 +25,9 @@ git config alias.svn-rev '!f() { rev=$1; shift; git log --all --grep="^From-SVN:
 git config alias.gcc-descr \!"f() { if test \${1:-no} = --full; then c=\${2:-master}; r=\$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' \$c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-,r,p'); expr match \${r:-no} '^r[0-9]\\+\$' >/dev/null && r=\${r}-0-g\$(git rev-parse \${2:-master}); else c=\${1:-master}; r=\$(git describe --all --match 'basepoints/gcc-[0-9]*' \$c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-\\([0-9]\\+\\)-\\([0-9]\\+\\)-g[0-9a-f]*\$,r\\2-\\3,p;s,^\\(tags/\\)\\?basepoints/gcc-\\([0-9]\\+\\)\$,r\\2-0,p'); fi; if test -n \$r; then o=\$(git config --get gcc-config.upstream); rr=\$(echo \$r | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\\(-g[0-9a-f]\\+\\)\\?\$,\\1,p'); if git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$rr >/dev/null; then m=releases/gcc-\$rr; else m=master; fi; git merge-base --is-ancestor \$c \${o:-origin}/\$m && \echo \${r}; fi; }; f"
 git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream); r=\$(echo \$1 | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\$,\\1,p'); n=\$(echo \$1 | sed -n 's,^r[0-9]\\+-\\([0-9]\\+\\)\$,\\1,p'); test -z \$r && echo Invalid id \$1 && exit 1; h=\$(git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$r); test -z \$h && h=\$(git rev-parse --verify --quiet \${o:-origin}/master); p=\$(git describe --all --match 'basepoints/gcc-'\$r \$h | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+-\\([0-9]\\+\\)-g[0-9a-f]*\$,\\2,p;s,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+\$,0,p'); git rev-parse --verify \$h~\$(expr \$p - \$n); }; f"
 
+git config alias.gcc-backport '!f() { rev=$1; git cherry-pick -x $@; } ; f'
+git config alias.gcc-revert '!f() { rev=$1; git show $rev --format="Revert \"%s\"%n%n" --no-patch > commit.msg && git show $rev --format=%B --no-patch | tail -n +3 >> commit.msg && git show $rev --format="(this reverts commit %H)" --no-patch >> commit.msg && git revert -n $rev && git commit -F commit.msg; } ; f'
+
 # Make diff on MD files use "(define" as a function marker.
 # Use this in conjunction with a .gitattributes file containing
 # *.md    diff=md
-- 
2.26.2

Reply via email to