[{"id":3508,"web_url":"https://patchwork.libcamera.org/comment/3508/","msgid":"<20200118180220.GD5095@pendragon.ideasonboard.com>","date":"2020-01-18T18:02:20","subject":"Re: [libcamera-devel] [PATCH v3 5/6] checkstyle: Add support for\n\tchecking style on amendments","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Nicolas,\n\nThank you for the patch.\n\nOn Fri, Jan 17, 2020 at 10:54:47PM -0500, Nicolas Dufresne wrote:\n> From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> \n> This introduce a new argument \"--amend\" and a new special type of\n\ns/introduce/introduces/\n\n> commit \"Amendment\". It will check the style of changes that are in\n> the index combined with the changes of the last commit. So this is\n> the changes that would be applied by \"git commit --amend\" hence the\n> name of the argument.\n> \n> This is needed to implement pre-commit hook.\n> \n> Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  utils/checkstyle.py | 26 +++++++++++++++++++++++++-\n>  1 file changed, 25 insertions(+), 1 deletion(-)\n> \n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index 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\nYou should call the constructor of StagedChanges, not Commit.\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\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:","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A35E960455\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Jan 2020 19:02:35 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0CF9697A;\n\tSat, 18 Jan 2020 19:02:34 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1579370555;\n\tbh=N9QW2tfWpnYXnEGUdO3gROowMIwIT5L9i05KJyayi5k=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=kPtOOrutk4rHLufMEb/xehyEWwjtlZ0j4ELWmXhLmtsII1J043WMjCoDXKt7p+kxB\n\ts/TPg2E6pF8lsBputcPNleUvqtYSDCzbqbNIjRbC/uhy3aaf+vfwuF4ZLWXy2N7KuN\n\t3FMWJDM6TMFm9/Umk/VITxdxQCMz3jx0mTG9mkJA=","Date":"Sat, 18 Jan 2020 20:02:20 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Cc":"libcamera-devel@lists.libcamera.org,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","Message-ID":"<20200118180220.GD5095@pendragon.ideasonboard.com>","References":"<20200118035448.230530-1-nicolas@ndufresne.ca>\n\t<20200118035448.230530-6-nicolas@ndufresne.ca>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200118035448.230530-6-nicolas@ndufresne.ca>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [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 18:02:35 -0000"}},{"id":3512,"web_url":"https://patchwork.libcamera.org/comment/3512/","msgid":"<20200118183326.GH5095@pendragon.ideasonboard.com>","date":"2020-01-18T18:33:26","subject":"Re: [libcamera-devel] [PATCH v3 5/6] checkstyle: Add support for\n\tchecking style on amendments","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Sat, Jan 18, 2020 at 08:02:20PM +0200, Laurent Pinchart wrote:\n> On Fri, Jan 17, 2020 at 10:54:47PM -0500, Nicolas Dufresne wrote:\n> > From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> > \n> > This introduce a new argument \"--amend\" and a new special type of\n> \n> s/introduce/introduces/\n> \n> > commit \"Amendment\". It will check the style of changes that are in\n> > the index combined with the changes of the last commit. So this is\n> > the changes that would be applied by \"git commit --amend\" hence the\n> > name of the argument.\n> > \n> > This is needed to implement pre-commit hook.\n> > \n> > Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n> > Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > ---\n> >  utils/checkstyle.py | 26 +++++++++++++++++++++++++-\n> >  1 file changed, 25 insertions(+), 1 deletion(-)\n> > \n> > diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> > index 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> You should call the constructor of StagedChanges, not Commit.\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \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\nAnd here you can use\n\n        ret = subprocess.run(['git', 'show', '--pretty=oneline', '-s'],\n\nto generate a single line.\n\n> > +                             stdout=subprocess.PIPE).stdout.decode('utf-8')\n> > +        title = 'Amendment of: ' + ret.splitlines()[0]\n> > +        # Extract the list of modifier files\n\ns/modifier/modified/\n\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:","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F35160455\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 18 Jan 2020 19:33:41 +0100 (CET)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8657D97A;\n\tSat, 18 Jan 2020 19:33:40 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1579372420;\n\tbh=H9Mm3HeRg5NDPhTrlV5Jw396XOAtGshNX2RcAgCghKA=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=L/Ha+ia87vy7KknWo6As47fUoPoE+TjSpEfIcuNUd5zIRv0BE8R+JPnJeSksebhjq\n\tiP8TP2Zhncw489o60ULFur2mvU2l0MZ9NY2U+nWQysPGSnpVTsIBPDS+m2E1Pf2TUw\n\tJ3zl9QhAQTIfjM4/H6zTwMWnToDaBSx6+PnIaU+w=","Date":"Sat, 18 Jan 2020 20:33:26 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Nicolas Dufresne <nicolas@ndufresne.ca>","Cc":"libcamera-devel@lists.libcamera.org,\n\tNicolas Dufresne <nicolas.dufresne@collabora.com>","Message-ID":"<20200118183326.GH5095@pendragon.ideasonboard.com>","References":"<20200118035448.230530-1-nicolas@ndufresne.ca>\n\t<20200118035448.230530-6-nicolas@ndufresne.ca>\n\t<20200118180220.GD5095@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20200118180220.GD5095@pendragon.ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [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 18:33:41 -0000"}}]