MercurialWebTheme

patches/patch-hgweb-graph-data.diff

53:d50e96b62aa4
2012-04-28 Paul Boddie Fixed the patch for empty repository graphs.
     1 diff -r 55982f62651f mercurial/hgweb/webcommands.py     2 --- a/mercurial/hgweb/webcommands.py	Wed Apr 18 01:20:16 2012 +0300     3 +++ b/mercurial/hgweb/webcommands.py	Sat Apr 28 01:19:59 2012 +0200     4 @@ -785,6 +785,8 @@     5      tree = list(graphmod.colored(dag, web.repo))     6      canvasheight = (len(tree) + 1) * bg_height - 27     7      data = []     8 +    cols = 0     9 +    row = 0    10      for (id, type, ctx, vtx, edges) in tree:    11          if type != graphmod.CHANGESET:    12              continue    13 @@ -795,13 +797,38 @@    14          user = cgi.escape(templatefilters.person(ctx.user()))    15          branch = ctx.branch()    16          branch = branch, web.repo.branchtags().get(branch) == ctx.node()    17 -        data.append((node, vtx, edges, desc, user, age, branch, ctx.tags(),    18 -                     ctx.bookmarks()))    19 +    20 +        edgedata = [dict(col=edge[0], nextcol=edge[1],    21 +                         color=(edge[2] - 1) % 6 + 1,    22 +                         width=edge[3], bcolor=edge[4]) for edge in edges]    23 +    24 +        data.append(dict(node=node,    25 +                         col=vtx[0],    26 +                         color=(vtx[1] - 1) % 6 + 1,    27 +                         edges=edgedata,    28 +                         row=row,    29 +                         nextrow=row+1,    30 +                         bg_height=bg_height,    31 +                         desc=desc,    32 +                         user=user,    33 +                         age=age,    34 +                         branchname=branch[0],    35 +                         branchtip=branch[1],    36 +                         bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()),    37 +                         branches=webutil.nodebranchdict(web.repo, ctx),    38 +                         inbranch=webutil.nodeinbranch(web.repo, ctx),    39 +                         tags=webutil.nodetagsdict(web.repo, ctx.node())))    40 +    41 +        cols = max(cols, max([edge[0] for edge in edges] or [0]),    42 +                         max([edge[1] for edge in edges] or [0]))    43 +        row += 1    44      45      return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev,    46                  lessvars=lessvars, morevars=morevars, downrev=downrev,    47                  canvasheight=canvasheight, jsdata=data, bg_height=bg_height,    48 -                node=revnode_hex, changenav=changenav)    49 +                node=revnode_hex, changenav=changenav,    50 +                rows=row, cols=cols, canvaswidth=(cols+1)*bg_height,    51 +                truecanvasheight=row*bg_height)    52      53  def _getdoc(e):    54      doc = e[0].__doc__    55 diff -r 55982f62651f mercurial/templates/static/mercurial.js    56 --- a/mercurial/templates/static/mercurial.js	Wed Apr 18 01:20:16 2012 +0300    57 +++ b/mercurial/templates/static/mercurial.js	Sat Apr 28 01:19:59 2012 +0200    58 @@ -108,21 +108,22 @@    59  			this.bg[1] += this.bg_height;    60  			    61  			var cur = data[i];    62 -			var node = cur[1];    63 -			var edges = cur[2];    64 +			var column = cur["col"];    65 +			var color;    66 +			var edges = cur["edges"];    67  			var fold = false;    68  			    69  			var prevWidth = this.ctx.lineWidth;    70  			for (var j in edges) {    71  				    72  				line = edges[j];    73 -				start = line[0];    74 -				end = line[1];    75 -				color = line[2];    76 -				var width = line[3];    77 +				start = line["col"];    78 +				end = line["nextcol"];    79 +				color = line["color"];    80 +				var width = line["width"];    81  				if(width < 0)    82  					 width = prevWidth;    83 -				var branchcolor = line[4];    84 +				var branchcolor = line["bcolor"];    85  				if(branchcolor)    86  					color = branchcolor;    87  				    88 @@ -146,13 +147,12 @@    89  			    90  			// Draw the revision node in the right column    91  			    92 -			column = node[0]    93 -			color = node[1]    94 +			color = cur["color"];    95  			    96  			radius = this.box_size / 8;    97  			x = this.cell[0] + this.box_size * column + this.box_size / 2;    98  			y = this.bg[1] - this.bg_height / 2;    99 -			var add = this.vertex(x, y, color, parity, cur);   100 +			var add = this.vertexForEntry(x, y, color, parity, cur);   101  			backgrounds += add[0];   102  			nodedata += add[1];   103  			   104 @@ -165,6 +165,21 @@   105  		   106  	}   107     108 +	this.vertexForEntry = function(x, y, color, parity, cur) {   109 +		var tags = [], bookmarks = [];   110 +		for (var i in cur["tags"]) {   111 +			tags.push(cur["tags"][i]["name"]);   112 +		}   113 +		for (var i in cur["bookmarks"]) {   114 +			bookmarks.push(cur["bookmarks"][i]["name"]);   115 +		}   116 +		return this.vertex(x, y, color, parity, [   117 +			cur["node"], [cur["col"], cur["color"]],   118 +			cur["edges"], cur["desc"], cur["user"], cur["age"],   119 +			[cur["branchname"], cur["branchtip"]],   120 +			tags, bookmarks   121 +			])   122 +	}   123  }   124     125