churn: sort users with same churn by name
authorMads Kiilerich <mads@kiilerich.com>
Wed, 12 Dec 2012 02:38:14 +0100
changeset 18369 2150e70c0ee1
parent 18368 de685145f5c2
child 18370 c605e12dd622
churn: sort users with same churn by name This makes the output order well-defined and improves code readability.
hgext/churn.py
tests/test-churn.t
--- a/hgext/churn.py	Wed Dec 12 02:38:14 2012 +0100
+++ b/hgext/churn.py	Wed Dec 12 02:38:14 2012 +0100
@@ -144,8 +144,10 @@
     if not rate:
         return
 
-    sortkey = ((not opts.get('sort')) and (lambda x: -sum(x[1])) or None)
-    rate.sort(key=sortkey)
+    if opts.get('sort'):
+        rate.sort()
+    else:
+        rate.sort(key=lambda x: (-sum(x[1]), x))
 
     # Be careful not to have a zero maxcount (issue833)
     maxcount = float(max(sum(v) for k, v in rate)) or 1.0
--- a/tests/test-churn.t	Wed Dec 12 02:38:14 2012 +0100
+++ b/tests/test-churn.t	Wed Dec 12 02:38:14 2012 +0100
@@ -37,16 +37,16 @@
 churn all
 
   $ hg churn
+  user1      3 ***************************************************************
   user3      3 ***************************************************************
-  user1      3 ***************************************************************
   user2      2 ******************************************
 
 churn excluding one dir
 
   $ hg churn -X e
   user3      3 ***************************************************************
+  user1      2 ******************************************
   user2      2 ******************************************
-  user1      2 ******************************************
 
 churn up to rev 2
 
@@ -68,16 +68,16 @@
   $ mv ../aliases .hgchurn
   $ hg churn
   skipping malformed alias: not-an-alias
+  alias1      3 **************************************************************
   alias3      3 **************************************************************
-  alias1      3 **************************************************************
   user2       2 *****************************************
   $ rm .hgchurn
 
 churn with column specifier
 
   $ COLUMNS=40 hg churn
+  user1      3 ***********************
   user3      3 ***********************
-  user1      3 ***********************
   user2      2 ***************
 
 churn by hour
@@ -155,8 +155,8 @@
   $ hg churn -c
   user1            4 *********************************************************
   user3            3 *******************************************
+  user2            2 *****************************
   user4@x.com      2 *****************************
-  user2            2 *****************************
   with space       1 **************
 
   $ cd ..