commit - 65220bb2cef165004d1cafb6eff8c89aff6c7749
commit + 343ed68cdeb65d9a47851702cfd38f4cec8e2629
blob - bdf5217581836e69e003da3dbfe2a69d7b701ec3
blob + 626b2be493884a139c4fd9cfd31dffedaf7c4e14
--- dulwich/client.py
+++ dulwich/client.py
COMMAND_SHALLOW,
COMMAND_UNSHALLOW,
COMMAND_WANT,
+ DEFAULT_GIT_PROTOCOL_VERSION_FETCH,
+ DEFAULT_GIT_PROTOCOL_VERSION_SEND,
+ GIT_PROTOCOL_VERSIONS,
KNOWN_RECEIVE_CAPABILITIES,
KNOWN_UPLOAD_CAPABILITIES,
SIDE_BAND_CHANNEL_DATA,
extract_capability_names,
parse_capability,
pkt_line,
- GIT_PROTOCOL_VERSIONS,
)
from .refs import PEELED_TAG_SUFFIX, _import_remote_refs, read_info_refs
from .repo import Repo
assert isinstance(wants, list) and isinstance(wants[0], bytes)
wantcmd = COMMAND_WANT + b" " + wants[0]
if protocol_version is None:
- protocol_version = 0
+ protocol_version = DEFAULT_GIT_PROTOCOL_VERSION_SEND
if protocol_version != 2:
wantcmd += b" " + b" ".join(sorted(capabilities))
wantcmd += b"\n"
self._fetch_capabilities.remove(CAPABILITY_THIN_PACK)
if include_tags:
self._fetch_capabilities.add(CAPABILITY_INCLUDE_TAG)
- self.protocol_version = 0 # our default Git protocol version
+ self.protocol_version = 0 # will be overridden later
def get_url(self, path):
"""Retrieves full url to given path.
SendPackError: if server rejects the pack data
"""
- self.protocol_version = 0
+ self.protocol_version = DEFAULT_GIT_PROTOCOL_VERSION_SEND
proto, unused_can_read, stderr = self._connect(b"receive-pack", path)
with proto:
try:
path = path[1:]
if cmd == b"upload-pack":
if protocol_version is None:
- self.protocol_version = 2
+ self.protocol_version = DEFAULT_GIT_PROTOCOL_VERSION_FETCH
else:
self.protocol_version = protocol_version
else:
- self.protocol_version = 0
+ self.protocol_version = DEFAULT_GIT_PROTOCOL_VERSION_SEND
if cmd == b"upload-pack" and self.protocol_version == 2:
# Git protocol version advertisement is hidden behind two NUL bytes
# which lacks the "001f# service=git-receive-pack" marker.
if service == b"git-upload-pack":
if protocol_version is None:
- self.protocol_version = 2
+ self.protocol_version = DEFAULT_GIT_PROTOCOL_VERSION_FETCH
else:
self.protocol_version = protocol_version
if self.protocol_version == 2:
headers["Git-Protocol"] = "version=2"
else:
- self.protocol_version = 0
+ self.protocol_version = DEFAULT_GIT_PROTOCOL_VERSION_SEND
url = urljoin(base_url, tail)
resp, read = self._http_request(url, headers)
) = read_pkt_refs(proto.read_pkt_seq(), server_capabilities)
return refs, server_capabilities, base_url
else:
- self.protocol_version = 0
+ self.protocol_version = 0 # dumb servers only support protocol v0
return read_info_refs(resp), set(), base_url
finally:
resp.close()
blob - f1f0128fcdc51776d698834cc7574b78eb9a3d98
blob + 7b489d2e95d33e87b5f0d12b5c0f59363543b871
--- dulwich/protocol.py
+++ dulwich/protocol.py
# As of 2024, Git only implements version 2 during 'git fetch' and still uses
# version 0 during 'git push'.
GIT_PROTOCOL_VERSIONS = [0, 1, 2]
+DEFAULT_GIT_PROTOCOL_VERSION_FETCH = 2
+DEFAULT_GIT_PROTOCOL_VERSION_SEND = 0
ZERO_SHA = b"0" * 40