Details
Details
- Reviewers
yuja - Group Reviewers
hg-reviewers - Commits
- rHG26ed66ab1e72: py3: handle keyword arguments in hgext/churn.py
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
yuja |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
import os | import os | ||||
import time | import time | ||||
from mercurial.i18n import _ | from mercurial.i18n import _ | ||||
from mercurial import ( | from mercurial import ( | ||||
cmdutil, | cmdutil, | ||||
encoding, | encoding, | ||||
patch, | patch, | ||||
pycompat, | |||||
registrar, | registrar, | ||||
scmutil, | scmutil, | ||||
util, | util, | ||||
) | ) | ||||
cmdtable = {} | cmdtable = {} | ||||
command = registrar.command(cmdtable) | command = registrar.command(cmdtable) | ||||
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | ||||
if l.startswith("+") and not l.startswith("+++ "): | if l.startswith("+") and not l.startswith("+++ "): | ||||
added += 1 | added += 1 | ||||
elif l.startswith("-") and not l.startswith("--- "): | elif l.startswith("-") and not l.startswith("--- "): | ||||
removed += 1 | removed += 1 | ||||
return (added, removed) | return (added, removed) | ||||
def countrate(ui, repo, amap, *pats, **opts): | def countrate(ui, repo, amap, *pats, **opts): | ||||
"""Calculate stats""" | """Calculate stats""" | ||||
opts = pycompat.byteskwargs(opts) | |||||
if opts.get('dateformat'): | if opts.get('dateformat'): | ||||
def getkey(ctx): | def getkey(ctx): | ||||
t, tz = ctx.date() | t, tz = ctx.date() | ||||
date = datetime.datetime(*time.gmtime(float(t) - tz)[:6]) | date = datetime.datetime(*time.gmtime(float(t) - tz)[:6]) | ||||
return date.strftime(opts['dateformat']) | return date.strftime(opts['dateformat']) | ||||
else: | else: | ||||
tmpl = opts.get('oldtemplate') or opts.get('template') | tmpl = opts.get('oldtemplate') or opts.get('template') | ||||
tmpl = cmdutil.makelogtemplater(ui, repo, tmpl) | tmpl = cmdutil.makelogtemplater(ui, repo, tmpl) | ||||
Such a file may be specified with the --aliases option, otherwise | Such a file may be specified with the --aliases option, otherwise | ||||
a .hgchurn file will be looked for in the working directory root. | a .hgchurn file will be looked for in the working directory root. | ||||
Aliases will be split from the rightmost "=". | Aliases will be split from the rightmost "=". | ||||
''' | ''' | ||||
def pad(s, l): | def pad(s, l): | ||||
return s + " " * (l - encoding.colwidth(s)) | return s + " " * (l - encoding.colwidth(s)) | ||||
amap = {} | amap = {} | ||||
aliases = opts.get('aliases') | aliases = opts.get(r'aliases') | ||||
if not aliases and os.path.exists(repo.wjoin('.hgchurn')): | if not aliases and os.path.exists(repo.wjoin('.hgchurn')): | ||||
aliases = repo.wjoin('.hgchurn') | aliases = repo.wjoin('.hgchurn') | ||||
if aliases: | if aliases: | ||||
for l in open(aliases, "r"): | for l in open(aliases, "r"): | ||||
try: | try: | ||||
alias, actual = l.rsplit('=' in l and '=' or None, 1) | alias, actual = l.rsplit('=' in l and '=' or None, 1) | ||||
amap[alias.strip()] = actual.strip() | amap[alias.strip()] = actual.strip() | ||||
except ValueError: | except ValueError: | ||||
l = l.strip() | l = l.strip() | ||||
if l: | if l: | ||||
ui.warn(_("skipping malformed alias: %s\n") % l) | ui.warn(_("skipping malformed alias: %s\n") % l) | ||||
continue | continue | ||||
rate = countrate(ui, repo, amap, *pats, **opts).items() | rate = countrate(ui, repo, amap, *pats, **opts).items() | ||||
if not rate: | if not rate: | ||||
return | return | ||||
if opts.get('sort'): | if opts.get(r'sort'): | ||||
rate.sort() | rate.sort() | ||||
else: | else: | ||||
rate.sort(key=lambda x: (-sum(x[1]), x)) | rate.sort(key=lambda x: (-sum(x[1]), x)) | ||||
# Be careful not to have a zero maxcount (issue833) | # Be careful not to have a zero maxcount (issue833) | ||||
maxcount = float(max(sum(v) for k, v in rate)) or 1.0 | maxcount = float(max(sum(v) for k, v in rate)) or 1.0 | ||||
maxname = max(len(k) for k, v in rate) | maxname = max(len(k) for k, v in rate) | ||||
ttywidth = ui.termwidth() | ttywidth = ui.termwidth() | ||||
ui.debug("assuming %i character terminal\n" % ttywidth) | ui.debug("assuming %i character terminal\n" % ttywidth) | ||||
width = ttywidth - maxname - 2 - 2 - 2 | width = ttywidth - maxname - 2 - 2 - 2 | ||||
if opts.get('diffstat'): | if opts.get(r'diffstat'): | ||||
width -= 15 | width -= 15 | ||||
def format(name, diffstat): | def format(name, diffstat): | ||||
added, removed = diffstat | added, removed = diffstat | ||||
return "%s %15s %s%s\n" % (pad(name, maxname), | return "%s %15s %s%s\n" % (pad(name, maxname), | ||||
'+%d/-%d' % (added, removed), | '+%d/-%d' % (added, removed), | ||||
ui.label('+' * charnum(added), | ui.label('+' * charnum(added), | ||||
'diffstat.inserted'), | 'diffstat.inserted'), | ||||
ui.label('-' * charnum(removed), | ui.label('-' * charnum(removed), |