]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Scripts/PatchCheck.py
BaseTools/PatchCheck: Disable text conversion in 'git show'
[mirror_edk2.git] / BaseTools / Scripts / PatchCheck.py
index 7bc5736dbf2ece138d20dc5947eef861c6ff9dac..2a4e6f603e79a7ffeaad694d11756150b4ca00ec 100755 (executable)
@@ -1,16 +1,9 @@
 ## @file\r
 #  Check a patch for various format issues\r
 #\r
-#  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
 #\r
-#  This program and the accompanying materials are licensed and made\r
-#  available under the terms and conditions of the BSD License which\r
-#  accompanies this distribution. The full text of the license may be\r
-#  found at http://opensource.org/licenses/bsd-license.php\r
-#\r
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"\r
-#  BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER\r
-#  EXPRESS OR IMPLIED.\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 from __future__ import print_function\r
@@ -74,11 +67,17 @@ class CommitMessageCheck:
             print(prefix, line)\r
             count += 1\r
 \r
+    # Find 'contributed-under:' at the start of a line ignoring case and\r
+    # requires ':' to be present.  Matches if there is white space before\r
+    # the tag or between the tag and the ':'.\r
+    contributed_under_re = \\r
+        re.compile(r'^\s*contributed-under\s*:', re.MULTILINE|re.IGNORECASE)\r
+\r
     def check_contributed_under(self):\r
-        cu_msg='Contributed-under: TianoCore Contribution Agreement 1.0'\r
-        if self.msg.find(cu_msg) < 0:\r
-            self.error('Missing Contributed-under! (Note: this must be ' +\r
-                       'added by the code contributor!)')\r
+        match = self.contributed_under_re.search(self.msg)\r
+        if match is not None:\r
+            self.error('Contributed-under! (Note: this must be ' +\r
+                       'removed by the code contributor!)')\r
 \r
     @staticmethod\r
     def make_signature_re(sig, re_input=False):\r
@@ -271,6 +270,7 @@ class GitDiffCheck:
             if line.startswith('@@ '):\r
                 self.state = PRE_PATCH\r
             elif len(line) >= 1 and line[0] not in ' -+' and \\r
+                 not line.startswith('\r\n') and  \\r
                  not line.startswith(r'\ No newline ') and not self.binary:\r
                 for line in self.lines[self.line_num + 1:]:\r
                     if line.startswith('diff --git'):\r
@@ -282,7 +282,7 @@ class GitDiffCheck:
         if self.state == START:\r
             if line.startswith('diff --git'):\r
                 self.state = PRE_PATCH\r
-                self.filename = line[13:].split(' ',1)[0]\r
+                self.filename = line[13:].split(' ', 1)[0]\r
                 self.is_newfile = False\r
                 self.force_crlf = not self.filename.endswith('.sh')\r
             elif len(line.rstrip()) != 0:\r
@@ -314,6 +314,8 @@ class GitDiffCheck:
                 pass\r
             elif line.startswith('+'):\r
                 self.check_added_line(line[1:])\r
+            elif line.startswith('\r\n'):\r
+                pass\r
             elif line.startswith(r'\ No newline '):\r
                 pass\r
             elif not line.startswith(' '):\r
@@ -329,6 +331,8 @@ class GitDiffCheck:
         'old mode ',\r
         'new mode ',\r
         'similarity index ',\r
+        'copy from ',\r
+        'copy to ',\r
         'rename ',\r
         )\r
 \r
@@ -525,6 +529,8 @@ class CheckGitCommits:
                 print('Checking git commit:', commit)\r
             patch = self.read_patch_from_git(commit)\r
             self.ok &= CheckOnePatch(commit, patch).ok\r
+        if not commits:\r
+            print("Couldn't find commit matching: '{}'".format(rev_spec))\r
 \r
     def read_commit_list_from_git(self, rev_spec, max_count):\r
         # Run git to get the commit patch\r
@@ -533,11 +539,11 @@ class CheckGitCommits:
             cmd.append('--max-count=' + str(max_count))\r
         cmd.append(rev_spec)\r
         out = self.run_git(*cmd)\r
-        return out.split()\r
+        return out.split() if out else []\r
 \r
     def read_patch_from_git(self, commit):\r
         # Run git to get the commit patch\r
-        return self.run_git('show', '--pretty=email', commit)\r
+        return self.run_git('show', '--pretty=email', '--no-textconv', commit)\r
 \r
     def run_git(self, *args):\r
         cmd = [ 'git' ]\r
@@ -545,7 +551,8 @@ class CheckGitCommits:
         p = subprocess.Popen(cmd,\r
                      stdout=subprocess.PIPE,\r
                      stderr=subprocess.STDOUT)\r
-        return p.communicate()[0].decode('utf-8', 'ignore')\r
+        Result = p.communicate()\r
+        return Result[0].decode('utf-8', 'ignore') if Result[0] and Result[0].find(b"fatal")!=0 else None\r
 \r
 class CheckOnePatchFile:\r
     """Performs a patch check for a single file.\r