comparison hggit/compat.py @ 1092:3799bf885c1d

compat: use newer read_pkt_refs from dulwich if possible Beginning with dulwich 0.18, it now supports reporting the symrefs so we no longer need to monkey patch (will require future patches to use the new code, though).
author Sean Farley <sean@farley.io>
date Mon, 27 Nov 2017 17:45:51 -0500
parents c06d4656b77b
children 8e61d7a29932
comparison
equal deleted inserted replaced
1091:367f9e0dc198 1092:3799bf885c1d
50 return url.passwordmgr(ui, realm) 50 return url.passwordmgr(ui, realm)
51 except (TypeError, AttributeError): 51 except (TypeError, AttributeError):
52 # compat with hg < 3.9 52 # compat with hg < 3.9
53 return url.passwordmgr(ui) 53 return url.passwordmgr(ui)
54 54
55 # dulwich doesn't return the symref where remote HEAD points, so we monkey
56 # patch it here
57 from dulwich.errors import GitProtocolError
58 from dulwich.protocol import extract_capabilities
59 55
60 def read_pkt_refs(proto): 56 try:
61 server_capabilities = None 57 import dulwich.client
62 refs = {} 58 FetchPackResult = dulwich.client.FetchPackResult
63 # Receive refs from server 59 read_pkt_refs = dulwich.client.read_pkt_refs
64 for pkt in proto.read_pkt_seq(): 60 except (AttributeError, ImportError):
65 (sha, ref) = pkt.rstrip('\n').split(None, 1) 61 # older dulwich doesn't return the symref where remote HEAD points, so we
66 if sha == 'ERR': 62 # monkey patch it here
67 raise GitProtocolError(ref) 63 from dulwich.errors import GitProtocolError
68 if server_capabilities is None: 64 from dulwich.protocol import extract_capabilities
69 (ref, server_capabilities) = extract_capabilities(ref)
70 symref = 'symref=HEAD:'
71 for cap in server_capabilities:
72 if cap.startswith(symref):
73 sha = cap.replace(symref, '')
74 refs[ref] = sha
75 65
76 if len(refs) == 0: 66
77 return None, set([]) 67
78 return refs, set(server_capabilities) 68 def read_pkt_refs(proto):
69 server_capabilities = None
70 refs = {}
71 # Receive refs from server
72 for pkt in proto.read_pkt_seq():
73 (sha, ref) = pkt.rstrip('\n').split(None, 1)
74 if sha == 'ERR':
75 raise GitProtocolError(ref)
76 if server_capabilities is None:
77 (ref, server_capabilities) = extract_capabilities(ref)
78 symref = 'symref=HEAD:'
79 for cap in server_capabilities:
80 if cap.startswith(symref):
81 sha = cap.replace(symref, '')
82 refs[ref] = sha
83
84 if len(refs) == 0:
85 return None, set([])
86 return refs, set(server_capabilities)
79 87
80 88
81 CONFIG_DEFAULTS = { 89 CONFIG_DEFAULTS = {
82 'git': { 90 'git': {
83 'authors': None, 91 'authors': None,