{"id":10741,"url":"https://patchwork.libcamera.org/api/patches/10741/?format=json","web_url":"https://patchwork.libcamera.org/patch/10741/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20201224122855.22200-6-laurent.pinchart@ideasonboard.com>","date":"2020-12-24T12:28:52","name":"[libcamera-devel,5/8] utils: checkstyle.py: Add ability to filter files by status in a commit","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"29ce10e39eda21f9fcb572b550a8a8b7f9134e15","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/10741/mbox/","series":[{"id":1550,"url":"https://patchwork.libcamera.org/api/series/1550/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1550","date":"2020-12-24T12:28:47","name":"checkstyle.py: Ensure meson.build is updated when adding header","version":1,"mbox":"https://patchwork.libcamera.org/series/1550/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10741/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10741/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B6FC9C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 24 Dec 2020 12:29:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 740E361FF6;\n\tThu, 24 Dec 2020 13:29:14 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E56F61FF3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Dec 2020 13:29:09 +0100 (CET)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 485B1DFC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 24 Dec 2020 13:29:09 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"V3SzuRIV\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1608812949;\n\tbh=uKANu3/kKLScJOKlHXIhE61UJF0R/3MmN5xzJ/AGvNE=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=V3SzuRIVHIgOZbx6iHyyYoJ/q0Ps8/1QSCmF3Zvk+juNKk7/QQRASYnSlaC2SvC5S\n\tF6G/omlRrCDTbd6EptmGfHcVa3XXOvgPlEHiOoba1hVe2MHMDnHXot0vkKVFL88Y2M\n\tAVtBjEXq+cPAyDngXciOC21sJHuuREJch9Vo2Wn4=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu, 24 Dec 2020 14:28:52 +0200","Message-Id":"<20201224122855.22200-6-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 5/8] utils: checkstyle.py: Add ability to\n\tfilter files by status in a commit","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"A commit can perform different operations on a file. Record the file\nstatus (added, modified, renamed, deleted, ...) and add the ability to\nfilter files by status when listing the files touched by a commit.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n utils/checkstyle.py | 39 +++++++++++++++++++++++++++++----------\n 1 file changed, 29 insertions(+), 10 deletions(-)","diff":"diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex 77e635dc5154..07e896d9819f 100755\n--- a/utils/checkstyle.py\n+++ b/utils/checkstyle.py\n@@ -194,6 +194,26 @@ def parse_diff(diff):\n # Commit, Staged Changes & Amendments\n #\n \n+class CommitFile:\n+    def __init__(self, name):\n+        info = name.split()\n+        self.__status = info[0][0]\n+\n+        # For renamed files, store the new name\n+        if self.__status == 'R':\n+            self.__filename = info[2]\n+        else:\n+            self.__filename = info[1]\n+\n+    @property\n+    def filename(self):\n+        return self.__filename\n+\n+    @property\n+    def status(self):\n+        return self.__status\n+\n+\n class Commit:\n     def __init__(self, commit):\n         self.commit = commit\n@@ -201,16 +221,15 @@ class Commit:\n \n     def __parse(self):\n         # Get the commit title and list of files.\n-        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-only',\n+        ret = subprocess.run(['git', 'show', '--pretty=oneline', '--name-status',\n                               self.commit],\n                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n         files = ret.splitlines()\n-        self.__files = files[1:]\n+        self.__files = [CommitFile(f) for f in files[1:]]\n         self.__title = files[0]\n \n-    @property\n-    def files(self):\n-        return self.__files\n+    def files(self, filter='AM'):\n+        return [f.filename for f in self.__files if f.status in filter]\n \n     @property\n     def title(self):\n@@ -231,10 +250,10 @@ class StagedChanges(Commit):\n         Commit.__init__(self, '')\n \n     def __parse(self):\n-        ret = subprocess.run(['git', 'diff', '--staged', '--name-only'],\n+        ret = subprocess.run(['git', 'diff', '--staged', '--name-status'],\n                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n         self.__title = \"Staged changes\"\n-        self.__files = ret.splitlines()\n+        self.__files = [CommitFile(f) for f in ret.splitlines()]\n \n     def get_diff(self, top_level, filename):\n         return subprocess.run(['git', 'diff', '--staged', '--',\n@@ -252,9 +271,9 @@ class Amendment(StagedChanges):\n                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n         self.__title = 'Amendment of ' + ret.strip()\n         # Extract the list of modified files\n-        ret = subprocess.run(['git', 'diff', '--staged', '--name-only', 'HEAD~'],\n+        ret = subprocess.run(['git', 'diff', '--staged', '--name-status', 'HEAD~'],\n                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n-        self.__files = ret.splitlines()\n+        self.__files = [CommitFile(f) for f in ret.splitlines()]\n \n     def get_diff(self, top_level, filename):\n         return subprocess.run(['git', 'diff', '--staged', 'HEAD~', '--',\n@@ -705,7 +724,7 @@ def check_style(top_level, commit):\n     patterns = set()\n     patterns.update(StyleChecker.all_patterns())\n     patterns.update(Formatter.all_patterns())\n-    files = [f for f in commit.files if len([p for p in patterns if fnmatch.fnmatch(os.path.basename(f), p)])]\n+    files = [f for f in commit.files() if len([p for p in patterns if fnmatch.fnmatch(os.path.basename(f), p)])]\n     if len(files) == 0:\n         print(\"Commit doesn't touch source files, skipping\")\n         return 0\n","prefixes":["libcamera-devel","5/8"]}