[{"id":30722,"web_url":"https://patchwork.libcamera.org/comment/30722/","msgid":"<87ed6uw879.fsf@redhat.com>","date":"2024-08-12T06:45:14","subject":"Re: [PATCH 2/3] utils: checkstyle.py: Skip title and trailers\n\tcheckers for pre-commit","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> When running checkstyle.py in a pre-commit hook, there is either no\n> commit message at all (when committing staged changes as a new commit),\n> or the commit message comes from a previous commit being amended. In\n> either case, there's no new commit message yet, and thus nothing to\n> validate for the title and trailers checkers. The trailers checker, in\n> particular, will always flag an error, making all commits fail.\n>\n> To fix that, just skip the two checkers during pre-commit.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  utils/checkstyle.py | 22 ++++++++++++++--------\n>  1 file changed, 14 insertions(+), 8 deletions(-)\n>\n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index aa0731abdb5a..2b1e1f6c1b9e 100755\n> --- a/utils/checkstyle.py\n> +++ b/utils/checkstyle.py\n> @@ -344,11 +344,16 @@ class CommitChecker(metaclass=ClassRegistry):\n>      # Class methods\n>      #\n>      @classmethod\n> -    def checkers(cls, names):\n> +    def checkers(cls, commit, names):\n>          for checker in cls.subclasses:\n>              if names and checker.__name__ not in names:\n>                  continue\n> -            yield checker\n> +            if checker.supports(commit):\n> +                yield checker\n> +\n> +    @classmethod\n> +    def supports(cls, commit):\n> +        return type(commit) in cls.commit_types\n>  \n>  \n>  class CommitIssue(object):\n> @@ -357,6 +362,8 @@ class CommitIssue(object):\n>  \n>  \n>  class HeaderAddChecker(CommitChecker):\n> +    commit_types = (Commit, StagedChanges, Amendment)\n> +\n>      @classmethod\n>      def check(cls, commit, top_level):\n>          issues = []\n> @@ -401,6 +408,8 @@ class HeaderAddChecker(CommitChecker):\n>  \n>  \n>  class TitleChecker(CommitChecker):\n> +    commit_types = (Commit,)\n> +\n>      prefix_regex = re.compile(r'^([a-zA-Z0-9_.-]+: )+')\n>      release_regex = re.compile(r'libcamera v[0-9]+\\.[0-9]+\\.[0-9]+')\n>  \n> @@ -408,11 +417,6 @@ class TitleChecker(CommitChecker):\n>      def check(cls, commit, top_level):\n>          title = commit.title\n>  \n> -        # Skip the check when validating staged changes (as done through a\n> -        # pre-commit hook) as there is no title to check in that case.\n> -        if isinstance(commit, StagedChanges):\n> -            return []\n> -\n>          # Ignore release commits, they don't need a prefix.\n>          if TitleChecker.release_regex.fullmatch(title):\n>              return []\n> @@ -468,6 +472,8 @@ class TitleChecker(CommitChecker):\n>  \n>  \n>  class TrailersChecker(CommitChecker):\n> +    commit_types = (Commit,)\n> +\n>      commit_regex = re.compile(r'[0-9a-f]{12}[0-9a-f]* \\(\".*\"\\)')\n>  \n>      coverity_regex = re.compile(r'Coverity CID=.*')\n> @@ -1020,7 +1026,7 @@ def check_style(top_level, commit, checkers):\n>      issues = 0\n>  \n>      # Apply the commit checkers first.\n> -    for checker in CommitChecker.checkers(checkers):\n> +    for checker in CommitChecker.checkers(commit, checkers):\n>          for issue in checker.check(commit, top_level):\n>              print('%s%s%s' % (Colours.fg(Colours.Yellow), issue.msg, Colours.reset()))\n>              issues += 1","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 CCEE0C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Aug 2024 06:45:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7D8E3633BD;\n\tMon, 12 Aug 2024 08:45:22 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EE6CC63398\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 08:45:20 +0200 (CEST)","from mail-ej1-f72.google.com (mail-ej1-f72.google.com\n\t[209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-450-VGHmupwjMAOSztSRJviNLw-1; Mon, 12 Aug 2024 02:45:18 -0400","by mail-ej1-f72.google.com with SMTP id\n\ta640c23a62f3a-a7a83f54fdeso328780766b.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 11 Aug 2024 23:45:17 -0700 (PDT)","from nuthatch (ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\ta640c23a62f3a-a80bb0e49a5sm202777066b.69.2024.08.11.23.45.15\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 11 Aug 2024 23:45:15 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"dtJ+ea7K\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1723445119;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=+aE+HwjYkhoVbBiQg44E1xXpenXuGp2PpGsB6ggJTbk=;\n\tb=dtJ+ea7KCjREqomUAyzi44UH6de/ECGBTWV2RlQAqDchHclekIwYlkA58VX6J/c998E2Qw\n\tekeLq1E8qrOIswudeixSs3YsKSFg5SyfR9qCizKUPpjfSRfZZBnyvXy5/ZyPgd3D+OQus5\n\t8Yun9XoSeCOO2aBuNzM5KXScs9hsW5s=","X-MC-Unique":"VGHmupwjMAOSztSRJviNLw-1","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1723445116; x=1724049916;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=+aE+HwjYkhoVbBiQg44E1xXpenXuGp2PpGsB6ggJTbk=;\n\tb=bCTfUxGr1qnV4Sp1VvkEr50mOXCOwdZkSs2aQ5DajM/1w4X+eWirp4DLWrd9cSXhYe\n\tLHMHv/+NoKOeAxNN2jnflkj7JoY85IAvJrBJj2YVifdhGZs1nPj76+TJlTFoCnp1tHjs\n\t+W5DaerL7tiOHOtOxI+lq1WL5LqkKbk52gdoaboCJS23A6fikmYeaFaXasQg0F2qI+06\n\tIgwl8iLI0RaqaN5foBzd58kMWFkE/2UPNP17lrtalJOroAFJqwUxaoLhmz2ihHNZzN3x\n\tsZDllKIQhbDrLfOE2/awhTop1ClNfzxXnsp/EgUlgkJoAi/ifsX5/ecVVWsetaRnCEsd\n\tXpVg==","X-Gm-Message-State":"AOJu0Yx8L8JJ3y6JUoQKXM7DJ7eEWFRxse7KNIHNePRCu5v3qMKrqeXs\n\tej85geeEZkPAt0RYawgKjb7K2WEemqGMiDi4/ivC/PSmlJVSYk9en9/L9j28Xn7e7bbnsqVYhsU\n\tWXH0C/kCXgQyik43lH2uCSThZnwarcCQwMonjBYtoQCr21NjWsOzJNivib5mgkcnEZSTdcba6Xm\n\t4N5yPU7Crm9oM0eldDHwSygznmrtL73LjTGaD3j9BvdejmaDNZOYST9vw=","X-Received":["by 2002:a17:906:d25c:b0:a7d:2498:f927 with SMTP id\n\ta640c23a62f3a-a80aa65f05dmr560437366b.44.1723445116295; \n\tSun, 11 Aug 2024 23:45:16 -0700 (PDT)","by 2002:a17:906:d25c:b0:a7d:2498:f927 with SMTP id\n\ta640c23a62f3a-a80aa65f05dmr560436466b.44.1723445115843; \n\tSun, 11 Aug 2024 23:45:15 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IGtnJDJskh5OjwnUMW12UNB3Q6jGRItidPwOmDRcC5OoRMelKoARCcao83FLl7qdFY60sw+Fw==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 2/3] utils: checkstyle.py: Skip title and trailers\n\tcheckers for pre-commit","In-Reply-To":"<20240810005840.20841-2-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Sat, 10 Aug 2024 03:58:39 +0300\")","References":"<20240810005840.20841-1-laurent.pinchart@ideasonboard.com>\n\t<20240810005840.20841-2-laurent.pinchart@ideasonboard.com>","Date":"Mon, 12 Aug 2024 08:45:14 +0200","Message-ID":"<87ed6uw879.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":30732,"web_url":"https://patchwork.libcamera.org/comment/30732/","msgid":"<6dfad6b8-6378-4a07-8264-afe7909a3312@ideasonboard.com>","date":"2024-08-12T12:07:08","subject":"Re: [PATCH 2/3] utils: checkstyle.py: Skip title and trailers\n\tcheckers for pre-commit","submitter":{"id":156,"url":"https://patchwork.libcamera.org/api/people/156/","name":"Dan Scally","email":"dan.scally@ideasonboard.com"},"content":"Hi Laurent, thanks for the patch\n\nOn 10/08/2024 01:58, Laurent Pinchart wrote:\n> When running checkstyle.py in a pre-commit hook, there is either no\n> commit message at all (when committing staged changes as a new commit),\n> or the commit message comes from a previous commit being amended. In\n> either case, there's no new commit message yet, and thus nothing to\n> validate for the title and trailers checkers. The trailers checker, in\n> particular, will always flag an error, making all commits fail.\n>\n> To fix that, just skip the two checkers during pre-commit.\n\n\nI like that this is done in a way which facilitates the same thing being done more easily in the \nfuture if needed.\n\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n\nReviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n\n> ---\n>   utils/checkstyle.py | 22 ++++++++++++++--------\n>   1 file changed, 14 insertions(+), 8 deletions(-)\n>\n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index aa0731abdb5a..2b1e1f6c1b9e 100755\n> --- a/utils/checkstyle.py\n> +++ b/utils/checkstyle.py\n> @@ -344,11 +344,16 @@ class CommitChecker(metaclass=ClassRegistry):\n>       # Class methods\n>       #\n>       @classmethod\n> -    def checkers(cls, names):\n> +    def checkers(cls, commit, names):\n>           for checker in cls.subclasses:\n>               if names and checker.__name__ not in names:\n>                   continue\n> -            yield checker\n> +            if checker.supports(commit):\n> +                yield checker\n> +\n> +    @classmethod\n> +    def supports(cls, commit):\n> +        return type(commit) in cls.commit_types\n>   \n>   \n>   class CommitIssue(object):\n> @@ -357,6 +362,8 @@ class CommitIssue(object):\n>   \n>   \n>   class HeaderAddChecker(CommitChecker):\n> +    commit_types = (Commit, StagedChanges, Amendment)\n> +\n>       @classmethod\n>       def check(cls, commit, top_level):\n>           issues = []\n> @@ -401,6 +408,8 @@ class HeaderAddChecker(CommitChecker):\n>   \n>   \n>   class TitleChecker(CommitChecker):\n> +    commit_types = (Commit,)\n> +\n>       prefix_regex = re.compile(r'^([a-zA-Z0-9_.-]+: )+')\n>       release_regex = re.compile(r'libcamera v[0-9]+\\.[0-9]+\\.[0-9]+')\n>   \n> @@ -408,11 +417,6 @@ class TitleChecker(CommitChecker):\n>       def check(cls, commit, top_level):\n>           title = commit.title\n>   \n> -        # Skip the check when validating staged changes (as done through a\n> -        # pre-commit hook) as there is no title to check in that case.\n> -        if isinstance(commit, StagedChanges):\n> -            return []\n> -\n>           # Ignore release commits, they don't need a prefix.\n>           if TitleChecker.release_regex.fullmatch(title):\n>               return []\n> @@ -468,6 +472,8 @@ class TitleChecker(CommitChecker):\n>   \n>   \n>   class TrailersChecker(CommitChecker):\n> +    commit_types = (Commit,)\n> +\n>       commit_regex = re.compile(r'[0-9a-f]{12}[0-9a-f]* \\(\".*\"\\)')\n>   \n>       coverity_regex = re.compile(r'Coverity CID=.*')\n> @@ -1020,7 +1026,7 @@ def check_style(top_level, commit, checkers):\n>       issues = 0\n>   \n>       # Apply the commit checkers first.\n> -    for checker in CommitChecker.checkers(checkers):\n> +    for checker in CommitChecker.checkers(commit, checkers):\n>           for issue in checker.check(commit, top_level):\n>               print('%s%s%s' % (Colours.fg(Colours.Yellow), issue.msg, Colours.reset()))\n>               issues += 1","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 0BBD6BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Aug 2024 12:07:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F28F4633B5;\n\tMon, 12 Aug 2024 14:07:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AD3FB63369\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 14:07:11 +0200 (CEST)","from [192.168.0.43]\n\t(cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4A7256B5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 14:06:15 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"P3pnOphf\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1723464375;\n\tbh=N6BUk8JbJ/5zTkTMW5ggYdIFbg5bbvZlJ+tAoVy7df8=;\n\th=Date:Subject:To:References:From:In-Reply-To:From;\n\tb=P3pnOphfUZe1BXurpT3VPf5DBpCycPN5esGvYV7qDWXIINQWtQiJzva589YixqqWi\n\taCRturieubBWwoFrUhOp/xLcRI8udi7Yn9I2Dc+lj1rXP1ju2wwD7KvbqZid6RKglQ\n\tiV4KGiL/sVbt4dosfZvTOTl09xMHZMimenX/GcGg=","Message-ID":"<6dfad6b8-6378-4a07-8264-afe7909a3312@ideasonboard.com>","Date":"Mon, 12 Aug 2024 13:07:08 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH 2/3] utils: checkstyle.py: Skip title and trailers\n\tcheckers for pre-commit","To":"libcamera-devel@lists.libcamera.org","References":"<20240810005840.20841-1-laurent.pinchart@ideasonboard.com>\n\t<20240810005840.20841-2-laurent.pinchart@ideasonboard.com>","Content-Language":"en-US","From":"Dan Scally <dan.scally@ideasonboard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Reply-To":"<20240810005840.20841-2-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":30733,"web_url":"https://patchwork.libcamera.org/comment/30733/","msgid":"<20240812121022.GA16961@pendragon.ideasonboard.com>","date":"2024-08-12T12:10:22","subject":"Re: [PATCH 2/3] utils: checkstyle.py: Skip title and trailers\n\tcheckers for pre-commit","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Mon, Aug 12, 2024 at 01:07:08PM +0100, Daniel Scally wrote:\n> Hi Laurent, thanks for the patch\n> \n> On 10/08/2024 01:58, Laurent Pinchart wrote:\n> > When running checkstyle.py in a pre-commit hook, there is either no\n> > commit message at all (when committing staged changes as a new commit),\n> > or the commit message comes from a previous commit being amended. In\n> > either case, there's no new commit message yet, and thus nothing to\n> > validate for the title and trailers checkers. The trailers checker, in\n> > particular, will always flag an error, making all commits fail.\n> >\n> > To fix that, just skip the two checkers during pre-commit.\n> \n> I like that this is done in a way which facilitates the same thing being done more easily in the \n> future if needed.\n\nWhen I copied the existing 'if isinstance(commit, StagedChanges):' line\nfrom TitleChecker, I knew before hitting 'p' that I had to do better :-)\n\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>\n> \n> > ---\n> >   utils/checkstyle.py | 22 ++++++++++++++--------\n> >   1 file changed, 14 insertions(+), 8 deletions(-)\n> >\n> > diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> > index aa0731abdb5a..2b1e1f6c1b9e 100755\n> > --- a/utils/checkstyle.py\n> > +++ b/utils/checkstyle.py\n> > @@ -344,11 +344,16 @@ class CommitChecker(metaclass=ClassRegistry):\n> >       # Class methods\n> >       #\n> >       @classmethod\n> > -    def checkers(cls, names):\n> > +    def checkers(cls, commit, names):\n> >           for checker in cls.subclasses:\n> >               if names and checker.__name__ not in names:\n> >                   continue\n> > -            yield checker\n> > +            if checker.supports(commit):\n> > +                yield checker\n> > +\n> > +    @classmethod\n> > +    def supports(cls, commit):\n> > +        return type(commit) in cls.commit_types\n> >   \n> >   \n> >   class CommitIssue(object):\n> > @@ -357,6 +362,8 @@ class CommitIssue(object):\n> >   \n> >   \n> >   class HeaderAddChecker(CommitChecker):\n> > +    commit_types = (Commit, StagedChanges, Amendment)\n> > +\n> >       @classmethod\n> >       def check(cls, commit, top_level):\n> >           issues = []\n> > @@ -401,6 +408,8 @@ class HeaderAddChecker(CommitChecker):\n> >   \n> >   \n> >   class TitleChecker(CommitChecker):\n> > +    commit_types = (Commit,)\n> > +\n> >       prefix_regex = re.compile(r'^([a-zA-Z0-9_.-]+: )+')\n> >       release_regex = re.compile(r'libcamera v[0-9]+\\.[0-9]+\\.[0-9]+')\n> >   \n> > @@ -408,11 +417,6 @@ class TitleChecker(CommitChecker):\n> >       def check(cls, commit, top_level):\n> >           title = commit.title\n> >   \n> > -        # Skip the check when validating staged changes (as done through a\n> > -        # pre-commit hook) as there is no title to check in that case.\n> > -        if isinstance(commit, StagedChanges):\n> > -            return []\n> > -\n> >           # Ignore release commits, they don't need a prefix.\n> >           if TitleChecker.release_regex.fullmatch(title):\n> >               return []\n> > @@ -468,6 +472,8 @@ class TitleChecker(CommitChecker):\n> >   \n> >   \n> >   class TrailersChecker(CommitChecker):\n> > +    commit_types = (Commit,)\n> > +\n> >       commit_regex = re.compile(r'[0-9a-f]{12}[0-9a-f]* \\(\".*\"\\)')\n> >   \n> >       coverity_regex = re.compile(r'Coverity CID=.*')\n> > @@ -1020,7 +1026,7 @@ def check_style(top_level, commit, checkers):\n> >       issues = 0\n> >   \n> >       # Apply the commit checkers first.\n> > -    for checker in CommitChecker.checkers(checkers):\n> > +    for checker in CommitChecker.checkers(commit, checkers):\n> >           for issue in checker.check(commit, top_level):\n> >               print('%s%s%s' % (Colours.fg(Colours.Yellow), issue.msg, Colours.reset()))\n> >               issues += 1","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 22E41BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 12 Aug 2024 12:10:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 02484633BA;\n\tMon, 12 Aug 2024 14:10:46 +0200 (CEST)","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 BF14F63398\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 12 Aug 2024 14:10:45 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2A2B86B5;\n\tMon, 12 Aug 2024 14:09:49 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"qN6An0hR\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1723464589;\n\tbh=/sNsQs13sxjECOk0kisGR2kcWJUUOnfIMMh+tQDgqmU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qN6An0hRbkO/ArqLwjz9aPt5HRKtRhBSCmcynreT1BfD9lOSV4HXIACcj8iwABcBx\n\t70uhZfsaKRaVmv0UjzFGk9IPAh9by/KL/CwuFlQ8KsrG6YkJHJi/qtLf54lmeXJi5T\n\tew9nlgD6jPkBrijBKhYMoQyOqX4AvsNUz99BBIH0=","Date":"Mon, 12 Aug 2024 15:10:22 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Dan Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 2/3] utils: checkstyle.py: Skip title and trailers\n\tcheckers for pre-commit","Message-ID":"<20240812121022.GA16961@pendragon.ideasonboard.com>","References":"<20240810005840.20841-1-laurent.pinchart@ideasonboard.com>\n\t<20240810005840.20841-2-laurent.pinchart@ideasonboard.com>\n\t<6dfad6b8-6378-4a07-8264-afe7909a3312@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<6dfad6b8-6378-4a07-8264-afe7909a3312@ideasonboard.com>","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]