From patchwork Fri Oct 7 20:17:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Conole X-Patchwork-Id: 679723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3srLSS5Qd3z9sBR for ; Sat, 8 Oct 2016 07:18:32 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id AABDE10A1A; Fri, 7 Oct 2016 13:18:07 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 2F6B6109E9 for ; Fri, 7 Oct 2016 13:18:04 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 8708D1621DF for ; Fri, 7 Oct 2016 14:18:03 -0600 (MDT) X-ASG-Debug-ID: 1475871482-0b323747b755b00001-byXFYA Received: from mx3-pf1.cudamail.com ([192.168.14.2]) by bar6.cudamail.com with ESMTP id RI4Vn9bJBForqYEc (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 07 Oct 2016 14:18:02 -0600 (MDT) X-Barracuda-Envelope-From: aconole@redhat.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.2 Received: from unknown (HELO mx1.redhat.com) (209.132.183.28) by mx3-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 7 Oct 2016 20:18:02 -0000 Received-SPF: pass (mx3-pf1.cudamail.com: SPF record at _spf1.redhat.com designates 209.132.183.28 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.132.183.28 X-Barracuda-RBL-IP: 209.132.183.28 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E64251173A for ; Fri, 7 Oct 2016 20:18:01 +0000 (UTC) Received: from dhcp-25-97.bos.redhat.com (dhcp-25-172.bos.redhat.com [10.18.25.172]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u97KHweb011836 for ; Fri, 7 Oct 2016 16:18:01 -0400 X-CudaMail-Envelope-Sender: aconole@redhat.com From: Aaron Conole To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V1-1006039813 X-CudaMail-DTE: 100716 X-CudaMail-Originating-IP: 209.132.183.28 Date: Fri, 7 Oct 2016 16:17:57 -0400 X-ASG-Orig-Subj: [##CM-V1-1006039813##][PATCH 6/6] checkpatch: Print file line numbers Message-Id: <1475871477-11608-7-git-send-email-aconole@redhat.com> In-Reply-To: <1475871477-11608-1-git-send-email-aconole@redhat.com> References: <1475871477-11608-1-git-send-email-aconole@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Oct 2016 20:18:01 +0000 (UTC) X-Barracuda-Connect: UNKNOWN[192.168.14.2] X-Barracuda-Start-Time: 1475871482 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [PATCH 6/6] checkpatch: Print file line numbers X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" The line numbers being printed were the line numbers for the patchfile. This is sometimes okay to fix simple things (trailing or leading whitespace, missing signoffs, etc). But more complicated fixes, or those fixes which require a bit more care, aren't helped by this. So, we use the implied file line number. This can be useful with future work to 'mock' apply and build a real contextual scanner for checking multi-line changes. Signed-off-by: Aaron Conole --- utilities/checkpatch.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index c4361f0..26ecc9e 100755 --- a/utilities/checkpatch.py +++ b/utilities/checkpatch.py @@ -52,6 +52,7 @@ def print_warning(message, lineno=None): __regex_added_line = re.compile(r'^\+{1,2}[^\+][\w\W]*') +__regex_subtracted_line = re.compile(r'^\-{1,2}[^\-][\w\W]*') __regex_leading_with_whitespace_at_all = re.compile(r'^\s+') __regex_leading_with_spaces = re.compile(r'^ +[\S]+') __regex_trailing_whitespace = re.compile(r'[^\S]+$') @@ -77,6 +78,10 @@ line_length_blacklist = ['.am', '.at', 'etc', '.in', '.m4', '.mk', '.patch', '.py'] +def is_subtracted_line(line): + """Returns TRUE if the line in question has been removed.""" + return __regex_subtracted_line.search(line) is not None + def is_added_line(line): """Returns TRUE if the line in question is an added line. """ @@ -148,6 +153,8 @@ def ovs_checkpatch_parse(text): previous_file = '' scissors = re.compile(r'^[\w]*---[\w]*') hunks = re.compile('^(---|\+\+\+) (\S+)') + hunk_differences = re.compile( + r'^@@ ([1-9-+]+),([1-9-+]+) ([1-9-+]+),([1-9-+]+) @@') is_signature = re.compile(r'((\s*Signed-off-by: )(.*))$', re.I | re.M | re.S) is_co_author = re.compile(r'(\s*(Co-authored-by: )(.*))$', @@ -196,6 +203,14 @@ def ovs_checkpatch_parse(text): current_file = newfile.group(2) print_file_name = current_file continue + reset_line_number = hunk_differences.match(line) + if reset_line_number: + lineno = int(reset_line_number.group(3)) + if lineno < 0: + lineno = -1 * lineno + lineno -= 1 + if is_subtracted_line(line): + lineno -= 1 if not is_added_line(line): continue # Skip files which have /datapath in them, since they are