comparison mercurial/hgweb/webcommands.py @ 35096:23bba755cf80

hgweb: use webutil.commonentry() for nodes (but not for jsdata yet) in /graph This makes graphdata() simpler by using existing code that gets common changeset properties for showing in hgweb. graphdata() is a nested function in graph() that prepares entries for /graph view, but there are two different lists of changesets prepared: "jsdata" for JavaScript-rendered graph and "nodes" for everything else. For "jsdata", properties "node", "user", "age" and "desc" are passed through various template filters because we don't have these filters in JavaScript, so the data has to be prepared server-side. But now that commonentry() is used for producing "nodes" list (and it doesn't apply any filters), these filters need to be added to the appropriate templates (only raw at this moment, everything else either doesn't implement graph or uses JavaScript). This is a bit of refactoring that will hopefully simplify future patches. The end result is to have /graph that only renders the actual graph with nodes and vertices in JavaScript, and the rest is done server-side. This way server-side code can focus on showing a list of changesets, which is easy because we already have /log, /shortlog, etc, and JavaScript code can be simplified, making it easier to add obsolescence graph and other features.
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 20 Nov 2017 21:59:00 +0800
parents 4bc74bc78efd
children d61f2a3d5e53
comparison
equal deleted inserted replaced
35095:4bc74bc78efd 35096:23bba755cf80
1239 continue 1239 continue
1240 cols = max(cols, max([edge[0] for edge in edges] or [0]), 1240 cols = max(cols, max([edge[0] for edge in edges] or [0]),
1241 max([edge[1] for edge in edges] or [0])) 1241 max([edge[1] for edge in edges] or [0]))
1242 return cols 1242 return cols
1243 1243
1244 def graphdata(usetuples, encodestr): 1244 def graphdata(usetuples):
1245 # {jsdata} will be passed to |json, so it must be in utf-8
1246 encodestr = encoding.fromlocal
1245 data = [] 1247 data = []
1246 1248
1247 row = 0 1249 row = 0
1248 for (id, type, ctx, vtx, edges) in tree: 1250 for (id, type, ctx, vtx, edges) in tree:
1249 if type != graphmod.CHANGESET: 1251 if type != graphmod.CHANGESET:
1250 continue 1252 continue
1251 node = pycompat.bytestr(ctx)
1252 age = encodestr(templatefilters.age(ctx.date()))
1253 desc = templatefilters.firstline(encodestr(ctx.description()))
1254 desc = url.escape(templatefilters.nonempty(desc))
1255 user = url.escape(templatefilters.person(encodestr(ctx.user())))
1256 branch = url.escape(encodestr(ctx.branch()))
1257 try:
1258 branchnode = web.repo.branchtip(ctx.branch())
1259 except error.RepoLookupError:
1260 branchnode = None
1261 branch = branch, branchnode == ctx.node()
1262 1253
1263 if usetuples: 1254 if usetuples:
1255 node = pycompat.bytestr(ctx)
1256 age = encodestr(templatefilters.age(ctx.date()))
1257 desc = templatefilters.firstline(encodestr(ctx.description()))
1258 desc = url.escape(templatefilters.nonempty(desc))
1259 user = templatefilters.person(encodestr(ctx.user()))
1260 user = url.escape(user)
1261 branch = url.escape(encodestr(ctx.branch()))
1262 try:
1263 branchnode = web.repo.branchtip(ctx.branch())
1264 except error.RepoLookupError:
1265 branchnode = None
1266 branch = branch, branchnode == ctx.node()
1267
1264 data.append((node, vtx, edges, desc, user, age, branch, 1268 data.append((node, vtx, edges, desc, user, age, branch,
1265 [url.escape(encodestr(x)) for x in ctx.tags()], 1269 [url.escape(encodestr(x)) for x in ctx.tags()],
1266 [url.escape(encodestr(x)) 1270 [url.escape(encodestr(x))
1267 for x in ctx.bookmarks()])) 1271 for x in ctx.bookmarks()]))
1268 else: 1272 else:
1273 entry = webutil.commonentry(web.repo, ctx)
1269 edgedata = [{'col': edge[0], 'nextcol': edge[1], 1274 edgedata = [{'col': edge[0], 'nextcol': edge[1],
1270 'color': (edge[2] - 1) % 6 + 1, 1275 'color': (edge[2] - 1) % 6 + 1,
1271 'width': edge[3], 'bcolor': edge[4]} 1276 'width': edge[3], 'bcolor': edge[4]}
1272 for edge in edges] 1277 for edge in edges]
1273 1278
1274 data.append( 1279 entry.update(
1275 {'node': node, 1280 {'col': vtx[0],
1276 'col': vtx[0],
1277 'color': (vtx[1] - 1) % 6 + 1, 1281 'color': (vtx[1] - 1) % 6 + 1,
1278 'edges': edgedata, 1282 'edges': edgedata,
1279 'row': row, 1283 'row': row,
1280 'nextrow': row + 1, 1284 'nextrow': row + 1})
1281 'desc': desc, 1285
1282 'user': user, 1286 data.append(entry)
1283 'age': age,
1284 'bookmarks': webutil.nodebookmarksdict(
1285 web.repo, ctx.node()),
1286 'branches': webutil.nodebranchdict(web.repo, ctx),
1287 'inbranch': webutil.nodeinbranch(web.repo, ctx),
1288 'tags': webutil.nodetagsdict(web.repo, ctx.node())})
1289 1287
1290 row += 1 1288 row += 1
1291 1289
1292 return data 1290 return data
1293 1291
1300 lessvars=lessvars, morevars=morevars, downrev=downrev, 1298 lessvars=lessvars, morevars=morevars, downrev=downrev,
1301 cols=cols, rows=rows, 1299 cols=cols, rows=rows,
1302 canvaswidth=(cols + 1) * bg_height, 1300 canvaswidth=(cols + 1) * bg_height,
1303 truecanvasheight=rows * bg_height, 1301 truecanvasheight=rows * bg_height,
1304 canvasheight=canvasheight, bg_height=bg_height, 1302 canvasheight=canvasheight, bg_height=bg_height,
1305 # {jsdata} will be passed to |json, so it must be in utf-8 1303 jsdata=lambda **x: graphdata(True),
1306 jsdata=lambda **x: graphdata(True, encoding.fromlocal), 1304 nodes=lambda **x: graphdata(False),
1307 nodes=lambda **x: graphdata(False, pycompat.bytestr),
1308 node=ctx.hex(), changenav=changenav) 1305 node=ctx.hex(), changenav=changenav)
1309 1306
1310 def _getdoc(e): 1307 def _getdoc(e):
1311 doc = e[0].__doc__ 1308 doc = e[0].__doc__
1312 if doc: 1309 if doc: