Show a patch.

GET /api/1.1/patches/20870/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 20870,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/20870/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/20870/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20240810005840.20841-2-laurent.pinchart@ideasonboard.com>",
    "date": "2024-08-10T00:58:39",
    "name": "[2/3] utils: checkstyle.py: Skip title and trailers checkers for pre-commit",
    "commit_ref": "35f045f9783d22a94de7a8ac173db67e41cfd258",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "9f87777b9964cb250ce1f5d1b66a15c322aa74c2",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/20870/mbox/",
    "series": [
        {
            "id": 4508,
            "url": "https://patchwork.libcamera.org/api/1.1/series/4508/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4508",
            "date": "2024-08-10T00:58:38",
            "name": "[1/3] utils: checkstyle.py: Rework commit message parsing",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/4508/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/20870/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/20870/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 1BE18BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 10 Aug 2024 00:59:10 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C61A7633BE;\n\tSat, 10 Aug 2024 02:59:08 +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 B6AD563398\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 10 Aug 2024 02:59:05 +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 14D274AB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 10 Aug 2024 02:58:11 +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=\"PeoYNR+B\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1723251491;\n\tbh=TeT5iMEHtALqBdeywfOnjCzCMO6MbgIkPLlDMyxfhvs=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=PeoYNR+BzGwzpCkVB3AMkmEU6GEHxd+kaodkQMaX2FYIQKv+6pPgCu3LOAkBhkPqu\n\tDm+7M2Wh3uikg2jS2gvvYYwAp0gK5eobJnMlVlHyOkUs9MgEBVDyMnu0kZguM6AbJy\n\tYJmkyScTiN/kwlu2WKDp2KGm/mntNyXiUQUte4Bo=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Subject": "[PATCH 2/3] utils: checkstyle.py: Skip title and trailers checkers\n\tfor pre-commit",
        "Date": "Sat, 10 Aug 2024 03:58:39 +0300",
        "Message-ID": "<20240810005840.20841-2-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.44.2",
        "In-Reply-To": "<20240810005840.20841-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20240810005840.20841-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "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>"
    },
    "content": "When running checkstyle.py in a pre-commit hook, there is either no\ncommit message at all (when committing staged changes as a new commit),\nor the commit message comes from a previous commit being amended. In\neither case, there's no new commit message yet, and thus nothing to\nvalidate for the title and trailers checkers. The trailers checker, in\nparticular, will always flag an error, making all commits fail.\n\nTo fix that, just skip the two checkers during pre-commit.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n utils/checkstyle.py | 22 ++++++++++++++--------\n 1 file changed, 14 insertions(+), 8 deletions(-)",
    "diff": "diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex 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\n",
    "prefixes": [
        "2/3"
    ]
}