view hggit/ @ 1037:da62ef0569bb

compat: fix fallback for ui.passwordmgr The fallback introduced in 05c8aa7d3edc failed to work on hg < 3.8, which has no util.urlreq. This was apparently masked by the fact that the Makefile is not set up to run doctests in all modules, which we'll fix in an upcoming change.
author Kevin Bullock <>
date Sat, 05 Aug 2017 17:14:44 -0500
parents cfcd3032355c
children a2eccdeed26d
line wrap: on
line source

from mercurial import (
    util as hgutil,

    from 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") 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'))
        >>> hfsignoreclean(u'.h\ufeffg'.encode('utf-8'))
        if "\xe2" in s or "\xef" in s:
            for c in _ignore:
                s = s.replace(c, '')
        return s

def passwordmgr(ui):
        realm = hgutil.urlreq.httppasswordmgrwithdefaultrealm()
        return url.passwordmgr(ui, realm)
    except (TypeError, AttributeError):
        # compat with hg < 3.9
        return url.passwordmgr(ui)

# 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

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)