]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Scripts/PatchCheck.py
IntelFrameworkModulePkg: Refine casting expression result to bigger size
[mirror_edk2.git] / BaseTools / Scripts / PatchCheck.py
index 340a9972b8382e00a42a229edb52efde7107913e..7c3008233c24f07d540e37326f48f79ae8050540 100755 (executable)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Check a patch for various format issues\r
 #\r
-#  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2015 - 2016, 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
@@ -16,7 +16,7 @@
 from __future__ import print_function\r
 \r
 VersionNumber = '0.1'\r
-__copyright__ = "Copyright (c) 2015, Intel Corporation  All rights reserved."\r
+__copyright__ = "Copyright (c) 2015 - 2016, Intel Corporation  All rights reserved."\r
 \r
 import email\r
 import argparse\r
@@ -197,7 +197,7 @@ class CommitMessageCheck:
             self.error('Empty commit message!')\r
             return\r
 \r
-        if count >= 1 and len(lines[0]) > 76:\r
+        if count >= 1 and len(lines[0]) >= 72:\r
             self.error('First line of commit message (subject line) ' +\r
                        'is too long.')\r
 \r
@@ -210,7 +210,7 @@ class CommitMessageCheck:
                        'empty.')\r
 \r
         for i in range(2, count):\r
-            if (len(lines[i]) > 76 and\r
+            if (len(lines[i]) >= 76 and\r
                 len(lines[i].split()) > 1 and\r
                 not lines[i].startswith('git-svn-id:')):\r
                 self.error('Line %d of commit message is too long.' % (i + 1))\r
@@ -285,6 +285,10 @@ class GitDiffCheck:
                 self.set_filename(line[6:].rstrip())\r
             if line.startswith('@@ '):\r
                 self.state = PATCH\r
+                self.binary = False\r
+            elif line.startswith('GIT binary patch'):\r
+                self.state = PATCH\r
+                self.binary = True\r
             else:\r
                 ok = False\r
                 for pfx in self.pre_patch_prefixes:\r
@@ -294,6 +298,8 @@ class GitDiffCheck:
                     self.format_error("didn't find diff hunk marker (@@)")\r
             self.line_num += 1\r
         elif self.state == PATCH:\r
+            if self.binary:\r
+                pass\r
             if line.startswith('-'):\r
                 pass\r
             elif line.startswith('+'):\r
@@ -334,6 +340,14 @@ class GitDiffCheck:
 \r
         self.error(*lines)\r
 \r
+    old_debug_re = \\r
+        re.compile(r'''\r
+                        DEBUG \s* \( \s* \( \s*\r
+                        (?: DEBUG_[A-Z_]+ \s* \| \s*)*\r
+                        EFI_D_ ([A-Z_]+)\r
+                   ''',\r
+                   re.VERBOSE)\r
+\r
     def check_added_line(self, line):\r
         eol = ''\r
         for an_eol in self.line_endings:\r
@@ -351,6 +365,12 @@ class GitDiffCheck:
         if len(stripped) < len(line):\r
             self.added_line_error('Trailing whitespace found', line)\r
 \r
+        mo = self.old_debug_re.search(line)\r
+        if mo is not None:\r
+            self.added_line_error('EFI_D_' + mo.group(1) + ' was used, '\r
+                                  'but DEBUG_' + mo.group(1) +\r
+                                  ' is now recommended', line)\r
+\r
     split_diff_re = re.compile(r'''\r
                                    (?P<cmd>\r
                                        ^ diff \s+ --git \s+ a/.+ \s+ b/.+ $\r
@@ -430,6 +450,14 @@ class CheckOnePatch:
                    ''',\r
                    re.IGNORECASE | re.VERBOSE | re.MULTILINE)\r
 \r
+    subject_prefix_re = \\r
+        re.compile(r'''^\r
+                       \s* (\[\r
+                        [^\[\]]* # Allow all non-brackets\r
+                       \])* \s*\r
+                   ''',\r
+                   re.VERBOSE)\r
+\r
     def find_patch_pieces(self):\r
         if sys.version_info < (3, 0):\r
             patch = self.patch.encode('ascii', 'ignore')\r
@@ -466,14 +494,7 @@ class CheckOnePatch:
 \r
         self.commit_subject = pmail['subject'].replace('\r\n', '')\r
         self.commit_subject = self.commit_subject.replace('\n', '')\r
-\r
-        pfx_start = self.commit_subject.find('[')\r
-        if pfx_start >= 0:\r
-            pfx_end = self.commit_subject.find(']')\r
-            if pfx_end > pfx_start:\r
-                self.commit_prefix = self.commit_subject[pfx_start + 1 : pfx_end]\r
-                self.commit_subject = self.commit_subject[pfx_end + 1 :].lstrip()\r
-\r
+        self.commit_subject = self.subject_prefix_re.sub('', self.commit_subject, 1)\r
 \r
 class CheckGitCommits:\r
     """Reads patches from git based on the specified git revision range.\r