Mercurial > hg
changeset 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 | fc0f3ed071fc |
files | mercurial/hgweb/webcommands.py mercurial/templates/raw/graphnode.tmpl |
diffstat | 2 files changed, 28 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py Mon Nov 20 21:47:11 2017 +0800 +++ b/mercurial/hgweb/webcommands.py Mon Nov 20 21:59:00 2017 +0800 @@ -1241,51 +1241,49 @@ max([edge[1] for edge in edges] or [0])) return cols - def graphdata(usetuples, encodestr): + def graphdata(usetuples): + # {jsdata} will be passed to |json, so it must be in utf-8 + encodestr = encoding.fromlocal data = [] row = 0 for (id, type, ctx, vtx, edges) in tree: if type != graphmod.CHANGESET: continue - node = pycompat.bytestr(ctx) - age = encodestr(templatefilters.age(ctx.date())) - desc = templatefilters.firstline(encodestr(ctx.description())) - desc = url.escape(templatefilters.nonempty(desc)) - user = url.escape(templatefilters.person(encodestr(ctx.user()))) - branch = url.escape(encodestr(ctx.branch())) - try: - branchnode = web.repo.branchtip(ctx.branch()) - except error.RepoLookupError: - branchnode = None - branch = branch, branchnode == ctx.node() if usetuples: + node = pycompat.bytestr(ctx) + age = encodestr(templatefilters.age(ctx.date())) + desc = templatefilters.firstline(encodestr(ctx.description())) + desc = url.escape(templatefilters.nonempty(desc)) + user = templatefilters.person(encodestr(ctx.user())) + user = url.escape(user) + branch = url.escape(encodestr(ctx.branch())) + try: + branchnode = web.repo.branchtip(ctx.branch()) + except error.RepoLookupError: + branchnode = None + branch = branch, branchnode == ctx.node() + data.append((node, vtx, edges, desc, user, age, branch, [url.escape(encodestr(x)) for x in ctx.tags()], [url.escape(encodestr(x)) for x in ctx.bookmarks()])) 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] - data.append( - {'node': node, - 'col': vtx[0], + entry.update( + {'col': vtx[0], 'color': (vtx[1] - 1) % 6 + 1, 'edges': edgedata, 'row': row, - 'nextrow': row + 1, - 'desc': desc, - 'user': user, - 'age': age, - 'bookmarks': webutil.nodebookmarksdict( - web.repo, ctx.node()), - 'branches': webutil.nodebranchdict(web.repo, ctx), - 'inbranch': webutil.nodeinbranch(web.repo, ctx), - 'tags': webutil.nodetagsdict(web.repo, ctx.node())}) + 'nextrow': row + 1}) + + data.append(entry) row += 1 @@ -1302,9 +1300,8 @@ canvaswidth=(cols + 1) * bg_height, truecanvasheight=rows * bg_height, canvasheight=canvasheight, bg_height=bg_height, - # {jsdata} will be passed to |json, so it must be in utf-8 - jsdata=lambda **x: graphdata(True, encoding.fromlocal), - nodes=lambda **x: graphdata(False, pycompat.bytestr), + jsdata=lambda **x: graphdata(True), + nodes=lambda **x: graphdata(False), node=ctx.hex(), changenav=changenav) def _getdoc(e):
--- a/mercurial/templates/raw/graphnode.tmpl Mon Nov 20 21:47:11 2017 +0800 +++ b/mercurial/templates/raw/graphnode.tmpl Mon Nov 20 21:59:00 2017 +0800 @@ -1,7 +1,7 @@ -changeset: {node} -user: {user} -date: {age} -summary: {desc} +changeset: {node|short} +user: {author|person} +date: {date|age} +summary: {desc|firstline|nonempty} {branches%branchname}{tags%tagname}{bookmarks%bookmarkname} node: ({col}, {row}) (color {color}) {edges%graphedge}