{"id":2672,"url":"https://patchwork.libcamera.org/api/1.1/patches/2672/?format=json","web_url":"https://patchwork.libcamera.org/patch/2672/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200118035448.230530-6-nicolas@ndufresne.ca>","date":"2020-01-18T03:54:47","name":"[libcamera-devel,v3,5/6] checkstyle: Add support for checking style on amendments","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"3728f2cc0c995259eaa483f4044c0082be6de22c","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/1.1/people/30/?format=json","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2672/mbox/","series":[{"id":635,"url":"https://patchwork.libcamera.org/api/1.1/series/635/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=635","date":"2020-01-18T03:54:42","name":"Add the ability to do pre-commit style check","version":3,"mbox":"https://patchwork.libcamera.org/series/635/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2672/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2672/checks/","tags":{},"headers":{"Return-Path":"<nicolas@ndufresne.ca>","Received":["from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4ACC2607A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Jan 2020 05:00:04 +0100 (CET)","from nicolas-tpx395.localdomain (unknown\n\t[IPv6:2002:c0de:c115:0:66fc:8b:2a38:8313])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits))\n\t(No client certificate requested) (Authenticated sender: nicolas)\n\tby bhuna.collabora.co.uk (Postfix) with ESMTPSA id B113A2932F6;\n\tSat, 18 Jan 2020 04:00:02 +0000 (GMT)"],"From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"libcamera-devel@lists.libcamera.org","Cc":"Nicolas Dufresne <nicolas.dufresne@collabora.com>, =?utf-8?q?Niklas_S?=\n\t=?utf-8?b?w7ZkZXJsdW5k?= <niklas.soderlund@ragnatech.se>","Date":"Fri, 17 Jan 2020 22:54:47 -0500","Message-Id":"<20200118035448.230530-6-nicolas@ndufresne.ca>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200118035448.230530-1-nicolas@ndufresne.ca>","References":"<20200118035448.230530-1-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 5/6] checkstyle: Add support for\n\tchecking style on amendments","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sat, 18 Jan 2020 04:00:04 -0000"},"content":"From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nThis introduce a new argument \"--amend\" and a new special type of\ncommit \"Amendment\". It will check the style of changes that are in\nthe index combined with the changes of the last commit. So this is\nthe changes that would be applied by \"git commit --amend\" hence the\nname of the argument.\n\nThis is needed to implement pre-commit hook.\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n utils/checkstyle.py | 26 +++++++++++++++++++++++++-\n 1 file changed, 25 insertions(+), 1 deletion(-)","diff":"diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex 1cd5476..8591e4e 100755\n--- a/utils/checkstyle.py\n+++ b/utils/checkstyle.py\n@@ -500,6 +500,26 @@ class StagedChanges(Commit):\n                               stdout=subprocess.PIPE).stdout.decode('utf-8')\n \n \n+class Amendment(StagedChanges):\n+    def __init__(self):\n+        Commit.__init__(self, None)\n+\n+    def get_info(self, top_level):\n+        # Create a title using HEAD commit\n+        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only', 'HEAD'],\n+                             stdout=subprocess.PIPE).stdout.decode('utf-8')\n+        title = 'Amendment of: ' + ret.splitlines()[0]\n+        # Extract the list of modifier files\n+        ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'],\n+                             stdout=subprocess.PIPE).stdout.decode('utf-8')\n+        return title, ret.splitlines()\n+\n+    def get_diff(self, top_level, filename):\n+        return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',\n+                               '%s/%s' % (top_level, filename)],\n+                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n+\n+\n def check_file(top_level, commit, filename):\n     # Extract the line numbers touched by the commit.\n     diff = commit.get_diff(top_level, filename)\n@@ -632,6 +652,8 @@ def main(argv):\n                         help='Code formatter. Default to clang-format if not specified.')\n     parser.add_argument('--staged', '-s', action='store_true',\n                         help='Include the changes in the index. Defaults to False')\n+    parser.add_argument('--amend', '-a', action='store_true',\n+                        help='Include changes in the index and the previous patch combined. Defaults to False')\n     parser.add_argument('revision_range', type=str, default=None, nargs='?',\n                         help='Revision range (as defined by git rev-parse). Defaults to HEAD if not specified.')\n     args = parser.parse_args(argv[1:])\n@@ -670,8 +692,10 @@ def main(argv):\n     revlist = []\n     if args.staged:\n         revlist.append(StagedChanges())\n+    if args.amend:\n+        revlist.append(Amendment())\n \n-    # If not --staged\n+    # If none of --staged or --amend was passed\n     if len(revlist) == 0:\n         # And no revisions was passed, then default to HEAD\n         if not args.revision_range:\n","prefixes":["libcamera-devel","v3","5/6"]}