paul@56 | 1 | # HG changeset patch |
paul@56 | 2 | # User Paul Boddie <paul@boddie.org.uk> |
paul@56 | 3 | # Date 1337531723 -7200 |
paul@56 | 4 | # Node ID 9488fd4c05876377ad4e3b2ca4c60713d20bf917 |
paul@56 | 5 | # Parent d7c9976b930e1fdbf8608a65462cd124977c7d53 |
paul@56 | 6 | hgweb: make graph data suitable for template usage |
paul@56 | 7 | |
paul@56 | 8 | Previously, graph data has been encoded for processing done by |
paul@56 | 9 | JavaScript code run in the browser, employing simple structures |
paul@56 | 10 | with implicit member positions. This patch modifies the graph |
paul@56 | 11 | command to also produce data employing a dictionary-based |
paul@56 | 12 | structure suitable for use with the templating mechanism, thus |
paul@56 | 13 | permitting other ways of presenting repository graphs using that |
paul@56 | 14 | mechanism. |
paul@56 | 15 | |
paul@56 | 16 | In order to test these changes, the raw theme has been modified |
paul@56 | 17 | to include templates for graph nodes and edges. In a similar |
paul@56 | 18 | fashion, themes could employ technologies such as SVG that lend |
paul@56 | 19 | themselves to templating to produce the graph display. This patch |
paul@56 | 20 | makes use of a much simpler output representation than SVG in |
paul@56 | 21 | order to maintain clarity. |
paul@56 | 22 | |
paul@56 | 23 | diff -r d7c9976b930e -r 9488fd4c0587 mercurial/hgweb/webcommands.py |
paul@56 | 24 | --- a/mercurial/hgweb/webcommands.py Wed May 02 13:20:06 2012 +0200 |
paul@56 | 25 | +++ b/mercurial/hgweb/webcommands.py Sun May 20 18:35:23 2012 +0200 |
paul@56 | 26 | @@ -783,24 +783,69 @@ |
paul@56 | 27 | |
paul@56 | 28 | dag = graphmod.dagwalker(web.repo, range(startrev, downrev - 1, -1)) |
paul@52 | 29 | tree = list(graphmod.colored(dag, web.repo)) |
paul@56 | 30 | - canvasheight = (len(tree) + 1) * bg_height - 27 |
paul@56 | 31 | - data = [] |
paul@56 | 32 | - for (id, type, ctx, vtx, edges) in tree: |
paul@56 | 33 | - if type != graphmod.CHANGESET: |
paul@56 | 34 | - continue |
paul@56 | 35 | - node = str(ctx) |
paul@56 | 36 | - age = templatefilters.age(ctx.date()) |
paul@56 | 37 | - desc = templatefilters.firstline(ctx.description()) |
paul@56 | 38 | - desc = cgi.escape(templatefilters.nonempty(desc)) |
paul@56 | 39 | - user = cgi.escape(templatefilters.person(ctx.user())) |
paul@56 | 40 | - branch = ctx.branch() |
paul@56 | 41 | - branch = branch, web.repo.branchtags().get(branch) == ctx.node() |
paul@52 | 42 | - data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(), |
paul@52 | 43 | - ctx.bookmarks())) |
paul@52 | 44 | + |
paul@56 | 45 | + def getcolumns(tree): |
paul@56 | 46 | + cols = 0 |
paul@56 | 47 | + for (id, type, ctx, vtx, edges) in tree: |
paul@56 | 48 | + if type != graphmod.CHANGESET: |
paul@56 | 49 | + continue |
paul@56 | 50 | + cols = max(cols, max([edge[0] for edge in edges] or [0]), |
paul@56 | 51 | + max([edge[1] for edge in edges] or [0])) |
paul@56 | 52 | + return cols |
paul@56 | 53 | + |
paul@56 | 54 | + def graphdata(usetuples, **map): |
paul@56 | 55 | + data = [] |
paul@56 | 56 | + |
paul@56 | 57 | + row = 0 |
paul@56 | 58 | + for (id, type, ctx, vtx, edges) in tree: |
paul@56 | 59 | + if type != graphmod.CHANGESET: |
paul@56 | 60 | + continue |
paul@56 | 61 | + node = str(ctx) |
paul@56 | 62 | + age = templatefilters.age(ctx.date()) |
paul@56 | 63 | + desc = templatefilters.firstline(ctx.description()) |
paul@56 | 64 | + desc = cgi.escape(templatefilters.nonempty(desc)) |
paul@56 | 65 | + user = cgi.escape(templatefilters.person(ctx.user())) |
paul@56 | 66 | + branch = ctx.branch() |
paul@56 | 67 | + branch = branch, web.repo.branchtags().get(branch) == ctx.node() |
paul@52 | 68 | + |
paul@56 | 69 | + if usetuples: |
paul@56 | 70 | + data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(), |
paul@56 | 71 | + ctx.bookmarks())) |
paul@56 | 72 | + else: |
paul@56 | 73 | + edgedata = [dict(col=edge[0], nextcol=edge[1], |
paul@56 | 74 | + color=(edge[2] - 1) % 6 + 1, |
paul@56 | 75 | + width=edge[3], bcolor=edge[4]) for edge in edges] |
paul@52 | 76 | + |
paul@56 | 77 | + data.append(dict(node=node, |
paul@56 | 78 | + col=vtx[0], |
paul@56 | 79 | + color=(vtx[1] - 1) % 6 + 1, |
paul@56 | 80 | + edges=edgedata, |
paul@56 | 81 | + row=row, |
paul@56 | 82 | + nextrow=row+1, |
paul@56 | 83 | + desc=desc, |
paul@56 | 84 | + user=user, |
paul@56 | 85 | + age=age, |
paul@56 | 86 | + bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()), |
paul@56 | 87 | + branches=webutil.nodebranchdict(web.repo, ctx), |
paul@56 | 88 | + inbranch=webutil.nodeinbranch(web.repo, ctx), |
paul@56 | 89 | + tags=webutil.nodetagsdict(web.repo, ctx.node()))) |
paul@56 | 90 | + |
paul@56 | 91 | + row += 1 |
paul@56 | 92 | + |
paul@56 | 93 | + return data |
paul@56 | 94 | + |
paul@56 | 95 | + cols = getcolumns(tree) |
paul@56 | 96 | + rows = len(tree) |
paul@56 | 97 | + canvasheight = (rows + 1) * bg_height - 27 |
paul@52 | 98 | |
paul@52 | 99 | return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, |
paul@52 | 100 | lessvars=lessvars, morevars=morevars, downrev=downrev, |
paul@56 | 101 | - canvasheight=canvasheight, jsdata=data, bg_height=bg_height, |
paul@56 | 102 | + cols=cols, rows=rows, |
paul@56 | 103 | + canvaswidth=(cols+1)*bg_height, |
paul@56 | 104 | + truecanvasheight=rows*bg_height, |
paul@56 | 105 | + canvasheight=canvasheight, bg_height=bg_height, |
paul@56 | 106 | + jsdata=lambda **x: graphdata(True, **x), |
paul@56 | 107 | + nodes=lambda **x: graphdata(False, **x), |
paul@56 | 108 | node=revnode_hex, changenav=changenav) |
paul@52 | 109 | |
paul@52 | 110 | def _getdoc(e): |
paul@56 | 111 | diff -r d7c9976b930e -r 9488fd4c0587 mercurial/templates/raw/map |
paul@56 | 112 | --- a/mercurial/templates/raw/map Wed May 02 13:20:06 2012 +0200 |
paul@56 | 113 | +++ b/mercurial/templates/raw/map Sun May 20 18:35:23 2012 +0200 |
paul@55 | 114 | @@ -28,3 +28,9 @@ |
paul@55 | 115 | bookmarkentry = '{bookmark} {node}\n' |
paul@55 | 116 | branches = '{entries%branchentry}' |
paul@55 | 117 | branchentry = '{branch} {node} {status}\n' |
paul@55 | 118 | +graph = graph.tmpl |
paul@55 | 119 | +graphnode = graphnode.tmpl |
paul@55 | 120 | +graphedge = graphedge.tmpl |
paul@55 | 121 | +bookmarkname = 'bookmark: {name}\n' |
paul@55 | 122 | +branchname = 'branch: {name}\n' |
paul@55 | 123 | +tagname = 'tag: {name}\n' |
paul@56 | 124 | diff -r d7c9976b930e -r 9488fd4c0587 tests/test-hgweb-commands.t |
paul@56 | 125 | --- a/tests/test-hgweb-commands.t Wed May 02 13:20:06 2012 +0200 |
paul@56 | 126 | +++ b/tests/test-hgweb-commands.t Sun May 20 18:35:23 2012 +0200 |
paul@56 | 127 | @@ -1038,6 +1038,55 @@ |
paul@55 | 128 | </body> |
paul@55 | 129 | </html> |
paul@56 | 130 | |
paul@55 | 131 | +raw graph |
paul@55 | 132 | + |
paul@55 | 133 | + $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/graph/?style=raw' |
paul@55 | 134 | + 200 Script output follows |
paul@55 | 135 | + |
paul@55 | 136 | + |
paul@55 | 137 | + # HG graph |
paul@55 | 138 | + # Node ID ba87b23d29ca67a305625d81a20ac279c1e3f444 |
paul@55 | 139 | + # Rows shown 4 |
paul@55 | 140 | + |
paul@55 | 141 | + changeset: ba87b23d29ca |
paul@55 | 142 | + user: test |
paul@55 | 143 | + date: 1970-01-01 |
paul@55 | 144 | + summary: branch |
paul@55 | 145 | + branch: unstable |
paul@55 | 146 | + tag: tip |
paul@55 | 147 | + bookmark: something |
paul@55 | 148 | + |
paul@55 | 149 | + node: (0, 0) (color 1) |
paul@55 | 150 | + edge: (0, 0) -> (0, 1) (color 1) |
paul@55 | 151 | + |
paul@55 | 152 | + changeset: 1d22e65f027e |
paul@55 | 153 | + user: test |
paul@55 | 154 | + date: 1970-01-01 |
paul@55 | 155 | + summary: branch |
paul@55 | 156 | + branch: stable |
paul@55 | 157 | + |
paul@55 | 158 | + node: (0, 1) (color 1) |
paul@55 | 159 | + edge: (0, 1) -> (0, 2) (color 1) |
paul@55 | 160 | + |
paul@55 | 161 | + changeset: a4f92ed23982 |
paul@55 | 162 | + user: test |
paul@55 | 163 | + date: 1970-01-01 |
paul@55 | 164 | + summary: Added tag 1.0 for changeset 2ef0ac749a14 |
paul@55 | 165 | + branch: default |
paul@55 | 166 | + |
paul@55 | 167 | + node: (0, 2) (color 1) |
paul@55 | 168 | + edge: (0, 2) -> (0, 3) (color 1) |
paul@55 | 169 | + |
paul@55 | 170 | + changeset: 2ef0ac749a14 |
paul@55 | 171 | + user: test |
paul@55 | 172 | + date: 1970-01-01 |
paul@55 | 173 | + summary: base |
paul@55 | 174 | + tag: 1.0 |
paul@55 | 175 | + bookmark: anotherthing |
paul@55 | 176 | + |
paul@55 | 177 | + node: (0, 3) (color 1) |
paul@55 | 178 | + |
paul@56 | 179 | + |
paul@54 | 180 | |
paul@54 | 181 | capabilities |
paul@54 | 182 | |