[{"id":14343,"web_url":"https://patchwork.libcamera.org/comment/14343/","msgid":"<X+hj37vYZ8PsxoLX@wyvern>","date":"2020-12-27T10:37:19","subject":"Re: [libcamera-devel] [PATCH 5/8] utils: checkstyle.py: Add ability\n\tto filter files by status in a commit","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Laurent,\n\nThanks for your work.\n\nOn 2020-12-24 14:28:52 +0200, Laurent Pinchart wrote:\n> A commit can perform different operations on a file. Record the file\n> status (added, modified, renamed, deleted, ...) and add the ability to\n> filter files by status when listing the files touched by a commit.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  utils/checkstyle.py | 39 +++++++++++++++++++++++++++++----------\n>  1 file changed, 29 insertions(+), 10 deletions(-)\n> \n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index 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> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 F201DC0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 27 Dec 2020 10:37:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5A90661D64;\n\tSun, 27 Dec 2020 11:37:26 +0100 (CET)","from mail-lf1-x141.google.com (mail-lf1-x141.google.com\n\t[IPv6:2a00:1450:4864:20::141])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 634A4615AC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 27 Dec 2020 11:37:24 +0100 (CET)","by mail-lf1-x141.google.com with SMTP id h205so17985998lfd.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 27 Dec 2020 02:37:24 -0800 (PST)","from localhost ([185.224.57.161]) by smtp.gmail.com with ESMTPSA id\n\tc18sm4973954lfp.307.2020.12.27.02.37.22\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 27 Dec 2020 02:37:23 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"pgZmlfi0\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=xlWx1ZKRiuc7KTiLYVtS+YrIawLvO6+1OqgjKS1ATJk=;\n\tb=pgZmlfi06Yb7ldSRwc5MXAIwKfuZHLQXhLEPDg1hq4S7yYBcsrN5oGyulY9cK7HSeo\n\t38Y5xEZu8fBg+7ou4KdzMeeh9wPKp6uZZAhuis+fwjQ/6ElUOolmb4jddvoseJE7qgNY\n\tj9fKW4DfOT5B38e2UvbYqNdr2uZwxttGu2PkJ4Gq3AxdRIVuliO2BgRd36RndPB56aUm\n\tzNY0OKKNypm3UlGULL2mv6XINQjXoMztaDb+miEde2VRzQEEhIWaJBpxtDjp/qHW5/wt\n\tvZJNh9rifRK6C9tDmV+KqekaYq/s4/Sv+W9KG0cADSIie7G+J5CiNxzSyG/sLW0luLvO\n\t8cZw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=xlWx1ZKRiuc7KTiLYVtS+YrIawLvO6+1OqgjKS1ATJk=;\n\tb=kPNtNGFBqxdLxJC1mMcgSP2vst3SWzTshHgkDGAjWLV2VIN+vYRbey3y67C+C08enU\n\tNrk5XVYKB6Z4z4cdHFrC5U4sKeE+sh5NQoM9EMvc0M3oqldpUIFS6T7LMRsTN+TpV6gO\n\tL0+6wzOn583WV7m+dQ47guejcu3aWmoHEyNDNmkOqy3/LxEqLKFFr2GXkyXm62BymTn7\n\tpNMDBRSZyGtmaNQH2vJFdkmrADPdk3x8Ku7cUNg4mUtP/ii3KpHczKNlP6nA7LMxBcQ3\n\t7BqvN2setMZ8lrFUCvjqkd1FaaXMBieywrFYuJgdnMqHSVoLo54wFR5IhRwULHSEs8PX\n\tsF+g==","X-Gm-Message-State":"AOAM531ukadnPBTJLhMDExEkxccJwDDrUE57a+tgZQ//zS5Sq2Cspuhl\n\tlUvoisOR5XcpLm2qGPCMh57D9OXKn+axlw==","X-Google-Smtp-Source":"ABdhPJxABzjyVIqgqCq/SzOq1Fc9Fef6Xa2Br59NOhg8bDW+bD96g/HJzbPHbTxz1zU0QDokfndARg==","X-Received":"by 2002:ac2:57c7:: with SMTP id k7mr18085364lfo.20.1609065443811;\n\tSun, 27 Dec 2020 02:37:23 -0800 (PST)","Date":"Sun, 27 Dec 2020 11:37:19 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<X+hj37vYZ8PsxoLX@wyvern>","References":"<20201224122855.22200-1-laurent.pinchart@ideasonboard.com>\n\t<20201224122855.22200-6-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201224122855.22200-6-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 5/8] utils: checkstyle.py: Add ability\n\tto filter 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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]