Mercurial > hg-stable
changeset 35415:a48af4993aa0
hgweb: split graphdata() into jsdata() and nodes()
nodes keyword passed to the template can be any iterator, but jsdata needs to
be a list because it gets JSONified.
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Mon, 11 Dec 2017 13:47:58 +0800 |
parents | 27ab3150cd50 |
children | f84b01257e06 |
files | mercurial/hgweb/webcommands.py |
diffstat | 1 files changed, 22 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py Sun Dec 10 15:56:22 2017 +0800 +++ b/mercurial/hgweb/webcommands.py Mon Dec 11 13:47:58 2017 +0800 @@ -1231,33 +1231,29 @@ tree = list(item for item in graphmod.colored(dag, web.repo) if item[1] == graphmod.CHANGESET) - def graphdata(usetuples): - data = [] + def jsdata(): + return [{'node': pycompat.bytestr(ctx), + 'vertex': vtx, + 'edges': edges} + for (id, type, ctx, vtx, edges) in tree] - row = 0 - for (id, type, ctx, vtx, edges) in tree: - if usetuples: - node = pycompat.bytestr(ctx) - data.append({'node': node, 'vertex': vtx, 'edges': edges}) - else: - entry = webutil.commonentry(web.repo, ctx) - edgedata = [{'col': edge[0], 'nextcol': edge[1], - 'color': (edge[2] - 1) % 6 + 1, - 'width': edge[3], 'bcolor': edge[4]} - for edge in edges] + def nodes(): + for row, (id, type, ctx, vtx, edges) in enumerate(tree): + entry = webutil.commonentry(web.repo, ctx) + edgedata = [{'col': edge[0], + 'nextcol': edge[1], + 'color': (edge[2] - 1) % 6 + 1, + 'width': edge[3], + 'bcolor': edge[4]} + for edge in edges] - entry.update( - {'col': vtx[0], - 'color': (vtx[1] - 1) % 6 + 1, - 'edges': edgedata, - 'row': row, - 'nextrow': row + 1}) + entry.update({'col': vtx[0], + 'color': (vtx[1] - 1) % 6 + 1, + 'edges': edgedata, + 'row': row, + 'nextrow': row + 1}) - data.append(entry) - - row += 1 - - return data + yield entry rows = len(tree) @@ -1267,8 +1263,8 @@ rows=rows, bg_height=bg_height, changesets=count, - jsdata=lambda **x: graphdata(True), - nodes=lambda **x: graphdata(False), + jsdata=lambda **x: jsdata(), + nodes=lambda **x: nodes(), node=ctx.hex(), changenav=changenav) def _getdoc(e):