Mercurial > public > mercurial-scm > hg
diff hgext/churn.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | eef9a2d67051 |
line wrap: on
line diff
--- a/hgext/churn.py Sun Oct 06 09:45:02 2019 -0400 +++ b/hgext/churn.py Sun Oct 06 09:48:39 2019 -0400 @@ -32,17 +32,17 @@ # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should # be specifying the version(s) of Mercurial they are tested with, or # leave the attribute unspecified. -testedwith = 'ships-with-hg-core' +testedwith = b'ships-with-hg-core' def changedlines(ui, repo, ctx1, ctx2, fns): added, removed = 0, 0 fmatch = scmutil.matchfiles(repo, fns) - diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node(), fmatch)) - for l in diff.split('\n'): - if l.startswith("+") and not l.startswith("+++ "): + diff = b''.join(patch.diff(repo, ctx1.node(), ctx2.node(), fmatch)) + for l in diff.split(b'\n'): + if l.startswith(b"+") and not l.startswith(b"+++ "): added += 1 - elif l.startswith("-") and not l.startswith("--- "): + elif l.startswith(b"-") and not l.startswith(b"--- "): removed += 1 return (added, removed) @@ -50,17 +50,17 @@ def countrate(ui, repo, amap, *pats, **opts): """Calculate stats""" opts = pycompat.byteskwargs(opts) - if opts.get('dateformat'): + if opts.get(b'dateformat'): def getkey(ctx): t, tz = ctx.date() date = datetime.datetime(*time.gmtime(float(t) - tz)[:6]) return encoding.strtolocal( - date.strftime(encoding.strfromlocal(opts['dateformat'])) + date.strftime(encoding.strfromlocal(opts[b'dateformat'])) ) else: - tmpl = opts.get('oldtemplate') or opts.get('template') + tmpl = opts.get(b'oldtemplate') or opts.get(b'template') tmpl = logcmdutil.maketemplater(ui, repo, tmpl) def getkey(ctx): @@ -69,12 +69,12 @@ return ui.popbuffer() progress = ui.makeprogress( - _('analyzing'), unit=_('revisions'), total=len(repo) + _(b'analyzing'), unit=_(b'revisions'), total=len(repo) ) rate = {} df = False - if opts.get('date'): - df = dateutil.matchdate(opts['date']) + if opts.get(b'date'): + df = dateutil.matchdate(opts[b'date']) m = scmutil.match(repo[None], pats, opts) @@ -85,12 +85,12 @@ key = getkey(ctx).strip() key = amap.get(key, key) # alias remap - if opts.get('changesets'): + if opts.get(b'changesets'): rate[key] = (rate.get(key, (0,))[0] + 1, 0) else: parents = ctx.parents() if len(parents) > 1: - ui.note(_('revision %d is a merge, ignoring...\n') % (rev,)) + ui.note(_(b'revision %d is a merge, ignoring...\n') % (rev,)) return ctx1 = parents[0] @@ -108,50 +108,50 @@ @command( - 'churn', + b'churn', [ ( - 'r', - 'rev', + b'r', + b'rev', [], - _('count rate for the specified revision or revset'), - _('REV'), + _(b'count rate for the specified revision or revset'), + _(b'REV'), ), ( - 'd', - 'date', - '', - _('count rate for revisions matching date spec'), - _('DATE'), + b'd', + b'date', + b'', + _(b'count rate for revisions matching date spec'), + _(b'DATE'), ), ( - 't', - 'oldtemplate', - '', - _('template to group changesets (DEPRECATED)'), - _('TEMPLATE'), + b't', + b'oldtemplate', + b'', + _(b'template to group changesets (DEPRECATED)'), + _(b'TEMPLATE'), ), ( - 'T', - 'template', - '{author|email}', - _('template to group changesets'), - _('TEMPLATE'), + b'T', + b'template', + b'{author|email}', + _(b'template to group changesets'), + _(b'TEMPLATE'), ), ( - 'f', - 'dateformat', - '', - _('strftime-compatible format for grouping by date'), - _('FORMAT'), + b'f', + b'dateformat', + b'', + _(b'strftime-compatible format for grouping by date'), + _(b'FORMAT'), ), - ('c', 'changesets', False, _('count rate by number of changesets')), - ('s', 'sort', False, _('sort by key (default: sort by count)')), - ('', 'diffstat', False, _('display added/removed lines separately')), - ('', 'aliases', '', _('file with email aliases'), _('FILE')), + (b'c', b'changesets', False, _(b'count rate by number of changesets')), + (b's', b'sort', False, _(b'sort by key (default: sort by count)')), + (b'', b'diffstat', False, _(b'display added/removed lines separately')), + (b'', b'aliases', b'', _(b'file with email aliases'), _(b'FILE')), ] + cmdutil.walkopts, - _("hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]"), + _(b"hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]"), helpcategory=command.CATEGORY_MAINTENANCE, inferrepo=True, ) @@ -193,21 +193,21 @@ ''' def pad(s, l): - return s + " " * (l - encoding.colwidth(s)) + return s + b" " * (l - encoding.colwidth(s)) amap = {} aliases = opts.get(r'aliases') - if not aliases and os.path.exists(repo.wjoin('.hgchurn')): - aliases = repo.wjoin('.hgchurn') + if not aliases and os.path.exists(repo.wjoin(b'.hgchurn')): + aliases = repo.wjoin(b'.hgchurn') if aliases: - for l in open(aliases, "rb"): + for l in open(aliases, b"rb"): try: - alias, actual = l.rsplit('=' in l and '=' or None, 1) + alias, actual = l.rsplit(b'=' in l and b'=' or None, 1) amap[alias.strip()] = actual.strip() except ValueError: l = l.strip() if l: - ui.warn(_("skipping malformed alias: %s\n") % l) + ui.warn(_(b"skipping malformed alias: %s\n") % l) continue rate = list(countrate(ui, repo, amap, *pats, **opts).items()) @@ -224,7 +224,7 @@ maxname = max(len(k) for k, v in rate) ttywidth = ui.termwidth() - ui.debug("assuming %i character terminal\n" % ttywidth) + ui.debug(b"assuming %i character terminal\n" % ttywidth) width = ttywidth - maxname - 2 - 2 - 2 if opts.get(r'diffstat'): @@ -232,21 +232,21 @@ def format(name, diffstat): added, removed = diffstat - return "%s %15s %s%s\n" % ( + return b"%s %15s %s%s\n" % ( pad(name, maxname), - '+%d/-%d' % (added, removed), - ui.label('+' * charnum(added), 'diffstat.inserted'), - ui.label('-' * charnum(removed), 'diffstat.deleted'), + b'+%d/-%d' % (added, removed), + ui.label(b'+' * charnum(added), b'diffstat.inserted'), + ui.label(b'-' * charnum(removed), b'diffstat.deleted'), ) else: width -= 6 def format(name, count): - return "%s %6d %s\n" % ( + return b"%s %6d %s\n" % ( pad(name, maxname), sum(count), - '*' * charnum(sum(count)), + b'*' * charnum(sum(count)), ) def charnum(count):