Patchwork [3,of,4] json: implement {comparison} template

login
register
mail settings
Submitter Gregory Szorc
Date April 11, 2015, 2:40 a.m.
Message ID <cb1e30a5c4f4c8ebd09a.1428720042@gps-mbp.local>
Download mbox | patch
Permalink /patch/8605/
State Accepted
Commit 73e3a4ff4eaa239ae64a1f30a662f202c3fdafec
Headers show

Comments

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

Similar to {filediff}, we abbreviate some property names to cut down on
string bloat.

Patch

diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
--- a/mercurial/templates/json/map
+++ b/mercurial/templates/json/map
@@ -111,9 +111,30 @@  diffline = '\{
   "t": "",
   "n": {lineno|json},
   "l": {line|json}
   }'
-filecomparison = '"not yet implemented"'
+filecomparison = '\{
+  "path": {file|json},
+  "node": {node|json},
+  "date": {date|json},
+  "desc": {desc|json},
+  "author": {author|json},
+  "parents": [{join(parent%changesetparent, ", ")}],
+  "children": [{join(child%changesetparent, ", ")}],
+  "leftnode": {leftnode|json},
+  "rightnode": {rightnode|json},
+  "comparison": [{join(comparison, ", ")}]
+  }'
+comparisonblock = '\{
+  "lines": [{join(lines, ", ")}]
+  }'
+comparisonline = '\{
+  "t": {type|json},
+  "ln": {leftlineno|json},
+  "ll": {leftline|json},
+  "rn": {rightlineno|json},
+  "rl": {rightline|json}
+  }'
 fileannotate = '"not yet implemented"'
 filelog = '"not yet implemented"'
 graph = '"not yet implemented"'
 helptopics = '\{
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
@@ -729,9 +729,37 @@  comparison/{revision}/{path} shows infor
 
   $ request json-comparison/f8bbb9024b10/foo
   200 Script output follows
   
-  "not yet implemented"
+  {
+    "author": "test",
+    "children": [],
+    "comparison": [
+      {
+        "lines": [
+          {
+            "ll": "foo",
+            "ln": 1,
+            "rl": "bar",
+            "rn": 1,
+            "t": "replace"
+          }
+        ]
+      }
+    ],
+    "date": [
+      0.0,
+      0
+    ],
+    "desc": "modify foo",
+    "leftnode": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e",
+    "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+    "parents": [
+      "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+    ],
+    "path": "foo",
+    "rightnode": "f8bbb9024b10f93cdbb8d940337398291d40dea8"
+  }
 
 annotate/{revision}/{path} shows annotations for each line
 
   $ request json-annotate/f8bbb9024b10/foo