From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D0E1621967BE8 for ; Thu, 8 Jun 2017 00:48:21 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jun 2017 00:49:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,313,1493708400"; d="scan'208";a="111854290" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.13]) by fmsmga005.fm.intel.com with ESMTP; 08 Jun 2017 00:49:29 -0700 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Liming Gao , Jordan Justen Date: Thu, 8 Jun 2017 15:49:24 +0800 Message-Id: <20170608074924.12900-3-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20170608074924.12900-1-hao.a.wu@intel.com> References: <20170608074924.12900-1-hao.a.wu@intel.com> Subject: [PATCH 2/2] BaseTools/PatchCheck.py: Add warning info for new binary files X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Jun 2017 07:48:22 -0000 The commit adds the detection of adding new binary files in a patch file or in a commit. The following warning messages will be appended at the end of the script output: WARNING - The following binary files will be added into the repository: ... Cc: Liming Gao Cc: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- BaseTools/Scripts/PatchCheck.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py index 4bc697b1af..7bc5736dbf 100755 --- a/BaseTools/Scripts/PatchCheck.py +++ b/BaseTools/Scripts/PatchCheck.py @@ -243,6 +243,7 @@ class GitDiffCheck: self.count = len(self.lines) self.line_num = 0 self.state = START + self.new_bin = [] while self.line_num < self.count and self.format_ok: line_num = self.line_num self.run() @@ -254,6 +255,11 @@ class GitDiffCheck: return if self.ok: print('The code passed all checks.') + if self.new_bin: + print('\nWARNING - The following binary files will be added ' + + 'into the repository:') + for binary in self.new_bin: + print(' ' + binary) def run(self): line = self.lines[self.line_num] @@ -276,21 +282,25 @@ class GitDiffCheck: if self.state == START: if line.startswith('diff --git'): self.state = PRE_PATCH - self.set_filename(None) + self.filename = line[13:].split(' ',1)[0] + self.is_newfile = False + self.force_crlf = not self.filename.endswith('.sh') elif len(line.rstrip()) != 0: self.format_error("didn't find diff command") self.line_num += 1 elif self.state == PRE_PATCH: - if line.startswith('+++ b/'): - self.set_filename(line[6:].rstrip()) if line.startswith('@@ '): self.state = PATCH self.binary = False - elif line.startswith('GIT binary patch'): + elif line.startswith('GIT binary patch') or \ + line.startswith('Binary files'): self.state = PATCH self.binary = True + if self.is_newfile: + self.new_bin.append(self.filename) else: ok = False + self.is_newfile = self.newfile_prefix_re.match(line) for pfx in self.pre_patch_prefixes: if line.startswith(pfx): ok = True @@ -320,22 +330,20 @@ class GitDiffCheck: 'new mode ', 'similarity index ', 'rename ', - 'Binary files ', ) line_endings = ('\r\n', '\n\r', '\n', '\r') - def set_filename(self, filename): - self.hunk_filename = filename - if filename: - self.force_crlf = not filename.endswith('.sh') - else: - self.force_crlf = True + newfile_prefix_re = \ + re.compile(r'''^ + index\ 0+\.\. + ''', + re.VERBOSE) def added_line_error(self, msg, line): lines = [ msg ] - if self.hunk_filename is not None: - lines.append('File: ' + self.hunk_filename) + if self.filename is not None: + lines.append('File: ' + self.filename) lines.append('Line: ' + line) self.error(*lines) -- 2.12.0.windows.1