[PATCH 2 of 2] graph: in hgrc specify line color for main branch

Constantine Linnick theaspect at gmail.com
Tue Feb 7 19:11:23 UTC 2012


# HG changeset patch
# User Constantine Linnick <theaspect at gmail.com>
# Date 1327236423 -25200
# Node ID 1cd5ca16bf9a503d547a4c63b082410729091ace
# Parent  984234adafdb65d0e4c138a44c74121243f58eb5
graph: in hgrc specify line color for main branch

You can specify color to visually distinguish main branch (trunk)
on hgweb's graph page. If color specified, all branch heads will share
same color. Settings format is branch_name.color = value, where color
is six hexadecimal digits e.g.:
[graph]
default.color = FF0000

diff -r 984234adafdb -r 1cd5ca16bf9a mercurial/graphmod.py
--- a/mercurial/graphmod.py	Sun Jan 22 19:35:26 2012 +0700
+++ b/mercurial/graphmod.py	Sun Jan 22 19:47:03 2012 +0700
@@ -93,7 +93,8 @@
         gdict = config.setdefault(branch, {})
 
         # Validation
-        if (setting == "width" and val.isdigit() and 0 < int(val) < 30):
+        if ((setting == "width" and val.isdigit() and 0 < int(val) < 30) or
+                (setting == "color" and re.match('[0-9a-fA-F]{1,2}', val))):
             gdict[setting] = val
         else:
             continue
diff -r 984234adafdb -r 1cd5ca16bf9a mercurial/help/config.txt
--- a/mercurial/help/config.txt	Sun Jan 22 19:35:26 2012 +0700
+++ b/mercurial/help/config.txt	Sun Jan 22 19:47:03 2012 +0700
@@ -537,7 +537,7 @@
 ``graph``
 """""""""
 
-This section specifies line width to visually distinguish 
+This section specifies line width and color to visually distinguish 
 "main branch" or trunk in central repository graph.
 
 Format branch_name.attribute = value.
@@ -546,12 +546,17 @@
   [graph]
   # 2px width
   default.width = 2
+  # red color
+  default.color = FF0000
 
 Supported arguments:
 
 ``width``
   Set width in px. Width is number 0-99.
 
+``color``
+  Color is six hexadecimal digits RRGGBB.
+
 Known issues:
   If line style doesn't change, try to clear browser cache.
 
diff -r 984234adafdb -r 1cd5ca16bf9a mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Sun Jan 22 19:35:26 2012 +0700
+++ b/mercurial/templates/static/mercurial.js	Sun Jan 22 19:47:03 2012 +0700
@@ -58,19 +58,25 @@
 		
 		// Set the colour.
 		//
-		// Picks a distinct colour based on an internal wheel; the bg
+		// If color is hex string "FFFFFF" then append sharp and apply as is 
+		// If color is number
+		// picks a distinct colour based on an internal wheel; the bg
 		// parameter provides the value that should be assigned to the 'zero'
 		// colours and the fg parameter provides the multiplier that should be
 		// applied to the foreground colours.
-		
-		color %= colors.length;
-		var red = (colors[color][0] * fg) || bg;
-		var green = (colors[color][1] * fg) || bg;
-		var blue = (colors[color][2] * fg) || bg;
-		red = Math.round(red * 255);
-		green = Math.round(green * 255);
-		blue = Math.round(blue * 255);
-		var s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
+		var s;
+		if(typeof color == "string"){
+			s = "#"+color;
+		}else{ //typeof color == "number"
+			color %= colors.length;
+			var red = (colors[color][0] * fg) || bg;
+			var green = (colors[color][1] * fg) || bg;
+			var blue = (colors[color][2] * fg) || bg;
+			red = Math.round(red * 255);
+			green = Math.round(green * 255);
+			blue = Math.round(blue * 255);
+			s = 'rgb(' + red + ', ' + green + ', ' + blue + ')';
+		}
 		this.ctx.strokeStyle = s;
 		this.ctx.fillStyle = s;
 		return s;
@@ -116,6 +122,10 @@
 				if(line[3] && line[3]['width']){
 					this.ctx.lineWidth = line[3]['width'];
 				}
+				// Color if exists
+				if(line[3] && line[3]['color']){
+					color = line[3]['color'];
+				}
 				this.edge(x0, y0, x1, y1, color);
 				this.ctx.lineWidth = 1;
 			}
diff -r 984234adafdb -r 1cd5ca16bf9a tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t	Sun Jan 22 19:35:26 2012 +0700
+++ b/tests/test-hgweb-commands.t	Sun Jan 22 19:47:03 2012 +0700
@@ -31,6 +31,7 @@
   $ echo [graph] >> .hg/hgrc
   $ echo default.width = 3 >> .hg/hgrc
   $ echo stable.width = 3 >> .hg/hgrc
+  $ echo stable.color = FF0000 >> .hg/hgrc
   $ hg serve --config server.uncompressed=False -n test -p $HGPORT -d --pid-file=hg.pid -E errors.log
   $ cat hg.pid >> $DAEMON_PIDS
 
@@ -956,7 +957,7 @@
   <script>
   <!-- hide script content
   
-  var data = [["ba87b23d29ca", [0, 1], [[0, 0, 1, {"width": "3"}]], "branch", "test", "1970-01-01", ["unstable", true], ["tip"], ["something"]], ["1d22e65f027e", [0, 1], [[0, 0, 1, {"width": "3"}]], "branch", "test", "1970-01-01", ["stable", true], [], []], ["a4f92ed23982", [0, 1], [[0, 0, 1, {"width": "3"}]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], [], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"], ["anotherthing"]]];
+  var data = [["ba87b23d29ca", [0, 1], [[0, 0, 1, {"color": "FF0000", "width": "3"}]], "branch", "test", "1970-01-01", ["unstable", true], ["tip"], ["something"]], ["1d22e65f027e", [0, 1], [[0, 0, 1, {"width": "3"}]], "branch", "test", "1970-01-01", ["stable", true], [], []], ["a4f92ed23982", [0, 1], [[0, 0, 1, {"width": "3"}]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], [], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"], ["anotherthing"]]];
   var graph = new Graph();
   graph.scale(39);
   
@@ -1223,9 +1224,8 @@
 
   $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT '/graph/' \
   >     | grep '^var data ='
-  var data = [["548001d11f45", [0, 1], [[0, 0, 1, null]], "\u80fd", "test", "1970-01-01", ["unstable", true], ["tip"], ["something"]], ["ba87b23d29ca", [0, 1], [[0, 0, 1, {"width": "3"}]], "branch", "test", "1970-01-01", ["unstable", false], [], []], ["1d22e65f027e", [0, 1], [[0, 0, 1, {"width": "3"}]], "branch", "test", "1970-01-01", ["stable", true], [], []], ["a4f92ed23982", [0, 1], [[0, 0, 1, {"width": "3"}]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], [], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"], ["anotherthing"]]];
+  var data = [["548001d11f45", [0, 1], [[0, 0, 1, null]], "\u80fd", "test", "1970-01-01", ["unstable", true], ["tip"], ["something"]], ["ba87b23d29ca", [0, 1], [[0, 0, 1, {"color": "FF0000", "width": "3"}]], "branch", "test", "1970-01-01", ["unstable", false], [], []], ["1d22e65f027e", [0, 1], [[0, 0, 1, {"width": "3"}]], "branch", "test", "1970-01-01", ["stable", true], [], []], ["a4f92ed23982", [0, 1], [[0, 0, 1, {"width": "3"}]], "Added tag 1.0 for changeset 2ef0ac749a14", "test", "1970-01-01", ["default", true], [], []], ["2ef0ac749a14", [0, 1], [], "base", "test", "1970-01-01", ["default", false], ["1.0"], ["anotherthing"]]];
 
 ERRORS ENCOUNTERED
 
   $ cat errors.log
-



More information about the Mercurial-devel mailing list