mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
9dc21f8d0b
Summary: D13853115 adds `edenscm/` to `sys.path` and code still uses `import mercurial`. That has nasty problems if both `import mercurial` and `import edenscm.mercurial` are used, because Python would think `mercurial.foo` and `edenscm.mercurial.foo` are different modules so code like `try: ... except mercurial.error.Foo: ...`, or `isinstance(x, mercurial.foo.Bar)` would fail to handle the `edenscm.mercurial` version. There are also some module-level states (ex. `extensions._extensions`) that would cause trouble if they have multiple versions in a single process. Change imports to use the `edenscm` so ideally the `mercurial` is no longer imported at all. Add checks in extensions.py to catch unexpected extensions importing modules from the old (wrong) locations when running tests. Reviewed By: phillco Differential Revision: D13868981 fbshipit-source-id: f4e2513766957fd81d85407994f7521a08e4de48
102 lines
3.0 KiB
Python
102 lines
3.0 KiB
Python
# dulwich doesn't return the symref where remote HEAD points, so we monkey
|
|
# patch it here
|
|
from dulwich.errors import GitProtocolError
|
|
from dulwich.protocol import extract_capabilities
|
|
from edenscm.mercurial import url, util as hgutil
|
|
|
|
|
|
try:
|
|
from edenscm.mercurial import encoding
|
|
|
|
hfsignoreclean = encoding.hfsignoreclean
|
|
except AttributeError:
|
|
# compat with hg 3.2.1 and earlier, which doesn't have
|
|
# hfsignoreclean (This was borrowed wholesale from hg 3.2.2.)
|
|
_ignore = [
|
|
unichr(int(x, 16)).encode("utf-8") # noqa: F821
|
|
for x in "200c 200d 200e 200f 202a 202b 202c 202d 202e "
|
|
"206a 206b 206c 206d 206e 206f feff".split()
|
|
]
|
|
# verify the next function will work
|
|
assert set([i[0] for i in _ignore]) == set(["\xe2", "\xef"])
|
|
|
|
def hfsignoreclean(s):
|
|
"""Remove codepoints ignored by HFS+ from s.
|
|
|
|
>>> hfsignoreclean(u'.h\u200cg'.encode('utf-8'))
|
|
'.hg'
|
|
>>> hfsignoreclean(u'.h\ufeffg'.encode('utf-8'))
|
|
'.hg'
|
|
"""
|
|
if "\xe2" in s or "\xef" in s:
|
|
for c in _ignore:
|
|
s = s.replace(c, "")
|
|
return s
|
|
|
|
|
|
def passwordmgr(ui):
|
|
try:
|
|
realm = hgutil.urlreq.httppasswordmgrwithdefaultrealm()
|
|
return url.passwordmgr(ui, realm)
|
|
except (TypeError, AttributeError):
|
|
# compat with hg < 3.9
|
|
return url.passwordmgr(ui)
|
|
|
|
|
|
def read_pkt_refs(proto):
|
|
server_capabilities = None
|
|
refs = {}
|
|
# Receive refs from server
|
|
for pkt in proto.read_pkt_seq():
|
|
(sha, ref) = pkt.rstrip("\n").split(None, 1)
|
|
if sha == "ERR":
|
|
raise GitProtocolError(ref)
|
|
if server_capabilities is None:
|
|
(ref, server_capabilities) = extract_capabilities(ref)
|
|
symref = "symref=HEAD:"
|
|
for cap in server_capabilities:
|
|
if cap.startswith(symref):
|
|
sha = cap.replace(symref, "")
|
|
refs[ref] = sha
|
|
|
|
if len(refs) == 0:
|
|
return None, set([])
|
|
return refs, set(server_capabilities)
|
|
|
|
|
|
CONFIG_DEFAULTS = {
|
|
"git": {
|
|
"authors": None,
|
|
"blockdotgit": True,
|
|
"blockdothg": True,
|
|
"branch_bookmark_suffix": None,
|
|
"debugextrainmessage": False, # test only -- do not document this!
|
|
"findcopiesharder": False,
|
|
"intree": None,
|
|
"mindate": None,
|
|
"public": list,
|
|
"renamelimit": 400,
|
|
"similarity": 0,
|
|
},
|
|
"hggit": {"mapsavefrequency": 0, "usephases": False},
|
|
}
|
|
|
|
hasconfigitems = False
|
|
|
|
|
|
def registerconfigs(configitem):
|
|
global hasconfigitems
|
|
hasconfigitems = True
|
|
for section, items in CONFIG_DEFAULTS.iteritems():
|
|
for item, default in items.iteritems():
|
|
configitem(section, item, default=default)
|
|
|
|
|
|
def config(ui, subtype, section, item):
|
|
if subtype == "string":
|
|
subtype = ""
|
|
getconfig = getattr(ui, "config" + subtype)
|
|
if hasconfigitems:
|
|
return getconfig(section, item)
|
|
return getconfig(section, item, CONFIG_DEFAULTS[section][item])
|