Submitter | Laura Médioni |
---|---|
Date | June 15, 2016, 2:48 p.m. |
Message ID | <33c362973b2ab07b2e20.1466002101@sh79.dev.logilab.fr> |
Download | mbox | patch |
Permalink | /patch/15520/ |
State | Changes Requested |
Headers | show |
Comments
15.06.2016, 22:48, "Laura Médioni" <laura.medioni@logilab.fr>: > # HG changeset patch > # User Laura Médioni <laura.medioni@logilab.fr> > # Date 1465547502 -7200 > # Fri Jun 10 10:31:42 2016 +0200 > # Node ID 33c362973b2ab07b2e20d6818b7e72473e682fd4 > # Parent f4aad36209542e836d91477ce330b2dbb5181443 > templates: add support for search webcommand in json style > > diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map > --- a/mercurial/templates/json/map > +++ b/mercurial/templates/json/map > @@ -13,11 +13,16 @@ filerevision = '\{ > "lines": [{join(text%lineentry, ", ")}] > }' > lineentry = '\{ > "line": {line|json} > }' > -search = '"not yet implemented"' > +search = '\{ > + "node": {node|json}, > + "query": {query|json}, > + "entries": [{join(entries%searchentry, ", ")}] > + }' > +searchentry = '{changeset}' It's better to use a template directly for clarity, since searchentry doesn't do anything on its own.
On 06/16/2016 12:07 PM, Anton Shestakov wrote: > 15.06.2016, 22:48, "Laura Médioni" <laura.medioni@logilab.fr>: >> # HG changeset patch >> # User Laura Médioni <laura.medioni@logilab.fr> >> # Date 1465547502 -7200 >> # Fri Jun 10 10:31:42 2016 +0200 >> # Node ID 33c362973b2ab07b2e20d6818b7e72473e682fd4 >> # Parent f4aad36209542e836d91477ce330b2dbb5181443 >> templates: add support for search webcommand in json style >> >> diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map >> --- a/mercurial/templates/json/map >> +++ b/mercurial/templates/json/map >> @@ -13,11 +13,16 @@ filerevision = '\{ >> "lines": [{join(text%lineentry, ", ")}] >> }' >> lineentry = '\{ >> "line": {line|json} >> }' >> -search = '"not yet implemented"' >> +search = '\{ >> + "node": {node|json}, >> + "query": {query|json}, >> + "entries": [{join(entries%searchentry, ", ")}] >> + }' >> +searchentry = '{changeset}' > It's better to use a template directly for clarity, since searchentry doesn't do anything on its own. If I directly write something like " "entries": [{join(entries%changelistentry, ", ")}] ", I got a json decoding error. I guess that is because the template is named "searchentry".
On Mon, 20 Jun 2016 10:49:13 +0200, Laura Médioni wrote: > On 06/16/2016 12:07 PM, Anton Shestakov wrote: > > 15.06.2016, 22:48, "Laura Médioni" <laura.medioni@logilab.fr>: > >> # HG changeset patch > >> # User Laura Médioni <laura.medioni@logilab.fr> > >> # Date 1465547502 -7200 > >> # Fri Jun 10 10:31:42 2016 +0200 > >> # Node ID 33c362973b2ab07b2e20d6818b7e72473e682fd4 > >> # Parent f4aad36209542e836d91477ce330b2dbb5181443 > >> templates: add support for search webcommand in json style > >> > >> diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map > >> --- a/mercurial/templates/json/map > >> +++ b/mercurial/templates/json/map > >> @@ -13,11 +13,16 @@ filerevision = '\{ > >> "lines": [{join(text%lineentry, ", ")}] > >> }' > >> lineentry = '\{ > >> "line": {line|json} > >> }' > >> -search = '"not yet implemented"' > >> +search = '\{ > >> + "node": {node|json}, > >> + "query": {query|json}, > >> + "entries": [{join(entries%searchentry, ", ")}] > >> + }' > >> +searchentry = '{changeset}' > > It's better to use a template directly for clarity, since searchentry doesn't do anything on its own. > > If I directly write something like " "entries": > [{join(entries%changelistentry, ", ")}] ", I got a json decoding error. > I guess that is because the template is named "searchentry". Yep, you can write it as 'entries % changeset' or 'entries % "{changeset}"', but still "searchentry" key is required.
20.06.2016, 21:25, "Yuya Nishihara" <yuya@tcha.org>: > On Mon, 20 Jun 2016 10:49:13 +0200, Laura Médioni wrote: >> On 06/16/2016 12:07 PM, Anton Shestakov wrote: >> > 15.06.2016, 22:48, "Laura Médioni" <laura.medioni@logilab.fr>: >> >> # HG changeset patch >> >> # User Laura Médioni <laura.medioni@logilab.fr> >> >> # Date 1465547502 -7200 >> >> # Fri Jun 10 10:31:42 2016 +0200 >> >> # Node ID 33c362973b2ab07b2e20d6818b7e72473e682fd4 >> >> # Parent f4aad36209542e836d91477ce330b2dbb5181443 >> >> templates: add support for search webcommand in json style >> >> >> >> diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map >> >> --- a/mercurial/templates/json/map >> >> +++ b/mercurial/templates/json/map >> >> @@ -13,11 +13,16 @@ filerevision = '\{ >> >> "lines": [{join(text%lineentry, ", ")}] >> >> }' >> >> lineentry = '\{ >> >> "line": {line|json} >> >> }' >> >> -search = '"not yet implemented"' >> >> +search = '\{ >> >> + "node": {node|json}, >> >> + "query": {query|json}, >> >> + "entries": [{join(entries%searchentry, ", ")}] >> >> + }' >> >> +searchentry = '{changeset}' >> > It's better to use a template directly for clarity, since searchentry doesn't do anything on its own. >> >> If I directly write something like " "entries": >> [{join(entries%changelistentry, ", ")}] ", I got a json decoding error. >> I guess that is because the template is named "searchentry". > > Yep, you can write it as 'entries % changeset' or 'entries % "{changeset}"', > but still "searchentry" key is required. Looks like it's because of a changelist function in hgweb/webcommands.py (line 280-ish). It does "yield tmpl('searchentry', ..." instead of just "yield {'key': 'value'}" like most of the generators in that file. This way it allows writing just "{entries}" instead of "{entries%searchentry}". A shortcut that sort of backfires now. I assume there is no easy way to not require "searchentry" template to exist and maintain compatibility with custom hgweb themes at the same time. So I guess "searchentry = '{changeset}'" is fine, all things considered.
On Mon, 20 Jun 2016 21:41:53 +0800, Anton Shestakov wrote: > 20.06.2016, 21:25, "Yuya Nishihara" <yuya@tcha.org>: > > On Mon, 20 Jun 2016 10:49:13 +0200, Laura Médioni wrote: > >> On 06/16/2016 12:07 PM, Anton Shestakov wrote: > >> > 15.06.2016, 22:48, "Laura Médioni" <laura.medioni@logilab.fr>: > >> >> # HG changeset patch > >> >> # User Laura Médioni <laura.medioni@logilab.fr> > >> >> # Date 1465547502 -7200 > >> >> # Fri Jun 10 10:31:42 2016 +0200 > >> >> # Node ID 33c362973b2ab07b2e20d6818b7e72473e682fd4 > >> >> # Parent f4aad36209542e836d91477ce330b2dbb5181443 > >> >> templates: add support for search webcommand in json style > >> >> > >> >> diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map > >> >> --- a/mercurial/templates/json/map > >> >> +++ b/mercurial/templates/json/map > >> >> @@ -13,11 +13,16 @@ filerevision = '\{ > >> >> "lines": [{join(text%lineentry, ", ")}] > >> >> }' > >> >> lineentry = '\{ > >> >> "line": {line|json} > >> >> }' > >> >> -search = '"not yet implemented"' > >> >> +search = '\{ > >> >> + "node": {node|json}, > >> >> + "query": {query|json}, > >> >> + "entries": [{join(entries%searchentry, ", ")}] > >> >> + }' > >> >> +searchentry = '{changeset}' > >> > It's better to use a template directly for clarity, since searchentry doesn't do anything on its own. > >> > >> If I directly write something like " "entries": > >> [{join(entries%changelistentry, ", ")}] ", I got a json decoding error. > >> I guess that is because the template is named "searchentry". > > > > Yep, you can write it as 'entries % changeset' or 'entries % "{changeset}"', > > but still "searchentry" key is required. > > Looks like it's because of a changelist function in hgweb/webcommands.py (line 280-ish). It does "yield tmpl('searchentry', ..." instead of just "yield {'key': 'value'}" like most of the generators in that file. This way it allows writing just "{entries}" instead of "{entries%searchentry}". A shortcut that sort of backfires now. > > I assume there is no easy way to not require "searchentry" template to exist and maintain compatibility with custom hgweb themes at the same time. templatekw._hybrid might help, but it wouldn't be easy task.
Patch
diff --git a/mercurial/templates/json/map b/mercurial/templates/json/map --- a/mercurial/templates/json/map +++ b/mercurial/templates/json/map @@ -13,11 +13,16 @@ filerevision = '\{ "lines": [{join(text%lineentry, ", ")}] }' lineentry = '\{ "line": {line|json} }' -search = '"not yet implemented"' +search = '\{ + "node": {node|json}, + "query": {query|json}, + "entries": [{join(entries%searchentry, ", ")}] + }' +searchentry = '{changeset}' # changelog and shortlog are the same web API but with different # number of entries. changelog = changelist.tmpl shortlog = changelist.tmpl changelistentry = '\{ 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 @@ -1019,10 +1019,80 @@ summary/ shows a summary of repository s "tag": "tag1" } ] } + $ request json-changelog?rev=create + 200 Script output follows + + { + "entries": [ + { + "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": "create tag", + "node": "93a8ce14f89156426b7fa981af8042da53f03aa0", + "parents": [ + "78896eb0e102174ce9278438a95e12543e4367a7" + ], + "phase": "public", + "tags": [ + "" + ], + "user": "test" + } + ], + "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7", + "query": "create" + } + filediff/{revision}/{path} shows changes to a file in a revision $ request json-diff/f8bbb9024b10/foo 200 Script output follows