commit 71bce1944990afe1ff52045dff58479aeb636d09 from: Jelmer Vernooij via: Jelmer Vernooij date: Sun Oct 20 20:35:00 2024 UTC Reuse refs commit - 61d937ada18220c4731bfb4ebbde8b61f901e686 commit + 71bce1944990afe1ff52045dff58479aeb636d09 blob - d407bef9de4db4369bcd3400ad01ca33364c42c2 blob + a79d7dd7434b10a9409ff691c9007f3e6df37b8b --- dulwich/client.py +++ dulwich/client.py @@ -2355,7 +2355,9 @@ class AbstractHttpGitClient(GitClient): def _discover_references( self, service, base_url, protocol_version=None - ) -> Tuple[Dict[Ref, ObjectID], Set[bytes], str]: + ) -> Tuple[ + Dict[Ref, ObjectID], Set[bytes], str, Dict[Ref, Ref], Dict[Ref, ObjectID] + ]: if ( protocol_version is not None and protocol_version not in GIT_PROTOCOL_VERSIONS @@ -2457,18 +2459,16 @@ class AbstractHttpGitClient(GitClient): server_capabilities, resp, read, proto = begin_protocol_v2( proto ) - ( - refs, - symrefs, - peeled - ) = read_pkt_refs_v2(proto.read_pkt_seq()) + (refs, symrefs, peeled) = read_pkt_refs_v2(proto.read_pkt_seq()) else: ( refs, server_capabilities, ) = read_pkt_refs_v1(proto.read_pkt_seq()) - peeled = {} - (symrefs, agent) = _extract_symrefs_and_agent(server_capabilities) + (refs, peeled) = split_peeled_refs(refs) + (symrefs, agent) = _extract_symrefs_and_agent( + server_capabilities + ) return refs, server_capabilities, base_url, symrefs, peeled else: self.protocol_version = 0 # dumb servers only support protocol v0 blob - 7ae2c69b54a370a1b5507038a8a880735d212985 blob + 1fa48a9c0339688ce0ab956b788828ee83fa79e8 --- dulwich/contrib/swift.py +++ dulwich/contrib/swift.py @@ -59,7 +59,7 @@ from ..pack import ( write_pack_object, ) from ..protocol import TCP_GIT_PORT -from ..refs import InfoRefsContainer, read_info_refs, write_info_refs, split_peeled_refs +from ..refs import InfoRefsContainer, read_info_refs, split_peeled_refs, write_info_refs from ..repo import OBJECTDIR, BaseRepo from ..server import Backend, TCPGitServer blob - 2e2d4ab422cafebc55223c1b2d1a7e884fa0e515 blob + fd774089835ad64a4e462ada8148101679950f04 --- dulwich/refs.py +++ dulwich/refs.py @@ -585,17 +585,8 @@ class InfoRefsContainer(RefsContainer): def __init__(self, f) -> None: self._refs = {} self._peeled = {} - for line in f.readlines(): - sha, name = line.rstrip(b"\n").split(b"\t") - if name.endswith(PEELED_TAG_SUFFIX): - name = name[:-3] - if not check_ref_format(name): - raise ValueError(f"invalid ref name {name!r}") - self._peeled[name] = sha - else: - if not check_ref_format(name): - raise ValueError(f"invalid ref name {name!r}") - self._refs[name] = sha + refs = read_info_refs(f) + (self._refs, self._peeled) = split_peeled_refs(refs) def allkeys(self): return self._refs.keys() @@ -1179,9 +1170,9 @@ def split_peeled_refs(refs): """Split peeled refs from regular refs.""" peeled = {} regular = {} - for (ref, sha) in refs.items(): + for ref, sha in refs.items(): if ref.endswith(PEELED_TAG_SUFFIX): - peeled[ref[:-len(PEELED_TAG_SUFFIX)]] = sha + peeled[ref[: -len(PEELED_TAG_SUFFIX)]] = sha else: regular[ref] = sha return regular, peeled blob - 5c491beaac0012ee99eabad358e6cc0e92eb9c02 blob + 9d2947c8b28789d00594822677740842f18cf0b9 --- tests/test_client.py +++ tests/test_client.py @@ -1138,7 +1138,9 @@ class HttpGitClientTests(TestCase): # instantiate HttpGitClient with mocked pool manager c = HttpGitClient(base_url, pool_manager=pool_manager, config=None) # call method that detects url redirection - _, _, processed_url, _, _ = c._discover_references(b"git-upload-pack", base_url) + _, _, processed_url, _, _ = c._discover_references( + b"git-upload-pack", base_url + ) # send the same request as the method above without redirection resp = c.pool_manager.request("GET", base_url + tail, redirect=False) blob - 96873a10dd67a7ba68b5c7235f781e4e9b73b8be blob + 361e98a3c6f04c1b340738f02b35f0a40965059f --- tests/test_refs.py +++ tests/test_refs.py @@ -38,8 +38,8 @@ from dulwich.refs import ( parse_symref_value, read_packed_refs, read_packed_refs_with_peeled, - strip_peeled_refs, split_peeled_refs, + strip_peeled_refs, write_packed_refs, ) from dulwich.repo import Repo @@ -819,7 +819,10 @@ class StripPeeledRefsTests(TestCase): def test_split_peeled_refs(self): (regular, peeled) = split_peeled_refs(self.all_refs) self.assertEqual(regular, self.non_peeled_refs) - self.assertEqual(peeled, { - b'refs/tags/2.0.0': b"0749936d0956c661ac8f8d3483774509c165f89e", - b"refs/tags/1.0.0": b"a93db4b0360cc635a2b93675010bac8d101f73f0"}) - + self.assertEqual( + peeled, + { + b"refs/tags/2.0.0": b"0749936d0956c661ac8f8d3483774509c165f89e", + b"refs/tags/1.0.0": b"a93db4b0360cc635a2b93675010bac8d101f73f0", + }, + )