# HG changeset patch # User Paul Boddie # Date 1337531954 -7200 # Node ID 38afdf6585ee819fb5f3a82821067f60fb76d637 # Parent a6e6bafe0e00b19b969f37bd33a81fe5ac68c2b7 Changed the name of the variable providing node data. Added a new version of the patch to hgweb. diff -r a6e6bafe0e00 -r 38afdf6585ee patches/patch-hgweb-graph-data.diff --- a/patches/patch-hgweb-graph-data.diff Sun Apr 29 20:57:36 2012 +0200 +++ b/patches/patch-hgweb-graph-data.diff Sun May 20 18:39:14 2012 +0200 @@ -1,86 +1,116 @@ -diff -r 55982f62651f mercurial/hgweb/webcommands.py ---- a/mercurial/hgweb/webcommands.py Wed Apr 18 01:20:16 2012 +0300 -+++ b/mercurial/hgweb/webcommands.py Sun Apr 29 20:56:26 2012 +0200 -@@ -785,6 +785,8 @@ +# HG changeset patch +# User Paul Boddie +# Date 1337531723 -7200 +# Node ID 9488fd4c05876377ad4e3b2ca4c60713d20bf917 +# Parent d7c9976b930e1fdbf8608a65462cd124977c7d53 +hgweb: make graph data suitable for template usage + +Previously, graph data has been encoded for processing done by +JavaScript code run in the browser, employing simple structures +with implicit member positions. This patch modifies the graph +command to also produce data employing a dictionary-based +structure suitable for use with the templating mechanism, thus +permitting other ways of presenting repository graphs using that +mechanism. + +In order to test these changes, the raw theme has been modified +to include templates for graph nodes and edges. In a similar +fashion, themes could employ technologies such as SVG that lend +themselves to templating to produce the graph display. This patch +makes use of a much simpler output representation than SVG in +order to maintain clarity. + +diff -r d7c9976b930e -r 9488fd4c0587 mercurial/hgweb/webcommands.py +--- a/mercurial/hgweb/webcommands.py Wed May 02 13:20:06 2012 +0200 ++++ b/mercurial/hgweb/webcommands.py Sun May 20 18:35:23 2012 +0200 +@@ -783,24 +783,69 @@ + + dag = graphmod.dagwalker(web.repo, range(startrev, downrev - 1, -1)) tree = list(graphmod.colored(dag, web.repo)) - canvasheight = (len(tree) + 1) * bg_height - 27 - data = [] -+ cols = 0 -+ row = 0 - for (id, type, ctx, vtx, edges) in tree: - if type != graphmod.CHANGESET: - continue -@@ -795,13 +797,38 @@ - user = cgi.escape(templatefilters.person(ctx.user())) - branch = ctx.branch() - branch = branch, web.repo.branchtags().get(branch) == ctx.node() +- canvasheight = (len(tree) + 1) * bg_height - 27 +- data = [] +- for (id, type, ctx, vtx, edges) in tree: +- if type != graphmod.CHANGESET: +- continue +- node = str(ctx) +- age = templatefilters.age(ctx.date()) +- desc = templatefilters.firstline(ctx.description()) +- desc = cgi.escape(templatefilters.nonempty(desc)) +- user = cgi.escape(templatefilters.person(ctx.user())) +- branch = ctx.branch() +- branch = branch, web.repo.branchtags().get(branch) == ctx.node() - data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(), - ctx.bookmarks())) + -+ edgedata = [dict(col=edge[0], nextcol=edge[1], -+ color=(edge[2] - 1) % 6 + 1, -+ width=edge[3], bcolor=edge[4]) for edge in edges] ++ def getcolumns(tree): ++ cols = 0 ++ for (id, type, ctx, vtx, edges) in tree: ++ if type != graphmod.CHANGESET: ++ continue ++ cols = max(cols, max([edge[0] for edge in edges] or [0]), ++ max([edge[1] for edge in edges] or [0])) ++ return cols ++ ++ def graphdata(usetuples, **map): ++ data = [] ++ ++ row = 0 ++ for (id, type, ctx, vtx, edges) in tree: ++ if type != graphmod.CHANGESET: ++ continue ++ node = str(ctx) ++ age = templatefilters.age(ctx.date()) ++ desc = templatefilters.firstline(ctx.description()) ++ desc = cgi.escape(templatefilters.nonempty(desc)) ++ user = cgi.escape(templatefilters.person(ctx.user())) ++ branch = ctx.branch() ++ branch = branch, web.repo.branchtags().get(branch) == ctx.node() + -+ data.append(dict(node=node, -+ 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()), -+ # convenience values for the canvas graph -+ branchname=branch[0], -+ branchtip=branch[1])) ++ if usetuples: ++ data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(), ++ ctx.bookmarks())) ++ else: ++ edgedata = [dict(col=edge[0], nextcol=edge[1], ++ color=(edge[2] - 1) % 6 + 1, ++ width=edge[3], bcolor=edge[4]) for edge in edges] + -+ cols = max(cols, max([edge[0] for edge in edges] or [0]), -+ max([edge[1] for edge in edges] or [0])) -+ row += 1 ++ data.append(dict(node=node, ++ 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()))) ++ ++ row += 1 ++ ++ return data ++ ++ cols = getcolumns(tree) ++ rows = len(tree) ++ canvasheight = (rows + 1) * bg_height - 27 return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, lessvars=lessvars, morevars=morevars, downrev=downrev, - canvasheight=canvasheight, jsdata=data, bg_height=bg_height, -- node=revnode_hex, changenav=changenav) -+ node=revnode_hex, changenav=changenav, -+ rows=row, cols=cols, canvaswidth=(cols+1)*bg_height, -+ truecanvasheight=row*bg_height) +- canvasheight=canvasheight, jsdata=data, bg_height=bg_height, ++ cols=cols, rows=rows, ++ canvaswidth=(cols+1)*bg_height, ++ truecanvasheight=rows*bg_height, ++ canvasheight=canvasheight, bg_height=bg_height, ++ jsdata=lambda **x: graphdata(True, **x), ++ nodes=lambda **x: graphdata(False, **x), + node=revnode_hex, changenav=changenav) def _getdoc(e): - doc = e[0].__doc__ -diff -r 55982f62651f mercurial/templates/raw/graph.tmpl ---- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/mercurial/templates/raw/graph.tmpl Sun Apr 29 20:56:26 2012 +0200 -@@ -0,0 +1,6 @@ -+{header} -+# HG graph -+# Node ID {node} -+# Rows shown {rows} -+ -+{jsdata%graphnode} -diff -r 55982f62651f mercurial/templates/raw/graphedge.tmpl ---- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/mercurial/templates/raw/graphedge.tmpl Sun Apr 29 20:56:26 2012 +0200 -@@ -0,0 +1,1 @@ -+edge: ({col}, {row}) -> ({nextcol}, {nextrow}) (color {color}) -diff -r 55982f62651f mercurial/templates/raw/graphnode.tmpl ---- /dev/null Thu Jan 01 00:00:00 1970 +0000 -+++ b/mercurial/templates/raw/graphnode.tmpl Sun Apr 29 20:56:26 2012 +0200 -@@ -0,0 +1,7 @@ -+changeset: {node} -+user: {user} -+date: {age} -+summary: {desc} -+{branches%branchname}{tags%tagname}{bookmarks%bookmarkname} -+node: ({col}, {row}) (color {color}) -+{edges%graphedge} -diff -r 55982f62651f mercurial/templates/raw/map ---- a/mercurial/templates/raw/map Wed Apr 18 01:20:16 2012 +0300 -+++ b/mercurial/templates/raw/map Sun Apr 29 20:56:26 2012 +0200 +diff -r d7c9976b930e -r 9488fd4c0587 mercurial/templates/raw/map +--- a/mercurial/templates/raw/map Wed May 02 13:20:06 2012 +0200 ++++ b/mercurial/templates/raw/map Sun May 20 18:35:23 2012 +0200 @@ -28,3 +28,9 @@ bookmarkentry = '{bookmark} {node}\n' branches = '{entries%branchentry}' @@ -91,95 +121,13 @@ +bookmarkname = 'bookmark: {name}\n' +branchname = 'branch: {name}\n' +tagname = 'tag: {name}\n' -diff -r 55982f62651f mercurial/templates/static/mercurial.js ---- a/mercurial/templates/static/mercurial.js Wed Apr 18 01:20:16 2012 +0300 -+++ b/mercurial/templates/static/mercurial.js Sun Apr 29 20:56:26 2012 +0200 -@@ -108,21 +108,22 @@ - this.bg[1] += this.bg_height; - - var cur = data[i]; -- var node = cur[1]; -- var edges = cur[2]; -+ var column = cur["col"]; -+ var color; -+ var edges = cur["edges"]; - var fold = false; - - var prevWidth = this.ctx.lineWidth; - for (var j in edges) { - - line = edges[j]; -- start = line[0]; -- end = line[1]; -- color = line[2]; -- var width = line[3]; -+ start = line["col"]; -+ end = line["nextcol"]; -+ color = line["color"]; -+ var width = line["width"]; - if(width < 0) - width = prevWidth; -- var branchcolor = line[4]; -+ var branchcolor = line["bcolor"]; - if(branchcolor) - color = branchcolor; - -@@ -146,13 +147,12 @@ - - // Draw the revision node in the right column - -- column = node[0] -- color = node[1] -+ color = cur["color"]; - - radius = this.box_size / 8; - x = this.cell[0] + this.box_size * column + this.box_size / 2; - y = this.bg[1] - this.bg_height / 2; -- var add = this.vertex(x, y, color, parity, cur); -+ var add = this.vertexForEntry(x, y, color, parity, cur); - backgrounds += add[0]; - nodedata += add[1]; - -@@ -165,6 +165,21 @@ - - } - -+ this.vertexForEntry = function(x, y, color, parity, cur) { -+ var tags = [], bookmarks = []; -+ for (var i in cur["tags"]) { -+ tags.push(cur["tags"][i]["name"]); -+ } -+ for (var i in cur["bookmarks"]) { -+ bookmarks.push(cur["bookmarks"][i]["name"]); -+ } -+ return this.vertex(x, y, color, parity, [ -+ cur["node"], [cur["col"], cur["color"]], -+ cur["edges"], cur["desc"], cur["user"], cur["age"], -+ [cur["branchname"], cur["branchtip"]], -+ tags, bookmarks -+ ]) -+ } - } - - -diff -r 55982f62651f tests/test-hgweb-commands.t ---- a/tests/test-hgweb-commands.t Wed Apr 18 01:20:16 2012 +0300 -+++ b/tests/test-hgweb-commands.t Sun Apr 29 20:56:26 2012 +0200 -@@ -957,7 +957,7 @@ -