# HG changeset patch # User Gregory Szorc # Date 2015-04-01 05:53:48 # Node ID 0bf54479a9eb600521939f39b31188a52be8f850 # Parent 76c0b4cfa0396339668bd2ce6716d83afc035b53 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. diff --git a/mercurial/templates/json/changelist.tmpl b/mercurial/templates/json/changelist.tmpl new file mode 100644 --- /dev/null +++ b/mercurial/templates/json/changelist.tmpl @@ -0,0 +1,5 @@ +\{ + "node": {node|json}, + "changeset_count": {changesets|json}, + "changesets": [{join(entries%changelistentry, ", ")}] +} diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map --- a/mercurial/templates/json/map +++ b/mercurial/templates/json/map @@ -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}, 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 @@ -129,21 +129,298 @@ changelog/ shows information about sever $ 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