diff mbox series

[pushed] changelog: allow flexible "cherry picked" format.

Message ID 8b26b356-7903-352e-c0c0-51fe1e7b6c35@suse.cz
State New
Headers show
Series [pushed] changelog: allow flexible "cherry picked" format. | expand

Commit Message

Martin Liška Nov. 27, 2020, 12:44 p.m. UTC
It handles the following:
(cherry picked from commit c0c7270cc4efd896fe99f8ad5409dbef089a407f (testsuite changes only))

contrib/ChangeLog:

	* gcc-changelog/git_commit.py: Use regex for cherry pick prefix.
	* gcc-changelog/test_email.py: Test it.
	* gcc-changelog/test_patches.txt: Likewise.
---
  contrib/gcc-changelog/git_commit.py    | 20 +++++++++++---------
  contrib/gcc-changelog/test_email.py    |  2 ++
  contrib/gcc-changelog/test_patches.txt |  2 +-
  3 files changed, 14 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/contrib/gcc-changelog/git_commit.py b/contrib/gcc-changelog/git_commit.py
index 5f856660bb3..d0ac23c22aa 100755
--- a/contrib/gcc-changelog/git_commit.py
+++ b/contrib/gcc-changelog/git_commit.py
@@ -158,11 +158,11 @@  end_of_location_regex = re.compile(r'[\[<(:]')
  item_empty_regex = re.compile(r'\t(\* \S+ )?\(\S+\):\s*$')
  item_parenthesis_regex = re.compile(r'\t(\*|\(\S+\):)')
  revert_regex = re.compile(r'This reverts commit (?P<hash>\w+).$')
+cherry_pick_regex = re.compile(r'cherry picked from commit (?P<hash>\w+)')
  
  LINE_LIMIT = 100
  TAB_WIDTH = 8
  CO_AUTHORED_BY_PREFIX = 'co-authored-by: '
-CHERRY_PICK_PREFIX = '(cherry picked from commit '
  
  REVIEW_PREFIXES = ('reviewed-by: ', 'reviewed-on: ', 'signed-off-by: ',
                     'acked-by: ', 'tested-by: ', 'reported-by: ',
@@ -422,14 +422,16 @@  class GitCommit:
                      continue
                  elif lowered_line.startswith(REVIEW_PREFIXES):
                      continue
-                elif line.startswith(CHERRY_PICK_PREFIX):
-                    commit = line[len(CHERRY_PICK_PREFIX):].rstrip(')')
-                    if self.cherry_pick_commit:
-                        self.errors.append(Error('multiple cherry pick lines',
-                                                 line))
-                    else:
-                        self.cherry_pick_commit = commit
-                    continue
+                else:
+                    m = cherry_pick_regex.search(line)
+                    if m:
+                        commit = m.group('hash')
+                        if self.cherry_pick_commit:
+                            msg = 'multiple cherry pick lines'
+                            self.errors.append(Error(msg, line))
+                        else:
+                            self.cherry_pick_commit = commit
+                        continue
  
                  # ChangeLog name will be deduced later
                  if not last_entry:
diff --git a/contrib/gcc-changelog/test_email.py b/contrib/gcc-changelog/test_email.py
index e38c3e52158..579194cdc24 100755
--- a/contrib/gcc-changelog/test_email.py
+++ b/contrib/gcc-changelog/test_email.py
@@ -355,6 +355,8 @@  class TestGccChangelog(unittest.TestCase):
      def test_backport(self):
          email = self.from_patch_glob('0001-asan-fix-RTX-emission.patch')
          assert not email.errors
+        expected_hash = '8cff672cb9a132d3d3158c2edfc9a64b55292b80'
+        assert email.cherry_pick_commit == expected_hash
          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>')
diff --git a/contrib/gcc-changelog/test_patches.txt b/contrib/gcc-changelog/test_patches.txt
index 37f49c851ec..9e9c5cd893f 100644
--- a/contrib/gcc-changelog/test_patches.txt
+++ b/contrib/gcc-changelog/test_patches.txt
@@ -3145,7 +3145,7 @@  gcc/ChangeLog:
  	by using Pmode instead of ptr_mode.
  
  Co-Authored-By: Jakub Jelinek <jakub@redhat.com>
-(cherry picked from commit 8cff672cb9a132d3d3158c2edfc9a64b55292b80)
+(cherry picked from commit 8cff672cb9a132d3d3158c2edfc9a64b55292b80 (only part))
  ---
   gcc/asan.c | 1 +
   1 file changed, 1 insertion(+)