{"id":2663,"url":"https://patchwork.libcamera.org/api/1.1/patches/2663/?format=json","web_url":"https://patchwork.libcamera.org/patch/2663/","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":"<20200117191733.198897-4-nicolas@ndufresne.ca>","date":"2020-01-17T19:17:30","name":"[libcamera-devel,v2,3/6] checkstyle: Introduce a Commit class","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"20949a55b9d4309cc3511b00845f935cc48898d5","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/2663/mbox/","series":[{"id":634,"url":"https://patchwork.libcamera.org/api/1.1/series/634/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=634","date":"2020-01-17T19:17:27","name":"Add the ability to do pre-commit style check","version":2,"mbox":"https://patchwork.libcamera.org/series/634/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2663/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2663/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 8B9FA60787\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jan 2020 20:17:58 +0100 (CET)","from nicolas-tpx395.localdomain (unknown [IPv6:2610:98:8005::127])\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 15DC52949D4;\n\tFri, 17 Jan 2020 19:17:58 +0000 (GMT)"],"From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"libcamera-devel@lists.libcamera.org","Cc":"Nicolas Dufresne <nicolas.dufresne@collabora.com>","Date":"Fri, 17 Jan 2020 14:17:30 -0500","Message-Id":"<20200117191733.198897-4-nicolas@ndufresne.ca>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200117191733.198897-1-nicolas@ndufresne.ca>","References":"<20200117191733.198897-1-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 3/6] checkstyle: Introduce a Commit\n\tclass","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":"Fri, 17 Jan 2020 19:17:58 -0000"},"content":"From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nThis introduce a Commit class used in the final revlist list. All the\ngit command are moved into that class. This class will be used to\nintroduce new type of commit (index and amendment) needed to implement\npre-commit hook support.\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n---\n utils/checkstyle.py | 43 +++++++++++++++++++++++++++++--------------\n 1 file changed, 29 insertions(+), 14 deletions(-)","diff":"diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex e7375b3..fb865c8 100644\n--- a/utils/checkstyle.py\n+++ b/utils/checkstyle.py\n@@ -458,12 +458,34 @@ class StripTrailingSpaceFormatter(Formatter):\n # Style checking\n #\n \n+class Commit:\n+    commit = None\n+\n+    def __init__(self, commit):\n+        self.commit = commit\n+\n+    def get_info(self, top_level):\n+        # Get the commit title and list of files.\n+        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',\n+                              self.commit],\n+                             stdout=subprocess.PIPE).stdout.decode('utf-8')\n+        files = ret.splitlines()\n+        return files[0], files[1:]\n+\n+    def get_diff(self, top_level, filename):\n+        return subprocess.run(['git', 'diff', '%s~..%s' % (self.commit, self.commit),\n+                               '--', '%s/%s' % (top_level, filename)],\n+                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n+\n+    def get_file(self, filename):\n+        return subprocess.run(['git', 'show', '%s:%s' % (self.commit, 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 = subprocess.run(['git', 'diff', '%s~..%s' % (commit, commit), '--',\n-                           '%s/%s' % (top_level, filename)],\n-                          stdout=subprocess.PIPE).stdout\n-    diff = diff.decode('utf-8').splitlines(True)\n+    diff = commit.get_diff(top_level, filename)\n+    diff = diff.splitlines(True)\n     commit_diff = parse_diff(diff)\n \n     lines = []\n@@ -476,9 +498,7 @@ def check_file(top_level, commit, filename):\n \n     # Format the file after the commit with all formatters and compute the diff\n     # between the unformatted and formatted contents.\n-    after = subprocess.run(['git', 'show', '%s:%s' % (commit, filename)],\n-                           stdout=subprocess.PIPE).stdout\n-    after = after.decode('utf-8')\n+    after = commit.get_file(filename)\n \n     formatted = after\n     for formatter in Formatter.formatters(filename):\n@@ -522,12 +542,7 @@ def check_file(top_level, commit, filename):\n \n \n def check_style(top_level, commit):\n-    # Get the commit title and list of files.\n-    ret = subprocess.run(['git', 'show', '--pretty=oneline','--name-only', commit],\n-                         stdout=subprocess.PIPE)\n-    files = ret.stdout.decode('utf-8').splitlines()\n-    title = files[0]\n-    files = files[1:]\n+    title, files = commit.get_info(top_level)\n \n     separator = '-' * len(title)\n     print(separator)\n@@ -576,7 +591,7 @@ def extract_revlist(revs):\n         revlist = ret.stdout.decode('utf-8').splitlines()\n         revlist.reverse()\n \n-    return revlist\n+    return [Commit(x) for x in revlist]\n \n \n def git_top_level():\n","prefixes":["libcamera-devel","v2","3/6"]}