comparison mercurial/hgweb/webcommands.py @ 35406:76dcdc4e707b

hgweb: filter graphmod.colored() output before iterating over it Consumers in this function use output of graphmod.colored(), but only want items with type == CHANGESET, so let's filter it early. This is primarily just a refactoring, but it also fixes a potential small bug with `rows = len(tree)` (this variable is used for "Rows shown" line in raw-graph) if there are items of other types.
author Anton Shestakov <av6@dwimlabs.net>
date Fri, 08 Dec 2017 21:50:11 +0800
parents b963750b125f
children 27ab3150cd50
comparison
equal deleted inserted replaced
35405:e66d6e938d2d 35406:76dcdc4e707b
1226 # We have to feed a baseset to dagwalker as it is expecting smartset 1226 # We have to feed a baseset to dagwalker as it is expecting smartset
1227 # object. This does not have a big impact on hgweb performance itself 1227 # object. This does not have a big impact on hgweb performance itself
1228 # since hgweb graphing code is not itself lazy yet. 1228 # since hgweb graphing code is not itself lazy yet.
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(graphmod.colored(dag, web.repo)) 1231 tree = list(item for item in graphmod.colored(dag, web.repo)
1232 if item[1] == graphmod.CHANGESET)
1232 1233
1233 def getcolumns(tree): 1234 def getcolumns(tree):
1234 cols = 0 1235 cols = 0
1235 for (id, type, ctx, vtx, edges) in tree: 1236 for (id, type, ctx, vtx, edges) in tree:
1236 if type != graphmod.CHANGESET:
1237 continue
1238 cols = max(cols, max([edge[0] for edge in edges] or [0]), 1237 cols = max(cols, max([edge[0] for edge in edges] or [0]),
1239 max([edge[1] for edge in edges] or [0])) 1238 max([edge[1] for edge in edges] or [0]))
1240 return cols 1239 return cols
1241 1240
1242 def graphdata(usetuples): 1241 def graphdata(usetuples):
1243 data = [] 1242 data = []
1244 1243
1245 row = 0 1244 row = 0
1246 for (id, type, ctx, vtx, edges) in tree: 1245 for (id, type, ctx, vtx, edges) in tree:
1247 if type != graphmod.CHANGESET:
1248 continue
1249
1250 if usetuples: 1246 if usetuples:
1251 node = pycompat.bytestr(ctx) 1247 node = pycompat.bytestr(ctx)
1252 data.append({'node': node, 'vertex': vtx, 'edges': edges}) 1248 data.append({'node': node, 'vertex': vtx, 'edges': edges})
1253 else: 1249 else:
1254 entry = webutil.commonentry(web.repo, ctx) 1250 entry = webutil.commonentry(web.repo, ctx)