Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/webcommands.py @ 35408: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 |
comparison
equal
deleted
inserted
replaced
35407:27ab3150cd50 | 35408:a48af4993aa0 |
---|---|
1229 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) | 1229 dag = graphmod.dagwalker(web.repo, smartset.baseset(revs)) |
1230 # As we said one line above... not lazy. | 1230 # As we said one line above... not lazy. |
1231 tree = list(item for item in graphmod.colored(dag, web.repo) | 1231 tree = list(item for item in graphmod.colored(dag, web.repo) |
1232 if item[1] == graphmod.CHANGESET) | 1232 if item[1] == graphmod.CHANGESET) |
1233 | 1233 |
1234 def graphdata(usetuples): | 1234 def jsdata(): |
1235 data = [] | 1235 return [{'node': pycompat.bytestr(ctx), |
1236 | 1236 'vertex': vtx, |
1237 row = 0 | 1237 'edges': edges} |
1238 for (id, type, ctx, vtx, edges) in tree: | 1238 for (id, type, ctx, vtx, edges) in tree] |
1239 if usetuples: | 1239 |
1240 node = pycompat.bytestr(ctx) | 1240 def nodes(): |
1241 data.append({'node': node, 'vertex': vtx, 'edges': edges}) | 1241 for row, (id, type, ctx, vtx, edges) in enumerate(tree): |
1242 else: | 1242 entry = webutil.commonentry(web.repo, ctx) |
1243 entry = webutil.commonentry(web.repo, ctx) | 1243 edgedata = [{'col': edge[0], |
1244 edgedata = [{'col': edge[0], 'nextcol': edge[1], | 1244 'nextcol': edge[1], |
1245 'color': (edge[2] - 1) % 6 + 1, | 1245 'color': (edge[2] - 1) % 6 + 1, |
1246 'width': edge[3], 'bcolor': edge[4]} | 1246 'width': edge[3], |
1247 for edge in edges] | 1247 'bcolor': edge[4]} |
1248 | 1248 for edge in edges] |
1249 entry.update( | 1249 |
1250 {'col': vtx[0], | 1250 entry.update({'col': vtx[0], |
1251 'color': (vtx[1] - 1) % 6 + 1, | 1251 'color': (vtx[1] - 1) % 6 + 1, |
1252 'edges': edgedata, | 1252 'edges': edgedata, |
1253 'row': row, | 1253 'row': row, |
1254 'nextrow': row + 1}) | 1254 'nextrow': row + 1}) |
1255 | 1255 |
1256 data.append(entry) | 1256 yield entry |
1257 | |
1258 row += 1 | |
1259 | |
1260 return data | |
1261 | 1257 |
1262 rows = len(tree) | 1258 rows = len(tree) |
1263 | 1259 |
1264 return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount, | 1260 return tmpl('graph', rev=rev, symrev=symrev, revcount=revcount, |
1265 uprev=uprev, | 1261 uprev=uprev, |
1266 lessvars=lessvars, morevars=morevars, downrev=downrev, | 1262 lessvars=lessvars, morevars=morevars, downrev=downrev, |
1267 rows=rows, | 1263 rows=rows, |
1268 bg_height=bg_height, | 1264 bg_height=bg_height, |
1269 changesets=count, | 1265 changesets=count, |
1270 jsdata=lambda **x: graphdata(True), | 1266 jsdata=lambda **x: jsdata(), |
1271 nodes=lambda **x: graphdata(False), | 1267 nodes=lambda **x: nodes(), |
1272 node=ctx.hex(), changenav=changenav) | 1268 node=ctx.hex(), changenav=changenav) |
1273 | 1269 |
1274 def _getdoc(e): | 1270 def _getdoc(e): |
1275 doc = e[0].__doc__ | 1271 doc = e[0].__doc__ |
1276 if doc: | 1272 if doc: |