# HG changeset patch # User Mads Kiilerich # Date 2012-12-12 01:38:14 # Node ID 2150e70c0ee10676751c0da4da9ebb426a6944ac # Parent de685145f5c26eb84bd9850031e3b5793eb156bb 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 @@ def churn(ui, repo, *pats, **opts): 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 separate directories 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 @@ churn with .hgchurn $ 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 @@ Ignore trailing or leading spaces in ema $ hg churn -c user1 4 ********************************************************* user3 3 ******************************************* + user2 2 ***************************** user4@x.com 2 ***************************** - user2 2 ***************************** with space 1 ************** $ cd ..