[PATCH 3 of 5 V2] templates: add support for summary webcommand in json style
Laura Médioni
laura.medioni at logilab.fr
Wed Jun 15 10:48:20 EDT 2016
# HG changeset patch
# User Laura Médioni <laura.medioni at logilab.fr>
# Date 1465218851 -7200
# Mon Jun 06 15:14:11 2016 +0200
# Node ID f4aad36209542e836d91477ce330b2dbb5181443
# Parent 3f9f7b7fb8e5233b057f32ef9caf930f3ea4f28c
templates: add support for summary webcommand in json style
Change summary webcommand to yield each element of the shortlog instead of the
entire list.
This makes generated json more readable since each entry can be formatted
separately, instead of returning all the shortlog content in a single string.
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -705,12 +705,12 @@ def summary(web, req, tmpl):
l.append(tmpl(
'shortlogentry',
parity=next(parity),
**webutil.commonentry(web.repo, ctx)))
- l.reverse()
- yield l
+ for entry in reversed(l):
+ yield entry
tip = web.repo['tip']
count = len(web.repo)
start = max(0, count - web.maxchanges)
end = min(count, start + web.maxchanges)
diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map
--- a/mercurial/templates/json/map
+++ b/mercurial/templates/json/map
@@ -91,11 +91,25 @@ branchentry = '\{
"branch": {branch|utf8|json},
"node": {node|json},
"date": {date|json},
"status": {status|json}
}'
-summary = '"not yet implemented"'
+shortlogentry = '{changeset}'
+summary = '\{
+ "node": {node|json},
+ "lastchange": {lastchange|json},
+ "bookmarks": [{join(bookmarks%bookmarkentry, ", ")}],
+ "branches": [{join(branches%branchentry, ", ")}],
+ "shortlog": [{join(shortlog%shortlogentry, ", ")}],
+ "tags": [{join(tags%tagentry, ", ")}],
+ "archives": [{join(archives%archiveentry, ", ")}]
+ }'
+archiveentry = '\{
+ "node": {node|json},
+ "extension": {extension|json},
+ "type": {type|json}
+ }'
filediff = '\{
"path": {file|json},
"node": {node|json},
"date": {date|json},
"desc": {desc|utf8|json},
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
@@ -753,11 +753,275 @@ branches/ shows branches info
summary/ shows a summary of repository state
$ request json-summary
200 Script output follows
- "not yet implemented"
+ {
+ "archives": [],
+ "bookmarks": [
+ {
+ "bookmark": "bookmark2",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "node": "ceed296fe500c3fac9541e31dad860cb49c89e45"
+ },
+ {
+ "bookmark": "bookmark1",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5"
+ }
+ ],
+ "branches": [
+ {
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7",
+ "status": "open"
+ },
+ {
+ "branch": "test-branch",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "node": "ed66c30e87eb65337c05a4229efaa5f1d5285a90",
+ "status": "inactive"
+ }
+ ],
+ "lastchange": [
+ 0.0,
+ 0
+ ],
+ "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7",
+ "shortlog": [
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "merge test-branch into default",
+ "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7",
+ "parents": [
+ "ceed296fe500c3fac9541e31dad860cb49c89e45",
+ "ed66c30e87eb65337c05a4229efaa5f1d5285a90"
+ ],
+ "phase": "draft",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "test-branch",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "another commit in test-branch",
+ "node": "ed66c30e87eb65337c05a4229efaa5f1d5285a90",
+ "parents": [
+ "6ab967a8ab3489227a83f80e920faa039a71819f"
+ ],
+ "phase": "draft",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "test-branch",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "create test branch",
+ "node": "6ab967a8ab3489227a83f80e920faa039a71819f",
+ "parents": [
+ "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+ ],
+ "phase": "draft",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "create tag2",
+ "node": "ceed296fe500c3fac9541e31dad860cb49c89e45",
+ "parents": [
+ "f2890a05fea49bfaf9fb27ed5490894eba32da78"
+ ],
+ "phase": "draft",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "another commit to da/foo",
+ "node": "f2890a05fea49bfaf9fb27ed5490894eba32da78",
+ "parents": [
+ "93a8ce14f89156426b7fa981af8042da53f03aa0"
+ ],
+ "phase": "draft",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "create tag",
+ "node": "93a8ce14f89156426b7fa981af8042da53f03aa0",
+ "parents": [
+ "78896eb0e102174ce9278438a95e12543e4367a7"
+ ],
+ "phase": "public",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "move foo",
+ "node": "78896eb0e102174ce9278438a95e12543e4367a7",
+ "parents": [
+ "8d7c456572acf3557e8ed8a07286b10c408bcec5"
+ ],
+ "phase": "public",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "modify da/foo",
+ "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5",
+ "parents": [
+ "f8bbb9024b10f93cdbb8d940337398291d40dea8"
+ ],
+ "phase": "public",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "modify foo",
+ "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8",
+ "parents": [
+ "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+ ],
+ "phase": "public",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ },
+ {
+ "bookmarks": [
+ ""
+ ],
+ "branch": "default",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "initial",
+ "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e",
+ "parents": [],
+ "phase": "public",
+ "tags": [
+ ""
+ ],
+ "user": "test"
+ }
+ ],
+ "tags": [
+ {
+ "date": [
+ 0.0,
+ 0
+ ],
+ "node": "f2890a05fea49bfaf9fb27ed5490894eba32da78",
+ "tag": "tag2"
+ },
+ {
+ "date": [
+ 0.0,
+ 0
+ ],
+ "node": "78896eb0e102174ce9278438a95e12543e4367a7",
+ "tag": "tag1"
+ }
+ ]
+ }
filediff/{revision}/{path} shows changes to a file in a revision
$ request json-diff/f8bbb9024b10/foo
200 Script output follows
More information about the Mercurial-devel
mailing list