# HG changeset patch # User Anton Shestakov # Date 1512971278 -28800 # Node ID a48af4993aa06fb58ecf1b21eb69978e9efef299 # Parent 27ab3150cd50fe78f6346bb70df58338ea0ba84b 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. diff -r 27ab3150cd50 -r a48af4993aa0 mercurial/hgweb/webcommands.py --- 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):