[PATCH 17 of 24] churn: sort users with same churn by name

Mads Kiilerich mads at kiilerich.com
Sun Dec 16 16:34:12 CST 2012


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1355276294 -3600
# Node ID bf6de588da8525999fe4ed9d9e813eb6ce5ea9b5
# Parent  998b984fd3463b81c38370e003602f0b16a887d5
churn: sort users with same churn by name

This makes the output order well-defined and improves code readability.

diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -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
diff --git a/tests/test-churn.t b/tests/test-churn.t
--- a/tests/test-churn.t
+++ b/tests/test-churn.t
@@ -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 at x.com      2 *****************************
-  user2            2 *****************************
   with space       1 **************
 
   $ cd ..


More information about the Mercurial-devel mailing list