comparison hgext/churn.py @ 34974:26ed66ab1e72

py3: handle keyword arguments in hgext/churn.py Differential Revision: https://phab.mercurial-scm.org/D1299
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 23 Oct 2017 00:01:16 +0530
parents 50586a0a946f
children c8e2d6ed1f9e
comparison
equal deleted inserted replaced
34973:11a372d80496 34974:26ed66ab1e72
17 from mercurial.i18n import _ 17 from mercurial.i18n import _
18 from mercurial import ( 18 from mercurial import (
19 cmdutil, 19 cmdutil,
20 encoding, 20 encoding,
21 patch, 21 patch,
22 pycompat,
22 registrar, 23 registrar,
23 scmutil, 24 scmutil,
24 util, 25 util,
25 ) 26 )
26 27
43 removed += 1 44 removed += 1
44 return (added, removed) 45 return (added, removed)
45 46
46 def countrate(ui, repo, amap, *pats, **opts): 47 def countrate(ui, repo, amap, *pats, **opts):
47 """Calculate stats""" 48 """Calculate stats"""
49 opts = pycompat.byteskwargs(opts)
48 if opts.get('dateformat'): 50 if opts.get('dateformat'):
49 def getkey(ctx): 51 def getkey(ctx):
50 t, tz = ctx.date() 52 t, tz = ctx.date()
51 date = datetime.datetime(*time.gmtime(float(t) - tz)[:6]) 53 date = datetime.datetime(*time.gmtime(float(t) - tz)[:6])
52 return date.strftime(opts['dateformat']) 54 return date.strftime(opts['dateformat'])
152 ''' 154 '''
153 def pad(s, l): 155 def pad(s, l):
154 return s + " " * (l - encoding.colwidth(s)) 156 return s + " " * (l - encoding.colwidth(s))
155 157
156 amap = {} 158 amap = {}
157 aliases = opts.get('aliases') 159 aliases = opts.get(r'aliases')
158 if not aliases and os.path.exists(repo.wjoin('.hgchurn')): 160 if not aliases and os.path.exists(repo.wjoin('.hgchurn')):
159 aliases = repo.wjoin('.hgchurn') 161 aliases = repo.wjoin('.hgchurn')
160 if aliases: 162 if aliases:
161 for l in open(aliases, "r"): 163 for l in open(aliases, "r"):
162 try: 164 try:
170 172
171 rate = countrate(ui, repo, amap, *pats, **opts).items() 173 rate = countrate(ui, repo, amap, *pats, **opts).items()
172 if not rate: 174 if not rate:
173 return 175 return
174 176
175 if opts.get('sort'): 177 if opts.get(r'sort'):
176 rate.sort() 178 rate.sort()
177 else: 179 else:
178 rate.sort(key=lambda x: (-sum(x[1]), x)) 180 rate.sort(key=lambda x: (-sum(x[1]), x))
179 181
180 # Be careful not to have a zero maxcount (issue833) 182 # Be careful not to have a zero maxcount (issue833)
183 185
184 ttywidth = ui.termwidth() 186 ttywidth = ui.termwidth()
185 ui.debug("assuming %i character terminal\n" % ttywidth) 187 ui.debug("assuming %i character terminal\n" % ttywidth)
186 width = ttywidth - maxname - 2 - 2 - 2 188 width = ttywidth - maxname - 2 - 2 - 2
187 189
188 if opts.get('diffstat'): 190 if opts.get(r'diffstat'):
189 width -= 15 191 width -= 15
190 def format(name, diffstat): 192 def format(name, diffstat):
191 added, removed = diffstat 193 added, removed = diffstat
192 return "%s %15s %s%s\n" % (pad(name, maxname), 194 return "%s %15s %s%s\n" % (pad(name, maxname),
193 '+%d/-%d' % (added, removed), 195 '+%d/-%d' % (added, removed),