From patchwork Thu Dec 24 12:28:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10739 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 9D090C0F1A for ; Thu, 24 Dec 2020 12:29:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C6F8615AF; Thu, 24 Dec 2020 13:29:13 +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="I4h+YFIf"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0978F60528 for ; Thu, 24 Dec 2020 13:29:09 +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 9ED28DFC for ; Thu, 24 Dec 2020 13:29:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1608812948; bh=6yCYwRzf5QvfKinGmTRNPvWOY+FQEs89TQ6h/scAPW8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=I4h+YFIfEuBm4HCfMUVTqy6Qhlbe3L0juQEZ01HhKtaWBx71FrVokPToMtNQGh44D +eBHQZjtCOkFfoCjDE16+EZs+O4TMk7BXscTAzMWZd67TR2JSoW/6cW6lHdypM/DQe 3hd56yZHOSZSDlCwqT32F+vtVKMHyyAnMmTWF8zw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Dec 2020 14:28:50 +0200 Message-Id: <20201224122855.22200-4-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 3/8] utils: checkstyle.py: Move commit handling to a separate section 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 prepare for checkers that operate directly on commits, move the related classes to a separate section. No functional change is included. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Paul Elder --- utils/checkstyle.py | 120 +++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 76267d5ea764..4ba65e5a4ff1 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -190,6 +190,68 @@ def parse_diff(diff): return hunks +# ------------------------------------------------------------------------------ +# Commit, Staged Changes & Amendments +# + +class Commit: + def __init__(self, commit): + self.commit = commit + + def get_info(self): + # Get the commit title and list of files. + ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only', + self.commit], + stdout=subprocess.PIPE).stdout.decode('utf-8') + files = ret.splitlines() + # Returning title and files list as a tuple + return files[0], files[1:] + + def get_diff(self, top_level, filename): + return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit), + '--', '%s/%s' % (top_level, filename)], + stdout=subprocess.PIPE).stdout.decode('utf-8') + + def get_file(self, filename): + return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)], + stdout=subprocess.PIPE).stdout.decode('utf-8') + + +class StagedChanges(Commit): + def __init__(self): + Commit.__init__(self, '') + + def get_info(self): + ret = subprocess.run(['git', 'diff', '--staged', '--name-only'], + stdout=subprocess.PIPE).stdout.decode('utf-8') + return "Staged changes", ret.splitlines() + + def get_diff(self, top_level, filename): + return subprocess.run(['git', 'diff', '--staged', '--', + '%s/%s' % (top_level, filename)], + stdout=subprocess.PIPE).stdout.decode('utf-8') + + +class Amendment(StagedChanges): + def __init__(self): + StagedChanges.__init__(self) + + def get_info(self): + # Create a title using HEAD commit + ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'], + stdout=subprocess.PIPE).stdout.decode('utf-8') + title = 'Amendment of ' + ret.strip() + # Extract the list of modified files + ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'], + stdout=subprocess.PIPE).stdout.decode('utf-8') + return title, ret.splitlines() + + def get_diff(self, top_level, filename): + return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--', + '%s/%s' % (top_level, filename)], + stdout=subprocess.PIPE).stdout.decode('utf-8') + + # ------------------------------------------------------------------------------ # Helpers # @@ -564,64 +626,6 @@ class StripTrailingSpaceFormatter(Formatter): # Style checking # -class Commit: - def __init__(self, commit): - self.commit = commit - - def get_info(self): - # Get the commit title and list of files. - ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only', - self.commit], - stdout=subprocess.PIPE).stdout.decode('utf-8') - files = ret.splitlines() - # Returning title and files list as a tuple - return files[0], files[1:] - - def get_diff(self, top_level, filename): - return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit), - '--', '%s/%s' % (top_level, filename)], - stdout=subprocess.PIPE).stdout.decode('utf-8') - - def get_file(self, filename): - return subprocess.run(['git', 'show', '%s:%s' % (self.commit, filename)], - stdout=subprocess.PIPE).stdout.decode('utf-8') - - -class StagedChanges(Commit): - def __init__(self): - Commit.__init__(self, '') - - def get_info(self): - ret = subprocess.run(['git', 'diff', '--staged', '--name-only'], - stdout=subprocess.PIPE).stdout.decode('utf-8') - return "Staged changes", ret.splitlines() - - def get_diff(self, top_level, filename): - return subprocess.run(['git', 'diff', '--staged', '--', - '%s/%s' % (top_level, filename)], - stdout=subprocess.PIPE).stdout.decode('utf-8') - - -class Amendment(StagedChanges): - def __init__(self): - StagedChanges.__init__(self) - - def get_info(self): - # Create a title using HEAD commit - ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'], - stdout=subprocess.PIPE).stdout.decode('utf-8') - title = 'Amendment of ' + ret.strip() - # Extract the list of modified files - ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'], - stdout=subprocess.PIPE).stdout.decode('utf-8') - return title, ret.splitlines() - - def get_diff(self, top_level, filename): - return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--', - '%s/%s' % (top_level, filename)], - stdout=subprocess.PIPE).stdout.decode('utf-8') - - def check_file(top_level, commit, filename): # Extract the line numbers touched by the commit. diff = commit.get_diff(top_level, filename)