From patchwork Tue Jul 25 13:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 18892 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 24679BDC71 for ; Tue, 25 Jul 2023 13:55:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 87A5B61E26; Tue, 25 Jul 2023 15:55:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1690293341; bh=Ah3aB3bgi78ML7AYPDDgI7r/hdE2jQg49/6/EaNgC60=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=erhwBIm6JTf/9CAmcmC7l/xtF3/hgCLQ23cUcyTL09elIpzw3RtZawuMXbcBHv3qT S0dDkqlzkKQkMI/PfjkoAnnJMNCg06J/P94z7NYOhJEW04jyTRhIYzFUZA+VEefYXz 5F22zORq4N794wcFPHX4/zJgJtSHUxd53rQ0/pNC6Txm6/DA+ZNkXXOxAVQULsTCnA A8n85mPYwWyIQaTsVsE5F+ivE2wmpfmj9PbdFZoqEK/oACy23IV7bG5kMRqertvVTg vD/MZ2z6uCS6S3/O7Sk+/CfaSqlQMIfg+0IL79B8Gtat3mUQNYa3gTppCdHfOGHzFK eJsQjqEKKpZmw== 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 2C26161E26 for ; Tue, 25 Jul 2023 15:55:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="T8MnLSp2"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AE4F54AD; Tue, 25 Jul 2023 15:54:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1690293281; bh=Ah3aB3bgi78ML7AYPDDgI7r/hdE2jQg49/6/EaNgC60=; h=From:To:Cc:Subject:Date:From; b=T8MnLSp2jDi7QCOLyAglY4eJdkHbbK1CUanJw2YN3e6VcGyyg/+jdaiduU0whjz38 MobkaCOpjP0itGfA2jirO7ogrJlL7SSdLAq2M3W7UnslN4tIQSXSqCZ9IbLpEMS0ki MVRoGBHb2Ztq/eab3tPwM4LYUKhXqQlPAOe9g3Gs= To: libcamera-devel@lists.libcamera.org Date: Tue, 25 Jul 2023 16:55:47 +0300 Message-Id: <20230725135547.12589-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] utils: checkstyle.py: Extract title and trailers with one command 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Amendment class calls `git show` twice, once to extract the commit title, and a second time to extract the trailers. This can be combined in a single command, which is more efficient. Do so. While at it, centralize initialization of self._trailers in the Commit.__init__() function. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- utils/checkstyle.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) base-commit: baaad1bf9e2acb3ab721945041ef46496951c04c diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 214509bc74d4..836ea80fe89b 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -206,10 +206,10 @@ class CommitFile: class Commit: def __init__(self, commit): self.commit = commit + self._trailers = [] self._parse() def _parse_trailers(self, lines): - self._trailers = [] for index in range(1, len(lines)): line = lines[index] if not line: @@ -257,9 +257,6 @@ class StagedChanges(Commit): def __init__(self): Commit.__init__(self, '') - # There are no trailers to parse on a Staged Change. - self._trailers = [] - def _parse(self): ret = subprocess.run(['git', 'diff', '--staged', '--name-status'], stdout=subprocess.PIPE).stdout.decode('utf-8') @@ -278,21 +275,21 @@ class Amendment(Commit): Commit.__init__(self, '') def _parse(self): - # Create a title using HEAD commit - ret = subprocess.run(['git', 'show', '--pretty=oneline', '--no-patch'], + # Create a title using HEAD commit and parse the trailers. + ret = subprocess.run(['git', 'show', '--format=%H %s%n%(trailers:only,unfold)', + '--no-patch'], stdout=subprocess.PIPE).stdout.decode('utf-8') - self._title = 'Amendment of ' + ret.strip() + lines = ret.splitlines() + + self._title = 'Amendment of ' + lines[0].strip() + + self._parse_trailers(lines) + # Extract the list of modified files ret = subprocess.run(['git', 'diff', '--staged', '--name-status', 'HEAD~'], stdout=subprocess.PIPE).stdout.decode('utf-8') self._files = [CommitFile(f) for f in ret.splitlines()] - # Parse trailers from the existing commit only. - ret = subprocess.run(['git', 'show', '--format=%n%(trailers:only,unfold)', - '--no-patch'], - stdout=subprocess.PIPE).stdout.decode('utf-8') - self._parse_trailers(ret.splitlines()) - def get_diff(self, top_level, filename): diff = subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--', '%s/%s' % (top_level, filename)],