Patchwork [2,of,4] json: implement {filediff} template

login
register
mail settings
Submitter Gregory Szorc
Date April 11, 2015, 2:40 a.m.
Message ID <c327fa8f34213c97b88e.1428720041@gps-mbp.local>
Download mbox | patch
Permalink /patch/8604/
State Accepted
Commit 1fb56a16e681aa975356a14cc1691f2b8a6a2c60
Headers show

Comments

Gregory Szorc - April 11, 2015, 2:40 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1428719962 14400
#      Fri Apr 10 22:39:22 2015 -0400
# Node ID c327fa8f34213c97b88e34139e50d82c2a5a747a
# Parent  e1ce2479222ac3727bcc5f565bfe414ccac9bf59
json: implement {filediff} template

Single letter properties are used to keep payload size down, as diff
representation can be quite large and longer property names can create a
lot of extra work for parsers.

Rename is not yet captured. This can be done in a follow-up.

Patch

diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
--- a/mercurial/templates/json/map
+++ b/mercurial/templates/json/map
@@ -77,9 +77,42 @@  branchentry = '\{
   "date": {date|json},
   "status": {status|json}
   }'
 summary = '"not yet implemented"'
-filediff = '"not yet implemented"'
+filediff = '\{
+  "path": {file|json},
+  "node": {node|json},
+  "date": {date|json},
+  "desc": {desc|json},
+  "author": {author|json},
+  "parents": [{join(parent%changesetparent, ", ")}],
+  "children": [{join(child%changesetparent, ", ")}],
+  "diff": [{join(diff%diffblock, ", ")}]
+  }'
+diffblock = '\{
+  "blockno": {blockno|json},
+  "lines": [{join(lines, ", ")}]
+  }'
+difflineplus = '\{
+  "t": "+",
+  "n": {lineno|json},
+  "l": {line|json}
+  }'
+difflineminus = '\{
+  "t": "-",
+  "n": {lineno|json},
+  "l": {line|json}
+  }'
+difflineat = '\{
+  "t": "@",
+  "n": {lineno|json},
+  "l": {line|json}
+  }'
+diffline = '\{
+  "t": "",
+  "n": {lineno|json},
+  "l": {line|json}
+  }'
 filecomparison = '"not yet implemented"'
 fileannotate = '"not yet implemented"'
 filelog = '"not yet implemented"'
 graph = '"not yet implemented"'
diff --git a/tests/test-hgweb-json.t b/tests/test-hgweb-json.t
--- a/tests/test-hgweb-json.t
+++ b/tests/test-hgweb-json.t
@@ -677,9 +677,54 @@  filediff/{revision}/{path} shows changes
 
   $ request json-diff/f8bbb9024b10/foo
   200 Script output follows
   
-  "not yet implemented"
+  {
+    "author": "test",
+    "children": [],
+    "date": [
+      0.0,
+      0
+    ],
+    "desc": "modify foo",
+    "diff": [
+      {
+        "blockno": 1,
+        "lines": [
+          {
+            "l": "--- a/foo\tThu Jan 01 00:00:00 1970 +0000\n",
+            "n": 1,
+            "t": "-"
+          },
+          {
+            "l": "+++ b/foo\tThu Jan 01 00:00:00 1970 +0000\n",
+            "n": 2,
+            "t": "+"
+          },
+          {
+            "l": "@@ -1,1 +1,1 @@\n",
+            "n": 3,
+            "t": "@"
+          },
+          {
+            "l": "-foo\n",
+            "n": 4,
+            "t": "-"
+          },
+          {
+            "l": "+bar\n",
+            "n": 5,
+            "t": "+"
+          }
+        ]
+      }
+    ],
+    "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+    "parents": [
+      "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+    ],
+    "path": "foo"
+  }
 
 comparison/{revision}/{path} shows information about before and after for a file
 
   $ request json-comparison/f8bbb9024b10/foo