##// END OF EJS Templates
demandimportpy3: only use lazy extension loader on Python 3.6+...
demandimportpy3: only use lazy extension loader on Python 3.6+ There was an inline comment denoting a bug in the lazy extension loader on Python 3.5 which prevents it from working there. But the code was not conditional on the Python version. The result of this was a myriad of failures on Python 3.5 due to getattr() and friends not working on lazy extension modules. By making extension modules non-lazy on Python 3.5, we reduce the number of test failures from 48 to 22 on that Python version.

File last commit:

r43385:4aa72cdf default
r43695:2d31ef3f stable
Show More
commitextras.py
89 lines | 2.4 KiB | text/x-python | PythonLexer
# commitextras.py
#
# Copyright 2013 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
'''adds a new flag extras to commit (ADVANCED)'''
from __future__ import absolute_import
import re
from mercurial.i18n import _
from mercurial import (
commands,
error,
extensions,
registrar,
util,
)
cmdtable = {}
command = registrar.command(cmdtable)
testedwith = b'ships-with-hg-core'
usedinternally = {
b'amend_source',
b'branch',
b'close',
b'histedit_source',
b'topic',
b'rebase_source',
b'intermediate-source',
b'__touch-noise__',
b'source',
b'transplant_source',
}
def extsetup(ui):
entry = extensions.wrapcommand(commands.table, b'commit', _commit)
options = entry[1]
options.append(
(
b'',
b'extra',
[],
_(b'set a changeset\'s extra values'),
_(b"KEY=VALUE"),
)
)
def _commit(orig, ui, repo, *pats, **opts):
if util.safehasattr(repo, 'unfiltered'):
repo = repo.unfiltered()
class repoextra(repo.__class__):
def commit(self, *innerpats, **inneropts):
extras = opts.get(r'extra')
for raw in extras:
if b'=' not in raw:
msg = _(
b"unable to parse '%s', should follow "
b"KEY=VALUE format"
)
raise error.Abort(msg % raw)
k, v = raw.split(b'=', 1)
if not k:
msg = _(b"unable to parse '%s', keys can't be empty")
raise error.Abort(msg % raw)
if re.search(br'[^\w-]', k):
msg = _(
b"keys can only contain ascii letters, digits,"
b" '_' and '-'"
)
raise error.Abort(msg)
if k in usedinternally:
msg = _(
b"key '%s' is used internally, can't be set "
b"manually"
)
raise error.Abort(msg % k)
inneropts[r'extra'][k] = v
return super(repoextra, self).commit(*innerpats, **inneropts)
repo.__class__ = repoextra
return orig(ui, repo, *pats, **opts)