Show a patch.

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

{
    "id": 54,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/54/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/54/",
    "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": "<20181218194624.21444-1-laurent.pinchart@ideasonboard.com>",
    "date": "2018-12-18T19:46:24",
    "name": "[libcamera-devel] utils: checkstyle.py: Support execution from non-root directories",
    "commit_ref": "2887934ca0385fa7da6d4c1a9654010b979708ab",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "ffcbcce36d2f70a99cd61f88980cac468e8088d3",
    "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/54/mbox/",
    "series": [
        {
            "id": 28,
            "url": "https://patchwork.libcamera.org/api/1.1/series/28/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=28",
            "date": "2018-12-18T19:46:24",
            "name": "[libcamera-devel] utils: checkstyle.py: Support execution from non-root directories",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/28/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/54/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/54/checks/",
    "tags": {},
    "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 E8A3260B0C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 18 Dec 2018 20:45:35 +0100 (CET)",
            "from avalon.bb.dnainternet.fi\n\t(dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi\n\t[IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 421B153A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 18 Dec 2018 20:45:35 +0100 (CET)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1545162335;\n\tbh=24BDaEBW8tjobi0Ae5suyHrpsYClv+HRjjuMTjQ7zYo=;\n\th=From:To:Subject:Date:From;\n\tb=i+qTWZ7WKc2pjEPgpPBvb0euoaGPz1ntIak5D/BfBVHa34UEpzCYB6ZiHsq0jAluv\n\tdrd88URE4+Xmk1sIRE+nsihaPCLpuDuVU1WooEi+fEWICLaLNpnuwlUQzzFCY4RyRu\n\trSRjM+A+8E9Ux3mpt/CUdjR/hb/1pyGed1Dde1UE=",
        "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 18 Dec 2018 21:46:24 +0200",
        "Message-Id": "<20181218194624.21444-1-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.19.2",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH] utils: checkstyle.py: Support execution\n\tfrom non-root directories",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.23",
        "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": "Tue, 18 Dec 2018 19:45:37 -0000"
    },
    "content": "The git diff command is invoked with relative paths, which causes git to\nfail to locate files when the checkstyle.py script is run from\nsubdirectories of the git tree. Fix this by prepending the absolute path\nto the git tree root directory to the file names.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n utils/checkstyle.py | 34 ++++++++++++++++++++++++++++------\n 1 file changed, 28 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex 6e07ffdc19e6..b7c4d876a145 100755\n--- a/utils/checkstyle.py\n+++ b/utils/checkstyle.py\n@@ -144,10 +144,11 @@ def parse_diff(diff):\n     return hunks\n \n \n-def check_file(commit, filename):\n+def check_file(top_level, commit, filename):\n     # Extract the line numbers touched by the commit.\n-    diff = subprocess.run(['git', 'diff', '%s~..%s' % (commit, commit), '--', filename],\n-                            stdout=subprocess.PIPE).stdout\n+    diff = subprocess.run(['git', 'diff', '%s~..%s' % (commit, commit), '--',\n+                           '%s/%s' % (top_level, filename)],\n+                          stdout=subprocess.PIPE).stdout\n     diff = diff.decode('utf-8').splitlines(True)\n     commit_diff = parse_diff(diff)\n \n@@ -187,7 +188,7 @@ def check_file(commit, filename):\n     return len(formatted_diff)\n \n \n-def check_style(commit):\n+def check_style(top_level, commit):\n     # Get the commit title and list of files.\n     ret = subprocess.run(['git', 'show', '--pretty=oneline','--name-only', commit],\n                          stdout=subprocess.PIPE)\n@@ -208,7 +209,7 @@ def check_style(commit):\n \n     issues = 0\n     for f in files:\n-        issues += check_file(commit, f)\n+        issues += check_file(top_level, commit, f)\n \n     if issues == 0:\n         print(\"No style issue detected\")\n@@ -240,6 +241,18 @@ def extract_revlist(revs):\n     return revlist\n \n \n+def git_top_level():\n+    \"\"\"Get the absolute path of the git top-level directory.\"\"\"\n+    ret = subprocess.run(['git', 'rev-parse', '--show-toplevel'],\n+                         stdout=subprocess.PIPE,\n+                         stderr=subprocess.PIPE)\n+    if ret.returncode != 0:\n+        print(ret.stderr.decode('utf-8').splitlines()[0])\n+        return None\n+\n+    return ret.stdout.decode('utf-8').strip()\n+\n+\n def main(argv):\n \n     # Parse command line arguments\n@@ -256,12 +269,21 @@ def main(argv):\n             print(\"Executable %s not found\" % dependency)\n             return 1\n \n+    # Get the top level directory to pass absolute file names to git diff\n+    # commands, in order to support execution from subdirectories of the git\n+    # tree.\n+    top_level = git_top_level()\n+    if top_level is None:\n+            return 1\n+\n     revlist = extract_revlist(args.revision_range)\n \n     for commit in revlist:\n-        check_style(commit)\n+        check_style(top_level, commit)\n         print('')\n \n+    return 0\n+\n \n if __name__ == '__main__':\n     sys.exit(main(sys.argv))\n",
    "prefixes": [
        "libcamera-devel"
    ]
}