Patchwork [1,of,4,V2] hgweb: eliminate extra complexity in process_dates definition

login
register
mail settings
Submitter Alexander Plavin
Date Sept. 29, 2013, 5:15 p.m.
Message ID <ef97e7b67fe60c99181d.1380474933@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2662/
State Accepted
Headers show

Comments

Alexander Plavin - Sept. 29, 2013, 5:15 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1378459858 -14400
#      Fri Sep 06 13:30:58 2013 +0400
# Node ID ef97e7b67fe60c99181dc9153a15451077ece88d
# Parent  8c01d533c6f20a0883c22a14b324c90cde9efdaf
hgweb: eliminate extra complexity in process_dates definition

There was an extra anonymous outer function, called immediately. It is removed
in this patch.
Augie Fackler - Sept. 30, 2013, 7:42 p.m.
On Sun, Sep 29, 2013 at 09:15:33PM +0400, Alexander Plavin wrote:
> # HG changeset patch
> # User Alexander Plavin <alexander@plav.in>
> # Date 1378459858 -14400
> #      Fri Sep 06 13:30:58 2013 +0400
> # Node ID ef97e7b67fe60c99181dc9153a15451077ece88d
> # Parent  8c01d533c6f20a0883c22a14b324c90cde9efdaf
> hgweb: eliminate extra complexity in process_dates definition

Queueing this one because it's within my ability to comprehend js. Not
sure about 2 of N, so I'm going to stop reviewing the series here.

>
> There was an extra anonymous outer function, called immediately. It is removed
> in this patch.
>
> diff -r 8c01d533c6f2 -r ef97e7b67fe6 mercurial/templates/static/mercurial.js
> --- a/mercurial/templates/static/mercurial.js	Sun Sep 22 14:19:57 2013 +0400
> +++ b/mercurial/templates/static/mercurial.js	Fri Sep 06 13:30:58 2013 +0400
> @@ -176,7 +176,7 @@
>  }
>
>
> -process_dates = (function(document, RegExp, Math, isNaN, Date, _false, _true){
> +function process_dates(){
>
>       // derived from code from mercurial/templatefilter.py
>
> @@ -227,9 +227,9 @@
>
>               var delta = Math.floor((now.getTime() - once.getTime()) / 1000);
>
> -		var future = _false;
> +		var future = false;
>               if (delta < 0){
> -			future = _true;
> +			future = true;
>                       delta = -delta;
>                       if (delta > (30 * scales.year)){
>                               return "in the distant future";
> @@ -253,26 +253,24 @@
>               }
>       }
>
> -	return function(){
> -		var nodes = document.getElementsByTagName('*');
> -		var ageclass = new RegExp('\\bage\\b');
> -		var dateclass = new RegExp('\\bdate\\b');
> -		for (var i=0; i<nodes.length; ++i){
> -			var node = nodes[i];
> -			var classes = node.className;
> -			if (ageclass.test(classes)){
> -				var agevalue = age(node.textContent);
> -				if (dateclass.test(classes)){
> -					// We want both: date + (age)
> -					node.textContent += ' ('+agevalue+')';
> -				} else {
> -					node.title = node.textContent;
> -					node.textContent = agevalue;
> -				}
> +	var nodes = document.getElementsByTagName('*');
> +	var ageclass = new RegExp('\\bage\\b');
> +	var dateclass = new RegExp('\\bdate\\b');
> +	for (var i=0; i<nodes.length; ++i){
> +		var node = nodes[i];
> +		var classes = node.className;
> +		if (ageclass.test(classes)){
> +			var agevalue = age(node.textContent);
> +			if (dateclass.test(classes)){
> +				// We want both: date + (age)
> +				node.textContent += ' ('+agevalue+')';
> +			} else {
> +				node.title = node.textContent;
> +				node.textContent = agevalue;
>                       }
>               }
>       }
> -})(document, RegExp, Math, isNaN, Date, false, true)
> +}
>
>  function toggleDiffstat() {
>      var curdetails = document.getElementById('diffstatdetails').style.display;
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Laurens Holst - Oct. 1, 2013, 9:45 a.m.
Op 30-09-13 21:42, Augie Fackler schreef:
> On Sun, Sep 29, 2013 at 09:15:33PM +0400, Alexander Plavin wrote:
>> # HG changeset patch
>> # User Alexander Plavin <alexander@plav.in>
>> # Date 1378459858 -14400
>> #      Fri Sep 06 13:30:58 2013 +0400
>> # Node ID ef97e7b67fe60c99181dc9153a15451077ece88d
>> # Parent  8c01d533c6f20a0883c22a14b324c90cde9efdaf
>> hgweb: eliminate extra complexity in process_dates definition
> Queueing this one because it's within my ability to comprehend js. Not
> sure about 2 of N, so I'm going to stop reviewing the series here.

The rest LGTM.

~Laurens

Patch

diff -r 8c01d533c6f2 -r ef97e7b67fe6 mercurial/templates/static/mercurial.js
--- a/mercurial/templates/static/mercurial.js	Sun Sep 22 14:19:57 2013 +0400
+++ b/mercurial/templates/static/mercurial.js	Fri Sep 06 13:30:58 2013 +0400
@@ -176,7 +176,7 @@ 
 }
 
 
-process_dates = (function(document, RegExp, Math, isNaN, Date, _false, _true){
+function process_dates(){
 
 	// derived from code from mercurial/templatefilter.py
 
@@ -227,9 +227,9 @@ 
 
 		var delta = Math.floor((now.getTime() - once.getTime()) / 1000);
 
-		var future = _false;
+		var future = false;
 		if (delta < 0){
-			future = _true;
+			future = true;
 			delta = -delta;
 			if (delta > (30 * scales.year)){
 				return "in the distant future";
@@ -253,26 +253,24 @@ 
 		}
 	}
 
-	return function(){
-		var nodes = document.getElementsByTagName('*');
-		var ageclass = new RegExp('\\bage\\b');
-		var dateclass = new RegExp('\\bdate\\b');
-		for (var i=0; i<nodes.length; ++i){
-			var node = nodes[i];
-			var classes = node.className;
-			if (ageclass.test(classes)){
-				var agevalue = age(node.textContent);
-				if (dateclass.test(classes)){
-					// We want both: date + (age)
-					node.textContent += ' ('+agevalue+')';
-				} else {
-					node.title = node.textContent;
-					node.textContent = agevalue;
-				}
+	var nodes = document.getElementsByTagName('*');
+	var ageclass = new RegExp('\\bage\\b');
+	var dateclass = new RegExp('\\bdate\\b');
+	for (var i=0; i<nodes.length; ++i){
+		var node = nodes[i];
+		var classes = node.className;
+		if (ageclass.test(classes)){
+			var agevalue = age(node.textContent);
+			if (dateclass.test(classes)){
+				// We want both: date + (age)
+				node.textContent += ' ('+agevalue+')';
+			} else {
+				node.title = node.textContent;
+				node.textContent = agevalue;
 			}
 		}
 	}
-})(document, RegExp, Math, isNaN, Date, false, true)
+}
 
 function toggleDiffstat() {
     var curdetails = document.getElementById('diffstatdetails').style.display;