2018-07-06 03:45:27 +03:00
|
|
|
# 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
|
2019-01-30 03:25:33 +03:00
|
|
|
from edenscm.mercurial import url, util as hgutil
|
2016-08-05 00:16:06 +03:00
|
|
|
|
2018-07-06 03:45:27 +03:00
|
|
|
|
2014-11-24 03:06:21 +03:00
|
|
|
try:
|
2019-01-30 03:25:33 +03:00
|
|
|
from edenscm.mercurial import encoding
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2014-11-24 03:06:21 +03:00
|
|
|
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.)
|
2018-05-30 12:16:33 +03:00
|
|
|
_ignore = [
|
2019-12-04 21:53:06 +03:00
|
|
|
# pyre-fixme[18]: Global name `unichr` is undefined.
|
2018-07-06 03:45:27 +03:00
|
|
|
unichr(int(x, 16)).encode("utf-8") # noqa: F821
|
2018-05-30 12:16:33 +03:00
|
|
|
for x in "200c 200d 200e 200f 202a 202b 202c 202d 202e "
|
|
|
|
"206a 206b 206c 206d 206e 206f feff".split()
|
|
|
|
]
|
2014-11-24 03:06:21 +03:00
|
|
|
# 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:
|
2018-05-30 12:16:33 +03:00
|
|
|
s = s.replace(c, "")
|
2014-11-24 03:06:21 +03:00
|
|
|
return s
|
2016-08-05 00:16:06 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2017-08-06 01:07:59 +03:00
|
|
|
def passwordmgr(ui):
|
2016-08-05 00:16:06 +03:00
|
|
|
try:
|
2017-08-06 01:14:44 +03:00
|
|
|
realm = hgutil.urlreq.httppasswordmgrwithdefaultrealm()
|
|
|
|
return url.passwordmgr(ui, realm)
|
|
|
|
except (TypeError, AttributeError):
|
2016-08-05 00:16:06 +03:00
|
|
|
# compat with hg < 3.9
|
|
|
|
return url.passwordmgr(ui)
|
2015-05-15 21:38:59 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2015-05-15 21:38:59 +03:00
|
|
|
def read_pkt_refs(proto):
|
|
|
|
server_capabilities = None
|
|
|
|
refs = {}
|
|
|
|
# Receive refs from server
|
|
|
|
for pkt in proto.read_pkt_seq():
|
2018-05-30 12:16:33 +03:00
|
|
|
(sha, ref) = pkt.rstrip("\n").split(None, 1)
|
|
|
|
if sha == "ERR":
|
2015-05-15 21:38:59 +03:00
|
|
|
raise GitProtocolError(ref)
|
|
|
|
if server_capabilities is None:
|
|
|
|
(ref, server_capabilities) = extract_capabilities(ref)
|
2018-05-30 12:16:33 +03:00
|
|
|
symref = "symref=HEAD:"
|
2015-05-15 21:38:59 +03:00
|
|
|
for cap in server_capabilities:
|
|
|
|
if cap.startswith(symref):
|
2018-05-30 12:16:33 +03:00
|
|
|
sha = cap.replace(symref, "")
|
2015-05-15 21:38:59 +03:00
|
|
|
refs[ref] = sha
|
|
|
|
|
|
|
|
if len(refs) == 0:
|
|
|
|
return None, set([])
|
|
|
|
return refs, set(server_capabilities)
|
2017-10-24 21:56:26 +03:00
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2017-10-24 21:56:26 +03:00
|
|
|
CONFIG_DEFAULTS = {
|
2018-05-30 12:16:33 +03:00
|
|
|
"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,
|
2017-10-24 22:14:25 +03:00
|
|
|
},
|
2018-05-30 12:16:33 +03:00
|
|
|
"hggit": {"mapsavefrequency": 0, "usephases": False},
|
2017-10-24 21:56:26 +03:00
|
|
|
}
|
|
|
|
|
2017-11-02 04:05:44 +03:00
|
|
|
hasconfigitems = False
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2017-11-02 04:05:44 +03:00
|
|
|
def registerconfigs(configitem):
|
|
|
|
global hasconfigitems
|
|
|
|
hasconfigitems = True
|
2020-01-29 03:25:29 +03:00
|
|
|
for section, items in CONFIG_DEFAULTS.items():
|
|
|
|
for item, default in items.items():
|
2017-11-02 04:05:44 +03:00
|
|
|
configitem(section, item, default=default)
|
|
|
|
|
2018-05-30 12:16:33 +03:00
|
|
|
|
2017-10-24 21:56:26 +03:00
|
|
|
def config(ui, subtype, section, item):
|
2018-05-30 12:16:33 +03:00
|
|
|
if subtype == "string":
|
|
|
|
subtype = ""
|
|
|
|
getconfig = getattr(ui, "config" + subtype)
|
2017-11-02 04:05:44 +03:00
|
|
|
if hasconfigitems:
|
|
|
|
return getconfig(section, item)
|
2017-10-24 21:56:26 +03:00
|
|
|
return getconfig(section, item, CONFIG_DEFAULTS[section][item])
|