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

Constantine Linnick theaspect at gmail.com
Thu Feb 2 08:17:44 CST 2012


# HG changeset patch
# User Constantine Linnick <theaspect at gmail.com>
# Date 1327236423 -25200
# Node ID fa225c5025fb43cbd7b5d82c814edf84bedaa6c2
# Parent  537733973603cb4f974f01aecd51923da17e314f
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 537733973603 -r fa225c5025fb 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, dict())
 
         # Validation
-        if ((setting not in ('width',)) or
+        if ((setting not in ('color', 'width')) or
+                (setting == 'color' and not re.match('[a-fA-F0-9]{6}', val)) or
                 (setting == "width" and not re.match('[0-9]{1,2}', val))):
             continue
 
diff -r 537733973603 -r fa225c5025fb 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 537733973603 -r fa225c5025fb 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 537733973603 -r fa225c5025fb 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