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

login
register
mail settings
Submitter Gregory Szorc
Date April 2, 2015, 5:41 a.m.
Message ID <ab02d467a58597175db3.1427953319@gps-mbp.local>
Download mbox | patch
Permalink /patch/8447/
State Accepted
Headers show

Comments

Gregory Szorc - April 2, 2015, 5:41 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1427951043 25200
#      Wed Apr 01 22:04:03 2015 -0700
# Node ID ab02d467a58597175db35999548e1c24b0fa6452
# Parent  e637a0a086cf1c76ee95993c6f59a3a3b5f9e4be
json: implement {manifest} template

Property naming was borrowed from `hg files -Tjson`.

We omit branch because, again, representation of branches in this
template is wonky.
Matt Mackall - April 2, 2015, 9:01 p.m.
On Wed, 2015-04-01 at 22:41 -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1427951043 25200
> #      Wed Apr 01 22:04:03 2015 -0700
> # Node ID ab02d467a58597175db35999548e1c24b0fa6452
> # Parent  e637a0a086cf1c76ee95993c6f59a3a3b5f9e4be
> json: implement {manifest} template
> 
> Property naming was borrowed from `hg files -Tjson`.
> 
> We omit branch because, again, representation of branches in this
> template is wonky.

These first two are queued, thanks.

Patch

diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
--- a/mercurial/templates/json/map
+++ b/mercurial/templates/json/map
@@ -28,9 +28,29 @@  changeset = '\{
 changesetbranch = '{name|json}'
 changesetbookmark = '{bookmark|json}'
 changesettag = '{tag|json}'
 changesetparent = '{node|json}'
-manifest = '"not yet implemented"'
+manifest = '\{
+  "node": {node|json},
+  "abspath": {path|json},
+  "directories": [{join(dentries%direntry, ", ")}],
+  "files": [{join(fentries%fileentry, ", ")}],
+  "bookmarks": [{join(bookmarks%name, ", ")}],
+  "tags": [{join(tags%name, ", ")}]
+  }'
+name = '{name|json}'
+direntry = '\{
+  "abspath": {path|json},
+  "basename": {basename|json},
+  "emptydirs": {emptydirs|json}
+  }'
+fileentry = '\{
+  "abspath": {file|json},
+  "basename": {basename|json},
+  "date": {date|json},
+  "size": {size|json},
+  "flags": {permissions|json}
+  }'
 tags = '\{
   "node": {node|json},
   "tags": [{join(entriesnotip%tagentry, ", ")}]
   }'
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
@@ -118,12 +118,48 @@  file/{revision}/{path} shows file revisi
   "not yet implemented"
 
 file/{revision} shows root directory info
 
-  $ request json-file/06e557f3edf6
+  $ request json-file/cc725e08502a
   200 Script output follows
   
-  "not yet implemented"
+  {
+    "abspath": "/",
+    "bookmarks": [],
+    "directories": [
+      {
+        "abspath": "/da",
+        "basename": "da",
+        "emptydirs": ""
+      }
+    ],
+    "files": [
+      {
+        "abspath": ".hgtags",
+        "basename": ".hgtags",
+        "date": [
+          0.0,
+          0
+        ],
+        "flags": "",
+        "size": 92
+      },
+      {
+        "abspath": "foo-new",
+        "basename": "foo-new",
+        "date": [
+          0.0,
+          0
+        ],
+        "flags": "",
+        "size": 4
+      }
+    ],
+    "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7",
+    "tags": [
+      "tip"
+    ]
+  }
 
 changelog/ shows information about several changesets
 
   $ request json-changelog
@@ -521,9 +557,33 @@  manifest/{revision}/{path} shows info ab
 
   $ request json-manifest/06e557f3edf6/
   200 Script output follows
   
-  "not yet implemented"
+  {
+    "abspath": "/",
+    "bookmarks": [],
+    "directories": [
+      {
+        "abspath": "/da",
+        "basename": "da",
+        "emptydirs": ""
+      }
+    ],
+    "files": [
+      {
+        "abspath": "foo",
+        "basename": "foo",
+        "date": [
+          0.0,
+          0
+        ],
+        "flags": "",
+        "size": 4
+      }
+    ],
+    "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e",
+    "tags": []
+  }
 
 tags/ shows tags info
 
   $ request json-tags