[PATCH 2 of 4] templates: add support for summary webcommand in json style
Laura Médioni
laura.medioni at logilab.fr
Wed Jun 15 08:06:06 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 8a068602ddea1d5021acd55b8d5d13c436900fda
# Parent 21e855b309f5c1527938874ededc8168fa387c17
templates: add support for summary webcommand in json style
Change summary webcommand to yield each element of the sortlog 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
@@ -83,11 +83,30 @@ branchentry = '\{
"branch": {branch|utf8|json},
"node": {node|json},
"date": {date|json},
"status": {status|json}
}'
-summary = '"not yet implemented"'
+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}
+ }'
+shortlogentry = '\{
+ "node": {node|json},
+ "date": {date|json},
+ "desc": {desc|utf8|json},
+ "author": {author|utf8|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
@@ -738,11 +738,166 @@ 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": [
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "merge test-branch into default",
+ "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "another commit in test-branch",
+ "node": "ed66c30e87eb65337c05a4229efaa5f1d5285a90"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "create test branch",
+ "node": "6ab967a8ab3489227a83f80e920faa039a71819f"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "create tag2",
+ "node": "ceed296fe500c3fac9541e31dad860cb49c89e45"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "another commit to da/foo",
+ "node": "f2890a05fea49bfaf9fb27ed5490894eba32da78"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "create tag",
+ "node": "93a8ce14f89156426b7fa981af8042da53f03aa0"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "move foo",
+ "node": "78896eb0e102174ce9278438a95e12543e4367a7"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "modify da/foo",
+ "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "modify foo",
+ "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8"
+ },
+ {
+ "author": "test",
+ "date": [
+ 0.0,
+ 0
+ ],
+ "desc": "initial",
+ "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e"
+ }
+ ],
+ "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