comparison hgext/churn.py @ 18369:2150e70c0ee1

churn: sort users with same churn by name This makes the output order well-defined and improves code readability.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 12 Dec 2012 02:38:14 +0100
parents 434e5bd615fc
children 68f7129af6a8
comparison
equal deleted inserted replaced
18368:de685145f5c2 18369:2150e70c0ee1
142 142
143 rate = countrate(ui, repo, amap, *pats, **opts).items() 143 rate = countrate(ui, repo, amap, *pats, **opts).items()
144 if not rate: 144 if not rate:
145 return 145 return
146 146
147 sortkey = ((not opts.get('sort')) and (lambda x: -sum(x[1])) or None) 147 if opts.get('sort'):
148 rate.sort(key=sortkey) 148 rate.sort()
149 else:
150 rate.sort(key=lambda x: (-sum(x[1]), x))
149 151
150 # Be careful not to have a zero maxcount (issue833) 152 # Be careful not to have a zero maxcount (issue833)
151 maxcount = float(max(sum(v) for k, v in rate)) or 1.0 153 maxcount = float(max(sum(v) for k, v in rate)) or 1.0
152 maxname = max(len(k) for k, v in rate) 154 maxname = max(len(k) for k, v in rate)
153 155