From patchwork Sat Jan 18 20:00:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Dufresne X-Patchwork-Id: 2679 Return-Path: Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8B704607B2 for ; Sat, 18 Jan 2020 21:02:54 +0100 (CET) Received: from nicolas-tpx395.localdomain (unknown [IPv6:2002:c0de:c115:0:66fc:8b:2a38:8313]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: nicolas) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id D1B5E2925A2; Sat, 18 Jan 2020 20:02:52 +0000 (GMT) From: Nicolas Dufresne To: libcamera-devel@lists.libcamera.org Cc: Nicolas Dufresne , =?utf-8?q?Niklas_S?= =?utf-8?b?w7ZkZXJsdW5k?= , Laurent Pinchart Date: Sat, 18 Jan 2020 15:00:14 -0500 Message-Id: <20200118200015.16531-6-nicolas@ndufresne.ca> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200118200015.16531-1-nicolas@ndufresne.ca> References: <20200118200015.16531-1-nicolas@ndufresne.ca> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/6] checkstyle: Add support for checking style on amendments 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-List-Received-Date: Sat, 18 Jan 2020 20:02:54 -0000 From: Nicolas Dufresne This introduces a new argument "--amend" and a new special type of commit "Amendment". It will check the style of changes that are in the index combined with the changes of the last commit. So this is the changes that would be applied by "git commit --amend" hence the name of the argument. This is needed to implement pre-commit hook. Signed-off-by: Nicolas Dufresne Reviewed-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- utils/checkstyle.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index e7c3ae2..37f74c8 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -496,6 +496,26 @@ class StagedChanges(Commit): 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', 'HEAD'], + stdout=subprocess.PIPE).stdout.decode('utf-8') + title = 'Amendment of: ' + ret.splitlines()[0] + # 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) @@ -628,6 +648,8 @@ def main(argv): help='Code formatter. Default to clang-format if not specified.') parser.add_argument('--staged', '-s', action='store_true', help='Include the changes in the index. Defaults to False') + parser.add_argument('--amend', '-a', action='store_true', + help='Include changes in the index and the previous patch combined. Defaults to False') parser.add_argument('revision_range', type=str, default=None, nargs='?', help='Revision range (as defined by git rev-parse). Defaults to HEAD if not specified.') args = parser.parse_args(argv[1:]) @@ -666,6 +688,8 @@ def main(argv): commits = [] if args.staged: commits.append(StagedChanges()) + if args.amend: + commits.append(Amendment()) # If not --staged if len(commits) == 0: