]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - tools/patman/patchstream.py
buildman: Ignore conflicting tags
[karo-tx-uboot.git] / tools / patman / patchstream.py
index be40af3ed2908fb964a1b0b83a8e56f8faf71886..d630157f8f70f640858a28d66e0f00b61d74e82a 100644 (file)
@@ -1,22 +1,6 @@
 # Copyright (c) 2011 The Chromium OS Authors.
 #
-# See file CREDITS for list of people who contributed to this
-# project.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
-# MA 02111-1307 USA
+# SPDX-License-Identifier:     GPL-2.0+
 #
 
 import os
@@ -30,23 +14,32 @@ import gitutil
 from series import Series
 
 # Tags that we detect and remove
-re_remove = re.compile('^BUG=|^TEST=|^Change-Id:|^Review URL:'
-    '|Reviewed-on:|Reviewed-by:')
+re_remove = re.compile('^BUG=|^TEST=|^BRANCH=|^Change-Id:|^Review URL:'
+    '|Reviewed-on:|Commit-\w*:')
 
 # Lines which are allowed after a TEST= line
 re_allowed_after_test = re.compile('^Signed-off-by:')
 
+# Signoffs
+re_signoff = re.compile('^Signed-off-by: *(.*)')
+
 # The start of the cover letter
 re_cover = re.compile('^Cover-letter:')
 
+# A cover letter Cc
+re_cover_cc = re.compile('^Cover-letter-cc: *(.*)')
+
 # Patch series tag
-re_series = re.compile('^Series-(\w*): *(.*)')
+re_series_tag = re.compile('^Series-([a-z-]*): *(.*)')
+
+# Commit series tag
+re_commit_tag = re.compile('^Commit-([a-z-]*): *(.*)')
 
 # Commit tags that we want to collect and keep
-re_tag = re.compile('^(Tested-by|Acked-by|Signed-off-by|Cc): (.*)')
+re_tag = re.compile('^(Tested-by|Acked-by|Reviewed-by|Patch-cc): (.*)')
 
 # The start of a new commit in the git log
-re_commit = re.compile('^commit (.*)')
+re_commit = re.compile('^commit ([0-9a-f]*)$')
 
 # We detect these since checkpatch doesn't always do it
 re_space_before_tab = re.compile('^[+].* \t')
@@ -79,7 +72,6 @@ class PatchStream:
         self.in_change = 0               # Non-zero if we are in a change list
         self.blank_count = 0             # Number of blank lines stored up
         self.state = STATE_MSG_HEADER    # What state are we in?
-        self.tags = []                   # Tags collected, like Tested-by...
         self.signoff = []                # Contents of signoff line
         self.commit = None               # Current commit
 
@@ -100,22 +92,26 @@ class PatchStream:
         if self.is_log:
             self.series.AddTag(self.commit, line, name, value)
 
+    def AddToCommit(self, line, name, value):
+        """Add a new Commit-xxx tag.
+
+        When a Commit-xxx tag is detected, we come here to record it.
+
+        Args:
+            line: Source line containing tag (useful for debug/error messages)
+            name: Tag name (part after 'Commit-')
+            value: Tag value (part after 'Commit-xxx: ')
+        """
+        if name == 'notes':
+            self.in_section = 'commit-' + name
+            self.skip_blank = False
+
     def CloseCommit(self):
         """Save the current commit into our commit list, and reset our state"""
         if self.commit and self.is_log:
             self.series.AddCommit(self.commit)
             self.commit = None
 
-    def FormatTags(self, tags):
-        out_list = []
-        for tag in sorted(tags):
-            if tag.startswith('Cc:'):
-                tag_list = tag[4:].split(',')
-                out_list += gitutil.BuildEmailList(tag_list, 'Cc:')
-            else:
-                out_list.append(tag)
-        return out_list
-
     def ProcessLine(self, line):
         """Process a single line of a patch file or commit log
 
@@ -148,8 +144,11 @@ class PatchStream:
                 line = line[4:]
 
         # Handle state transition and skipping blank lines
-        series_match = re_series.match(line)
+        series_tag_match = re_series_tag.match(line)
+        commit_tag_match = re_commit_tag.match(line)
         commit_match = re_commit.match(line) if self.is_log else None
+        cover_cc_match = re_cover_cc.match(line)
+        signoff_match = re_signoff.match(line)
         tag_match = None
         if self.state == STATE_PATCH_HEADER:
             tag_match = re_tag.match(line)
@@ -174,6 +173,9 @@ class PatchStream:
                 elif self.in_section == 'notes':
                     if self.is_log:
                         self.series.notes += self.section
+                elif self.in_section == 'commit-notes':
+                    if self.is_log:
+                        self.commit.notes += self.section
                 else:
                     self.warn.append("Unknown section '%s'" % self.in_section)
                 self.in_section = None
@@ -187,7 +189,7 @@ class PatchStream:
             self.commit.subject = line
 
         # Detect the tags we want to remove, and skip blank lines
-        elif re_remove.match(line):
+        elif re_remove.match(line) and not commit_tag_match:
             self.skip_blank = True
 
             # TEST= should be the last thing in the commit, so remove
@@ -202,19 +204,27 @@ class PatchStream:
             self.in_section = 'cover'
             self.skip_blank = False
 
+        elif cover_cc_match:
+            value = cover_cc_match.group(1)
+            self.AddToSeries(line, 'cover-cc', value)
+
         # If we are in a change list, key collected lines until a blank one
         elif self.in_change:
             if is_blank:
                 # Blank line ends this change list
                 self.in_change = 0
+            elif line == '---':
+                self.in_change = 0
+                out = self.ProcessLine(line)
             else:
-                self.series.AddChange(self.in_change, self.commit, line)
+                if self.is_log:
+                    self.series.AddChange(self.in_change, self.commit, line)
             self.skip_blank = False
 
         # Detect Series-xxx tags
-        elif series_match:
-            name = series_match.group(1)
-            value = series_match.group(2)
+        elif series_tag_match:
+            name = series_tag_match.group(1)
+            value = series_tag_match.group(2)
             if name == 'changes':
                 # value is the version number: e.g. 1, or 2
                 try:
@@ -227,28 +237,36 @@ class PatchStream:
                 self.AddToSeries(line, name, value)
                 self.skip_blank = True
 
+        # Detect Commit-xxx tags
+        elif commit_tag_match:
+            name = commit_tag_match.group(1)
+            value = commit_tag_match.group(2)
+            if name == 'notes':
+                self.AddToCommit(line, name, value)
+                self.skip_blank = True
+
         # Detect the start of a new commit
         elif commit_match:
             self.CloseCommit()
-            self.commit = commit.Commit(commit_match.group(1)[:7])
+            # TODO: We should store the whole hash, and just display a subset
+            self.commit = commit.Commit(commit_match.group(1)[:8])
 
         # Detect tags in the commit message
         elif tag_match:
-            # Onlly allow a single signoff tag
-            if tag_match.group(1) == 'Signed-off-by':
-                if self.signoff:
-                    self.warn.append('Patch has more than one Signed-off-by '
-                            'tag')
-                self.signoff += [line]
-
             # Remove Tested-by self, since few will take much notice
-            elif (tag_match.group(1) == 'Tested-by' and
+            if (tag_match.group(1) == 'Tested-by' and
                     tag_match.group(2).find(os.getenv('USER') + '@') != -1):
                 self.warn.append("Ignoring %s" % line)
-            elif tag_match.group(1) == 'Cc':
+            elif tag_match.group(1) == 'Patch-cc':
                 self.commit.AddCc(tag_match.group(2).split(','))
             else:
-                self.tags.append(line);
+                out = [line]
+
+        # Suppress duplicate signoffs
+        elif signoff_match:
+            if (self.is_log or not self.commit or
+                self.commit.CheckDuplicateSignoff(signoff_match.group(1))):
+                out = [line]
 
         # Well that means this is an ordinary line
         else:
@@ -281,11 +299,11 @@ class PatchStream:
 
                 # Output the tags (signeoff first), then change list
                 out = []
-                if self.signoff:
-                    out += self.signoff
                 log = self.series.MakeChangeLog(self.commit)
-                out += self.FormatTags(self.tags)
-                out += [line] + log
+                out += [line]
+                if self.commit:
+                    out += self.commit.notes
+                out += [''] + log
             elif self.found_test:
                 if not re_allowed_after_test.match(line):
                     self.lines_after_test += 1
@@ -336,25 +354,47 @@ class PatchStream:
         self.Finalize()
 
 
-def GetMetaData(start, count):
+def GetMetaDataForList(commit_range, git_dir=None, count=None,
+                       series = None, allow_overwrite=False):
     """Reads out patch series metadata from the commits
 
     This does a 'git log' on the relevant commits and pulls out the tags we
     are interested in.
 
     Args:
-        start: Commit to start from: 0=HEAD, 1=next one, etc.
-        count: Number of commits to list
+        commit_range: Range of commits to count (e.g. 'HEAD..base')
+        git_dir: Path to git repositiory (None to use default)
+        count: Number of commits to list, or None for no limit
+        series: Series object to add information into. By default a new series
+            is started.
+        allow_overwrite: Allow tags to overwrite an existing tag
+    Returns:
+        A Series object containing information about the commits.
     """
-    pipe = [['git', 'log', '--reverse', 'HEAD~%d' % start, '-n%d' % count]]
-    stdout = command.RunPipe(pipe, capture=True)
-    series = Series()
+    if not series:
+        series = Series()
+    series.allow_overwrite = allow_overwrite
+    params = gitutil.LogCmd(commit_range,reverse=True, count=count,
+                            git_dir=git_dir)
+    stdout = command.RunPipe([params], capture=True).stdout
     ps = PatchStream(series, is_log=True)
     for line in stdout.splitlines():
         ps.ProcessLine(line)
     ps.Finalize()
     return series
 
+def GetMetaData(start, count):
+    """Reads out patch series metadata from the commits
+
+    This does a 'git log' on the relevant commits and pulls out the tags we
+    are interested in.
+
+    Args:
+        start: Commit to start from: 0=HEAD, 1=next one, etc.
+        count: Number of commits to list
+    """
+    return GetMetaDataForList('HEAD~%d' % start, None, count)
+
 def FixPatch(backup_dir, fname, series, commit):
     """Fix up a patch file, by adding/removing as required.