Show a patch.

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

{
    "id": 2664,
    "url": "https://patchwork.libcamera.org/api/patches/2664/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/2664/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20200117191733.198897-5-nicolas@ndufresne.ca>",
    "date": "2020-01-17T19:17:31",
    "name": "[libcamera-devel,v2,4/6] checkstyle: Add support for checking style on indexed changes",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "10fd84c0b1b348aba5f5f8b693b0335f715db825",
    "submitter": {
        "id": 30,
        "url": "https://patchwork.libcamera.org/api/people/30/?format=api",
        "name": "Nicolas Dufresne",
        "email": "nicolas@ndufresne.ca"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/2664/mbox/",
    "series": [
        {
            "id": 634,
            "url": "https://patchwork.libcamera.org/api/series/634/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=634",
            "date": "2020-01-17T19:17:27",
            "name": "Add the ability to do pre-commit style check",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/634/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/2664/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/2664/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<nicolas@ndufresne.ca>",
        "Received": [
            "from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A10A260783\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jan 2020 20:17:59 +0100 (CET)",
            "from nicolas-tpx395.localdomain (unknown [IPv6:2610:98:8005::127])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits))\n\t(No client certificate requested) (Authenticated sender: nicolas)\n\tby bhuna.collabora.co.uk (Postfix) with ESMTPSA id 2CBEA2949D5;\n\tFri, 17 Jan 2020 19:17:59 +0000 (GMT)"
        ],
        "From": "Nicolas Dufresne <nicolas@ndufresne.ca>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Nicolas Dufresne <nicolas.dufresne@collabora.com>",
        "Date": "Fri, 17 Jan 2020 14:17:31 -0500",
        "Message-Id": "<20200117191733.198897-5-nicolas@ndufresne.ca>",
        "X-Mailer": "git-send-email 2.24.1",
        "In-Reply-To": "<20200117191733.198897-1-nicolas@ndufresne.ca>",
        "References": "<20200117191733.198897-1-nicolas@ndufresne.ca>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 4/6] checkstyle: Add support for\n\tchecking style on indexed changes",
        "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": "Fri, 17 Jan 2020 19:18:00 -0000"
    },
    "content": "From: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\nThis introduce a new command line \"--staged\" and a new special type of\ncommit \"Index\". It will check the style of changes that are in the\nindex, so the changes that would be committed by \"git commit\".\n\n\"--staged\" was chosen to match with \"git diff --staged\" command line.\nOther valid name could have been \"--index\" or \"--cached\". This was\nmy personal preference, alias can be added later. Note that we must\nnot confuse this with working tree changes, as these changes are not\npicked by \"git commit\".\n\nThis feature is needed to implement pre-commit hook.\n\nSigned-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n---\n utils/checkstyle.py | 34 ++++++++++++++++++++++++++++++++--\n 1 file changed, 32 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex fb865c8..8e456cd 100644\n--- a/utils/checkstyle.py\n+++ b/utils/checkstyle.py\n@@ -482,6 +482,25 @@ class Commit:\n                               stdout=subprocess.PIPE).stdout.decode('utf-8')\n \n \n+class Index(Commit):\n+    def __init__(self):\n+        Commit.__init__(self, None)\n+\n+    def get_info(self, top_level):\n+        ret = subprocess.run(['git', 'diff', '--staged', '--name-only'],\n+                             stdout=subprocess.PIPE).stdout.decode('utf-8')\n+        return \"Staged changes\", ret.splitlines()\n+\n+    def get_diff(self, top_level, filename):\n+        return subprocess.run(['git', 'diff', '--staged', '--',\n+                               '%s/%s' % (top_level, filename)],\n+                              stdout=subprocess.PIPE).stdout.decode('utf-8')\n+\n+    def get_file(self, filename):\n+        return subprocess.run(['git', 'show', ':%s' % (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@@ -612,7 +631,9 @@ def main(argv):\n     parser = argparse.ArgumentParser()\n     parser.add_argument('--formatter', '-f', type=str, choices=['astyle', 'clang-format'],\n                         help='Code formatter. Default to clang-format if not specified.')\n-    parser.add_argument('revision_range', type=str, default='HEAD', nargs='?',\n+    parser.add_argument('--staged', '-s', action='store_true',\n+                        help='Include the changes in the index. 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 \n@@ -647,7 +668,16 @@ def main(argv):\n     if top_level is None:\n             return 1\n \n-    revlist = extract_revlist(args.revision_range)\n+    revlist = []\n+    if args.staged:\n+        revlist.append(Index())\n+\n+    # If nothing of --staged or --amend was passed, defaults to HEAD\n+    if len(revlist) == 0 and not args.revision_range:\n+        args.revision_range = 'HEAD'\n+\n+    if args.revision_range:\n+        revlist += extract_revlist(args.revision_range)\n \n     issues = 0\n     for commit in revlist:\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "4/6"
    ]
}