Mercurial > hg
changeset 24588:0bf54479a9eb
json: implement {shortlog} and {changelog} templates
These are the same dispatch function under the hood. The only difference
is the default number of entries to render and the template to use. So
it makes sense to use a shared template.
Format for {changelistentry} is similar to {changeset}. However, there
are differences to argument names and their values preventing us from
(easily) using the same template. (Perhaps there is room to consolidate
the templates as a follow-up.)
We're currently not recording some data in {changelistentry} that exists
in {changeset}. This includes the branch name. This should be added in
a follow-up. For now, something is better than nothing.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 31 Mar 2015 22:53:48 -0700 |
parents | 76c0b4cfa039 |
children | 30a737ae9b7d |
files | mercurial/templates/json/changelist.tmpl mercurial/templates/json/map tests/test-hgweb-json.t |
diffstat | 3 files changed, 300 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial/templates/json/changelist.tmpl Tue Mar 31 22:53:48 2015 -0700 @@ -0,0 +1,5 @@ +\{ + "node": {node|json}, + "changeset_count": {changesets|json}, + "changesets": [{join(entries%changelistentry, ", ")}] +}
--- a/mercurial/templates/json/map Wed Apr 01 20:23:58 2015 -0700 +++ b/mercurial/templates/json/map Tue Mar 31 22:53:48 2015 -0700 @@ -1,8 +1,19 @@ mimetype = 'application/json' filerevision = '"not yet implemented"' search = '"not yet implemented"' -shortlog = '"not yet implemented"' -changelog = '"not yet implemented"' +# changelog and shortlog are the same web API but with different +# number of entries. +changelog = changelist.tmpl +shortlog = changelist.tmpl +changelistentry = '\{ + "node": {node|json}, + "date": {date|json}, + "desc": {desc|json}, + "bookmarks": [{join(bookmarks%changelistentryname, ", ")}], + "tags": [{join(tags%changelistentryname, ", ")}], + "user": {author|json} + }' +changelistentryname = '{name|json}' changeset = '\{ "node": {node|json}, "date": {date|json},
--- a/tests/test-hgweb-json.t Wed Apr 01 20:23:58 2015 -0700 +++ b/tests/test-hgweb-json.t Tue Mar 31 22:53:48 2015 -0700 @@ -129,21 +129,298 @@ $ request json-changelog 200 Script output follows - "not yet implemented" + { + "changeset_count": 10, + "changesets": [ + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "merge test-branch into default", + "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7", + "tags": [ + "tip" + ], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "another commit in test-branch", + "node": "ed66c30e87eb65337c05a4229efaa5f1d5285a90", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "create test branch", + "node": "6ab967a8ab3489227a83f80e920faa039a71819f", + "tags": [], + "user": "test" + }, + { + "bookmarks": [ + "bookmark2" + ], + "date": [ + 0.0, + 0 + ], + "desc": "create tag2", + "node": "ceed296fe500c3fac9541e31dad860cb49c89e45", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "another commit to da/foo", + "node": "f2890a05fea49bfaf9fb27ed5490894eba32da78", + "tags": [ + "tag2" + ], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "create tag", + "node": "93a8ce14f89156426b7fa981af8042da53f03aa0", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "move foo", + "node": "78896eb0e102174ce9278438a95e12543e4367a7", + "tags": [ + "tag1" + ], + "user": "test" + }, + { + "bookmarks": [ + "bookmark1" + ], + "date": [ + 0.0, + 0 + ], + "desc": "modify da/foo", + "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "modify foo", + "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "initial", + "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e", + "tags": [], + "user": "test" + } + ], + "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7" + } -changelog/{revision} shows information about a single changeset +changelog/{revision} shows information starting at a specific changeset - $ request json-changelog/06e557f3edf6 + $ request json-changelog/f8bbb9024b10 200 Script output follows - "not yet implemented" + { + "changeset_count": 10, + "changesets": [ + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "modify foo", + "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "initial", + "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e", + "tags": [], + "user": "test" + } + ], + "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8" + } shortlog/ shows information about a set of changesets $ request json-shortlog 200 Script output follows - "not yet implemented" + { + "changeset_count": 10, + "changesets": [ + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "merge test-branch into default", + "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7", + "tags": [ + "tip" + ], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "another commit in test-branch", + "node": "ed66c30e87eb65337c05a4229efaa5f1d5285a90", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "create test branch", + "node": "6ab967a8ab3489227a83f80e920faa039a71819f", + "tags": [], + "user": "test" + }, + { + "bookmarks": [ + "bookmark2" + ], + "date": [ + 0.0, + 0 + ], + "desc": "create tag2", + "node": "ceed296fe500c3fac9541e31dad860cb49c89e45", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "another commit to da/foo", + "node": "f2890a05fea49bfaf9fb27ed5490894eba32da78", + "tags": [ + "tag2" + ], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "create tag", + "node": "93a8ce14f89156426b7fa981af8042da53f03aa0", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "move foo", + "node": "78896eb0e102174ce9278438a95e12543e4367a7", + "tags": [ + "tag1" + ], + "user": "test" + }, + { + "bookmarks": [ + "bookmark1" + ], + "date": [ + 0.0, + 0 + ], + "desc": "modify da/foo", + "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "modify foo", + "node": "f8bbb9024b10f93cdbb8d940337398291d40dea8", + "tags": [], + "user": "test" + }, + { + "bookmarks": [], + "date": [ + 0.0, + 0 + ], + "desc": "initial", + "node": "06e557f3edf66faa1ccaba5dd8c203c21cc79f1e", + "tags": [], + "user": "test" + } + ], + "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7" + } changeset/ renders the tip changeset