Commit f7f96325 authored by Augie Fackler's avatar Augie Fackler
Browse files

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
parent 2372284d9457
This diff is collapsed.
......@@ -232,66 +232,66 @@ urlreq = util.urlreq
# 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'
configtable = {}
configitem = registrar.configitem(configtable)
# deprecated config: acl.config
configitem(
'acl', 'config', default=None,
b'acl', b'config', default=None,
)
configitem(
'acl.groups', '.*', default=None, generic=True,
b'acl.groups', b'.*', default=None, generic=True,
)
configitem(
'acl.deny.branches', '.*', default=None, generic=True,
b'acl.deny.branches', b'.*', default=None, generic=True,
)
configitem(
'acl.allow.branches', '.*', default=None, generic=True,
b'acl.allow.branches', b'.*', default=None, generic=True,
)
configitem(
'acl.deny', '.*', default=None, generic=True,
b'acl.deny', b'.*', default=None, generic=True,
)
configitem(
'acl.allow', '.*', default=None, generic=True,
b'acl.allow', b'.*', default=None, generic=True,
)
configitem(
'acl', 'sources', default=lambda: ['serve'],
b'acl', b'sources', default=lambda: [b'serve'],
)
def _getusers(ui, group):
# First, try to use group definition from section [acl.groups]
hgrcusers = ui.configlist('acl.groups', group)
hgrcusers = ui.configlist(b'acl.groups', group)
if hgrcusers:
return hgrcusers
ui.debug('acl: "%s" not defined in [acl.groups]\n' % group)
ui.debug(b'acl: "%s" not defined in [acl.groups]\n' % group)
# If no users found in group definition, get users from OS-level group
try:
return util.groupmembers(group)
except KeyError:
raise error.Abort(_("group '%s' is undefined") % group)
raise error.Abort(_(b"group '%s' is undefined") % group)
def _usermatch(ui, user, usersorgroups):
if usersorgroups == '*':
if usersorgroups == b'*':
return True
for ug in usersorgroups.replace(',', ' ').split():
for ug in usersorgroups.replace(b',', b' ').split():
if ug.startswith('!'):
if ug.startswith(b'!'):
# Test for excluded user or group. Format:
# if ug is a user name: !username
# if ug is a group name: !@groupname
ug = ug[1:]
if (
not ug.startswith('@')
not ug.startswith(b'@')
and user != ug
or ug.startswith('@')
or ug.startswith(b'@')
and user not in _getusers(ui, ug[1:])
):
return True
......@@ -299,7 +299,9 @@ def _usermatch(ui, user, usersorgroups):
# Test for user or group. Format:
# if ug is a user name: username
# if ug is a group name: @groupname
elif user == ug or ug.startswith('@') and user in _getusers(ui, ug[1:]):
elif (
user == ug or ug.startswith(b'@') and user in _getusers(ui, ug[1:])
):
return True
return False
......@@ -308,14 +310,14 @@ def _usermatch(ui, user, usersorgroups):
def buildmatch(ui, repo, user, key):
'''return tuple of (match function, list enabled).'''
if not ui.has_section(key):
ui.debug('acl: %s not enabled\n' % key)
ui.debug(b'acl: %s not enabled\n' % key)
return None
pats = [
pat for pat, users in ui.configitems(key) if _usermatch(ui, user, users)
]
ui.debug(
'acl: %s enabled, %d entries for user %s\n' % (key, len(pats), user)
b'acl: %s enabled, %d entries for user %s\n' % (key, len(pats), user)
)
# Branch-based ACL
......@@ -323,14 +325,14 @@ def buildmatch(ui, repo, user, key):
if pats:
# If there's an asterisk (meaning "any branch"), always return True;
# Otherwise, test if b is in pats
if '*' in pats:
if b'*' in pats:
return util.always
return lambda b: b in pats
return util.never
# Path-based ACL
if pats:
return match.match(repo.root, '', pats)
return match.match(repo.root, b'', pats)
return util.never
......@@ -342,122 +344,128 @@ def ensureenabled(ui):
never loaded. This function ensure the extension is enabled when running
hooks.
"""
if 'acl' in ui._knownconfig:
if b'acl' in ui._knownconfig:
return
ui.setconfig('extensions', 'acl', '', source='internal')
extensions.loadall(ui, ['acl'])
ui.setconfig(b'extensions', b'acl', b'', source=b'internal')
extensions.loadall(ui, [b'acl'])
def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
ensureenabled(ui)
if hooktype not in ['pretxnchangegroup', 'pretxncommit', 'prepushkey']:
if hooktype not in [b'pretxnchangegroup', b'pretxncommit', b'prepushkey']:
raise error.Abort(
_(
'config error - hook type "%s" cannot stop '
'incoming changesets, commits, nor bookmarks'
b'config error - hook type "%s" cannot stop '
b'incoming changesets, commits, nor bookmarks'
)
% hooktype
)
if hooktype == 'pretxnchangegroup' and source not in ui.configlist(
'acl', 'sources'
if hooktype == b'pretxnchangegroup' and source not in ui.configlist(
b'acl', b'sources'
):
ui.debug('acl: changes have source "%s" - skipping\n' % source)
ui.debug(b'acl: changes have source "%s" - skipping\n' % source)
return
user = None
if source == 'serve' and r'url' in kwargs:
url = kwargs[r'url'].split(':')
if url[0] == 'remote' and url[1].startswith('http'):
if source == b'serve' and r'url' in kwargs:
url = kwargs[r'url'].split(b':')
if url[0] == b'remote' and url[1].startswith(b'http'):
user = urlreq.unquote(url[3])
if user is None:
user = procutil.getuser()
ui.debug('acl: checking access for user "%s"\n' % user)
ui.debug(b'acl: checking access for user "%s"\n' % user)
if hooktype == 'prepushkey':
if hooktype == b'prepushkey':
_pkhook(ui, repo, hooktype, node, source, user, **kwargs)
else:
_txnhook(ui, repo, hooktype, node, source, user, **kwargs)
def _pkhook(ui, repo, hooktype, node, source, user, **kwargs):
if kwargs[r'namespace'] == 'bookmarks':
if kwargs[r'namespace'] == b'bookmarks':
bookmark = kwargs[r'key']
ctx = kwargs[r'new']
allowbookmarks = buildmatch(ui, None, user, 'acl.allow.bookmarks')
denybookmarks = buildmatch(ui, None, user, 'acl.deny.bookmarks')
allowbookmarks = buildmatch(ui, None, user, b'acl.allow.bookmarks')
denybookmarks = buildmatch(ui, None, user, b'acl.deny.bookmarks')
if denybookmarks and denybookmarks(bookmark):
raise error.Abort(
_('acl: user "%s" denied on bookmark "%s"' ' (changeset "%s")')
_(
b'acl: user "%s" denied on bookmark "%s"'
b' (changeset "%s")'
)
% (user, bookmark, ctx)
)
if allowbookmarks and not allowbookmarks(bookmark):
raise error.Abort(
_(
'acl: user "%s" not allowed on bookmark "%s"'
' (changeset "%s")'
b'acl: user "%s" not allowed on bookmark "%s"'
b' (changeset "%s")'
)
% (user, bookmark, ctx)
)
ui.debug(
'acl: bookmark access granted: "%s" on bookmark "%s"\n'
b'acl: bookmark access granted: "%s" on bookmark "%s"\n'
% (ctx, bookmark)
)
def _txnhook(ui, repo, hooktype, node, source, user, **kwargs):
# deprecated config: acl.config
cfg = ui.config('acl', 'config')
cfg = ui.config(b'acl', b'config')
if cfg:
ui.readconfig(
cfg,
sections=[
'acl.groups',
'acl.allow.branches',
'acl.deny.branches',
'acl.allow',
'acl.deny',
b'acl.groups',
b'acl.allow.branches',
b'acl.deny.branches',
b'acl.allow',
b'acl.deny',
],
)
allowbranches = buildmatch(ui, None, user, 'acl.allow.branches')
denybranches = buildmatch(ui, None, user, 'acl.deny.branches')
allow = buildmatch(ui, repo, user, 'acl.allow')
deny = buildmatch(ui, repo, user, 'acl.deny')
allowbranches = buildmatch(ui, None, user, b'acl.allow.branches')
denybranches = buildmatch(ui, None, user, b'acl.deny.branches')
allow = buildmatch(ui, repo, user, b'acl.allow')
deny = buildmatch(ui, repo, user, b'acl.deny')
for rev in pycompat.xrange(repo[node].rev(), len(repo)):
ctx = repo[rev]
branch = ctx.branch()
if denybranches and denybranches(branch):
raise error.Abort(
_('acl: user "%s" denied on branch "%s"' ' (changeset "%s")')
_(b'acl: user "%s" denied on branch "%s"' b' (changeset "%s")')
% (user, branch, ctx)
)
if allowbranches and not allowbranches(branch):
raise error.Abort(
_(
'acl: user "%s" not allowed on branch "%s"'
' (changeset "%s")'
b'acl: user "%s" not allowed on branch "%s"'
b' (changeset "%s")'
)
% (user, branch, ctx)
)
ui.debug(
'acl: branch access granted: "%s" on branch "%s"\n' % (ctx, branch)
b'acl: branch access granted: "%s" on branch "%s"\n' % (ctx, branch)
)
for f in ctx.files():
if deny and deny(f):
raise error.Abort(
_('acl: user "%s" denied on "%s"' ' (changeset "%s")')
_(b'acl: user "%s" denied on "%s"' b' (changeset "%s")')
% (user, f, ctx)
)
if allow and not allow(f):
raise error.Abort(
_('acl: user "%s" not allowed on "%s"' ' (changeset "%s")')
_(
b'acl: user "%s" not allowed on "%s"'
b' (changeset "%s")'
)
% (user, f, ctx)
)
ui.debug('acl: path access granted: "%s"\n' % ctx)
ui.debug(b'acl: path access granted: "%s"\n' % ctx)
......@@ -24,23 +24,23 @@ from mercurial import (
# 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'
cmdtable = {}
command = registrar.command(cmdtable)
@command(
'amend',
b'amend',
[
(
'A',
'addremove',
b'A',
b'addremove',
None,
_('mark new/missing files as added/removed before committing'),
_(b'mark new/missing files as added/removed before committing'),
),
('e', 'edit', None, _('invoke editor on commit messages')),
('i', 'interactive', None, _('use interactive mode')),
(b'e', b'edit', None, _(b'invoke editor on commit messages')),
(b'i', b'interactive', None, _(b'use interactive mode')),
(
b'',
b'close-branch',
......@@ -48,13 +48,13 @@ command = registrar.command(cmdtable)
_(b'mark a branch as closed, hiding it from the branch list'),
),
(b's', b'secret', None, _(b'use the secret phase for committing')),
('n', 'note', '', _('store a note on the amend')),
(b'n', b'note', b'', _(b'store a note on the amend')),
]
+ cmdutil.walkopts
+ cmdutil.commitopts
+ cmdutil.commitopts2
+ cmdutil.commitopts3,
_('[OPTION]... [FILE]...'),
_(b'[OPTION]... [FILE]...'),
helpcategory=command.CATEGORY_COMMITTING,
inferrepo=True,
)
......@@ -70,7 +70,7 @@ def amend(ui, repo, *pats, **opts):
cmdutil.checknotesize(ui, opts)
with repo.wlock(), repo.lock():
if not opts.get('logfile'):
opts['message'] = opts.get('message') or repo['.'].description()
opts['amend'] = True
if not opts.get(b'logfile'):
opts[b'message'] = opts.get(b'message') or repo[b'.'].description()
opts[b'amend'] = True
return commands._docommit(ui, repo, *pats, **pycompat.strkwargs(opts))
......@@ -42,14 +42,14 @@ configtable = {}
configitem = registrar.configitem(configtable)
configitem(
'automv', 'similarity', default=95,
b'automv', b'similarity', default=95,
)
def extsetup(ui):
entry = extensions.wrapcommand(commands.table, 'commit', mvcheck)
entry = extensions.wrapcommand(commands.table, b'commit', mvcheck)
entry[1].append(
('', 'no-automv', None, _('disable automatic file move detection'))
(b'', b'no-automv', None, _(b'disable automatic file move detection'))
)
......@@ -57,11 +57,11 @@ def mvcheck(orig, ui, repo, *pats, **opts):
"""Hook to check for moves at commit time"""
opts = pycompat.byteskwargs(opts)
renames = None
disabled = opts.pop('no_automv', False)
disabled = opts.pop(b'no_automv', False)
if not disabled:
threshold = ui.configint('automv', 'similarity')
threshold = ui.configint(b'automv', b'similarity')
if not 0 <= threshold <= 100:
raise error.Abort(_('automv.similarity must be between 0 and 100'))
raise error.Abort(_(b'automv.similarity must be between 0 and 100'))
if threshold > 0:
match = scmutil.match(repo[None], pats, opts)
added, removed = _interestingfiles(repo, match)
......@@ -87,7 +87,7 @@ def _interestingfiles(repo, matcher):
added = stat.added
removed = stat.removed
copy = copies.pathcopies(repo['.'], repo[None], matcher)
copy = copies.pathcopies(repo[b'.'], repo[None], matcher)
# remove the copy files for which we already have copy info
added = [f for f in added if f not in copy]
......@@ -108,10 +108,10 @@ def _findrenames(repo, uipathfn, added, removed, similarity):
):
if repo.ui.verbose:
repo.ui.status(
_('detected move of %s as %s (%d%% similar)\n')
_(b'detected move of %s as %s (%d%% similar)\n')
% (uipathfn(src), uipathfn(dst), score * 100)
)
renames[dst] = src
if renames:
repo.ui.status(_('detected move of %d files\n') % len(renames))
repo.ui.status(_(b'detected move of %d files\n') % len(renames))
return renames
......@@ -26,33 +26,33 @@ from mercurial import (
# 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 prettyedge(before, edge, after):
if edge == '~':
return '\xE2\x95\xA7' # U+2567 ╧
if edge == '/':
return '\xE2\x95\xB1' # U+2571 ╱
if edge == '-':
return '\xE2\x94\x80' # U+2500 ─
if edge == '|':
return '\xE2\x94\x82' # U+2502 │
if edge == ':':
return '\xE2\x94\x86' # U+2506 ┆
if edge == '\\':
return '\xE2\x95\xB2' # U+2572 ╲
if edge == '+':
if before == ' ' and not after == ' ':
return '\xE2\x94\x9C' # U+251C ├
if after == ' ' and not before == ' ':
return '\xE2\x94\xA4' # U+2524 ┤
return '\xE2\x94\xBC' # U+253C ┼
if edge == b'~':
return b'\xE2\x95\xA7' # U+2567 ╧
if edge == b'/':
return b'\xE2\x95\xB1' # U+2571 ╱
if edge == b'-':
return b'\xE2\x94\x80' # U+2500 ─
if edge == b'|':
return b'\xE2\x94\x82' # U+2502 │
if edge == b':':
return b'\xE2\x94\x86' # U+2506 ┆
if edge == b'\\':
return b'\xE2\x95\xB2' # U+2572 ╲
if edge == b'+':
if before == b' ' and not after == b' ':
return b'\xE2\x94\x9C' # U+251C ├
if after == b' ' and not before == b' ':
return b'\xE2\x94\xA4' # U+2524 ┤
return b'\xE2\x94\xBC' # U+253C ┼
return edge
def convertedges(line):
line = ' %s ' % line
line = b' %s ' % line
pretty = []
for idx in pycompat.xrange(len(line) - 2):
pretty.append(
......@@ -62,21 +62,21 @@ def convertedges(line):
line[idx + 2 : idx + 3],
)
)
return ''.join(pretty)
return b''.join(pretty)
def getprettygraphnode(orig, *args, **kwargs):
node = orig(*args, **kwargs)
if node == 'o':
return '\xE2\x97\x8B' # U+25CB ○
if node == '@':
return '\xE2\x97\x8D' # U+25CD ◍
if node == '*':
return '\xE2\x88\x97' # U+2217 ∗
if node == 'x':
return '\xE2\x97\x8C' # U+25CC ◌
if node == '_':
return '\xE2\x95\xA4' # U+2564 ╤
if node == b'o':
return b'\xE2\x97\x8B' # U+25CB ○
if node == b'@':
return b'\xE2\x97\x8D' # U+25CD ◍
if node == b'*':
return b'\xE2\x88\x97' # U+2217 ∗
if node == b'x':
return b'\xE2\x97\x8C' # U+25CC ◌
if node == b'_':
return b'\xE2\x95\xA4' # U+2564 ╤
return node
......@@ -87,21 +87,21 @@ def outputprettygraph(orig, ui, graph, *args, **kwargs):
def extsetup(ui):
if ui.plain('graph'):
if ui.plain(b'graph'):
return
if encoding.encoding != 'UTF-8':
ui.warn(_('beautifygraph: unsupported encoding, UTF-8 required\n'))
if encoding.encoding != b'UTF-8':
ui.warn(_(b'beautifygraph: unsupported encoding, UTF-8 required\n'))
return
if r'A' in encoding._wide:
ui.warn(
_(
'beautifygraph: unsupported terminal settings, '
'monospace narrow text required\n'
b'beautifygraph: unsupported terminal settings, '
b'monospace narrow text required\n'
)
)
return
extensions.wrapfunction(graphmod, 'outputgraph', outputprettygraph)
extensions.wrapfunction(templatekw, 'getgraphnode', getprettygraphnode)
extensions.wrapfunction(graphmod, b'outputgraph', outputprettygraph)
extensions.wrapfunction(templatekw, b'getgraphnode', getprettygraphnode)
......@@ -63,7 +63,7 @@ from mercurial.utils import (
# 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'
cmdtable = {}
command = registrar.command(cmdtable)
......@@ -72,27 +72,27 @@ configtable = {}
configitem = registrar.configitem(configtable)
configitem(
'blackbox', 'dirty', default=False,
b'blackbox', b'dirty', default=False,
)
configitem(
'blackbox', 'maxsize', default='1 MB',
b'blackbox', b'maxsize', default=b'1 MB',
)
configitem(
'blackbox', 'logsource', default=False,
b'blackbox', b'logsource', default=False,
)
configitem(
'blackbox', 'maxfiles', default=7,
b'blackbox', b'maxfiles', default=7,
)
configitem(
'blackbox', 'track', default=lambda: ['*'],
b'blackbox', b'track', default=lambda: [b'*'],
)
configitem(
'blackbox',
'ignore',
default=lambda: ['chgserver', 'cmdserver', 'extension'],
b'blackbox',
b'ignore',
default=lambda: [b'chgserver', b'cmdserver', b'extension'],
)
configitem(
'blackbox', 'date-format', default='%Y/%m/%d %H:%M:%S',
b'blackbox', b'date-format', default=b'%Y/%m/%d %H:%M:%S',
)
_lastlogger = loggingutil.proxylogger()
......@@ -101,10 +101,10 @@ _lastlogger = loggingutil.proxylogger()
class blackboxlogger(object):
def __init__(self, ui, repo):
self._repo = repo
self._trackedevents = set(ui.configlist('blackbox', 'track'))
self._ignoredevents = set(ui.configlist('blackbox', 'ignore'))
self._maxfiles = ui.configint('blackbox', 'maxfiles')
self._maxsize = ui.configbytes('blackbox', 'maxsize')
self._trackedevents = set(ui.configlist(b'blackbox', b'track'))
self._ignoredevents = set(ui.configlist(b'blackbox', b'ignore'))
self._maxfiles = ui.configint(b'blackbox', b'maxfiles')
self._maxsize = ui.configbytes(b'blackbox', b'maxsize')
self._inlog = False
def tracked(self, event):
......@@ -125,29 +125,29 @@ class blackboxlogger(object):
self._inlog = False
def _log(self, ui, event, msg, opts):
default = ui.configdate('devel', 'default-date')
date = dateutil.datestr(default, ui.config('blackbox', 'date-format'))
default = ui.configdate(b'devel', b'default-date')
date = dateutil.datestr(default, ui.config(b'blackbox', b'date-format'))
user = procutil.getuser()
pid = '%d' % procutil.getpid()
changed = ''
pid = b'%d' % procutil.getpid()
changed = b''
ctx = self._repo[None]
parents = ctx.parents()
rev = '+'.join([hex(p.node()) for p in parents])
if ui.configbool('blackbox', 'dirty') and ctx.dirty(
rev = b'+'.join([hex(p.node()) for p in parents])
if ui.configbool(b'blackbox', b'dirty') and ctx.dirty(
missing=True, merge=False, branch=False
):
changed = '+'
if ui.configbool('blackbox', 'logsource'):
src = ' [%s]' % event