From patchwork Thu Dec 24 12:28:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10742 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3857AC0F1A for ; Thu, 24 Dec 2020 12:29:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E594561FF3; Thu, 24 Dec 2020 13:29:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wK0U1oyW"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0A5EA615B0 for ; Thu, 24 Dec 2020 13:29:10 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 978B1A1D for ; Thu, 24 Dec 2020 13:29:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1608812949; bh=842OaJz8aXP5QHYae35b2PfuGuUyo05f13sH0nuiqjI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wK0U1oyW8/AUsY2492T8+HP7mu3hzY2iSxu89UqfzazHvjgaPY2FiNYuMa6HllTB1 EK1XoHP2nYRbt2m9K5BCLadtKomw6gK4sCBiTGD2jXLxjxBinc0lhsnkCakuZZ9kuy 4rLOfvKkLckPbJX8s+viNXuYJVIaxGy0IeTr2OEA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Dec 2020 14:28:53 +0200 Message-Id: <20201224122855.22200-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201224122855.22200-1-laurent.pinchart@ideasonboard.com> References: <20201224122855.22200-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 6/8] utils: checkstyle.py: Move diff parsing to Commit class X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To avoid duplicating diff parsing in commit checkers, move it to the Commit class. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- utils/checkstyle.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 07e896d9819f..9c2a1837aa11 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -236,9 +236,10 @@ class Commit: return self.__title def get_diff(self, top_level, filename): - return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit), + diff = subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit), '--', '%s/%s' % (top_level, filename)], stdout=subprocess.PIPE).stdout.decode('utf-8') + return parse_diff(diff.splitlines(True)) def get_file(self, filename): return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)], @@ -256,9 +257,10 @@ class StagedChanges(Commit): self.__files = [CommitFile(f) for f in ret.splitlines()] def get_diff(self, top_level, filename): - return subprocess.run(['git', 'diff', '--staged', '--', + diff = subprocess.run(['git', 'diff', '--staged', '--', '%s/%s' % (top_level, filename)], stdout=subprocess.PIPE).stdout.decode('utf-8') + return parse_diff(diff.splitlines(True)) class Amendment(StagedChanges): @@ -276,9 +278,10 @@ class Amendment(StagedChanges): self.__files = [CommitFile(f) for f in ret.splitlines()] def get_diff(self, top_level, filename): - return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--', + diff = subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--', '%s/%s' % (top_level, filename)], stdout=subprocess.PIPE).stdout.decode('utf-8') + return parse_diff(diff.splitlines(True)) # ------------------------------------------------------------------------------ @@ -657,9 +660,7 @@ class StripTrailingSpaceFormatter(Formatter): def check_file(top_level, commit, filename): # Extract the line numbers touched by the commit. - diff = commit.get_diff(top_level, filename) - diff = diff.splitlines(True) - commit_diff = parse_diff(diff) + commit_diff = commit.get_diff(top_level, filename) lines = [] for hunk in commit_diff: