From patchwork Thu Dec 24 12:28:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 10740 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 3FFBEC0F1A for ; Thu, 24 Dec 2020 12:29:14 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E7C9060526; 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="dyDxFH9S"; 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 58478615D5 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 ED680A1D 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=1608812949; bh=z4u4x2raluKiHJaKWTFtx/4Qil1hDuWMhc/94oYSOn0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dyDxFH9Sn/WkhlM2NEnKSA0W95pbQyOqhS+fUp2bk0KwrPq7XL4XsLQxhujbPaWkE 23oHvQd6ltcN9Jv1wtnLqg9nnsJevP66g5EeyeTUd1PzYpPdW2b+cnSCcur68155R6 EpMlv3e5DFFaY9lP1BkfOiGsfv+pKG7tNQUsrkok= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Thu, 24 Dec 2020 14:28:51 +0200 Message-Id: <20201224122855.22200-5-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 4/8] utils: checkstyle.py: Make title and files properties of 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" Make the API of the Commit class more explicit by exposing the title and files as properties instead of through a get_info() method. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund Reviewed-by: Paul Elder --- utils/checkstyle.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 4ba65e5a4ff1..77e635dc5154 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -197,15 +197,24 @@ def parse_diff(diff): class Commit: def __init__(self, commit): self.commit = commit + self.__parse() - def get_info(self): + def __parse(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:] + self.__files = files[1:] + self.__title = files[0] + + @property + def files(self): + return self.__files + + @property + def title(self): + return self.__title def get_diff(self, top_level, filename): return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit), @@ -221,10 +230,11 @@ class StagedChanges(Commit): def __init__(self): Commit.__init__(self, '') - def get_info(self): + def __parse(self): ret = subprocess.run(['git', 'diff', '--staged', '--name-only'], stdout=subprocess.PIPE).stdout.decode('utf-8') - return "Staged changes", ret.splitlines() + self.__title = "Staged changes" + self.__files = ret.splitlines() def get_diff(self, top_level, filename): return subprocess.run(['git', 'diff', '--staged', '--', @@ -236,15 +246,15 @@ class Amendment(StagedChanges): def __init__(self): StagedChanges.__init__(self) - def get_info(self): + def __parse(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() + self.__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() + self.__files = ret.splitlines() def get_diff(self, top_level, filename): return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--', @@ -686,18 +696,16 @@ def check_file(top_level, commit, filename): def check_style(top_level, commit): - title, files = commit.get_info() - - separator = '-' * len(title) + separator = '-' * len(commit.title) print(separator) - print(title) + print(commit.title) print(separator) # Filter out files we have no checker for. patterns = set() patterns.update(StyleChecker.all_patterns()) patterns.update(Formatter.all_patterns()) - files = [f for f in files if len([p for p in patterns if fnmatch.fnmatch(os.path.basename(f), p)])] + files = [f for f in commit.files if len([p for p in patterns if fnmatch.fnmatch(os.path.basename(f), p)])] if len(files) == 0: print("Commit doesn't touch source files, skipping") return 0