|
@@ -52,9 +52,12 @@ import time
|
|
|
import zlib
|
|
|
from collections.abc import Iterable, Iterator
|
|
|
from functools import partial
|
|
|
-from typing import Optional, cast
|
|
|
+from typing import TYPE_CHECKING, Optional, cast
|
|
|
from typing import Protocol as TypingProtocol
|
|
|
|
|
|
+if TYPE_CHECKING:
|
|
|
+ from .object_store import BaseObjectStore
|
|
|
+
|
|
|
from dulwich import log_utils
|
|
|
|
|
|
from .archive import tar_stream
|
|
@@ -68,7 +71,7 @@ from .errors import (
|
|
|
UnexpectedCommandError,
|
|
|
)
|
|
|
from .object_store import find_shallow
|
|
|
-from .objects import Commit, ObjectID, valid_hexsha
|
|
|
+from .objects import Commit, ObjectID, Tree, valid_hexsha
|
|
|
from .pack import ObjectContainer, PackedObjectContainer, write_pack_from_container
|
|
|
from .protocol import (
|
|
|
CAPABILITIES_REF,
|
|
@@ -113,7 +116,7 @@ from .protocol import (
|
|
|
format_unshallow_line,
|
|
|
symref_capabilities,
|
|
|
)
|
|
|
-from .refs import PEELED_TAG_SUFFIX, RefsContainer, write_info_refs
|
|
|
+from .refs import PEELED_TAG_SUFFIX, Ref, RefsContainer, write_info_refs
|
|
|
from .repo import Repo
|
|
|
|
|
|
logger = log_utils.getLogger(__name__)
|
|
@@ -925,8 +928,8 @@ class ReceivePackHandler(PackHandler):
|
|
|
]
|
|
|
|
|
|
def _apply_pack(
|
|
|
- self, refs: list[tuple[bytes, bytes, bytes]]
|
|
|
- ) -> list[tuple[bytes, bytes]]:
|
|
|
+ self, refs: list[tuple[ObjectID, ObjectID, Ref]]
|
|
|
+ ) -> Iterator[tuple[bytes, bytes]]:
|
|
|
all_exceptions = (
|
|
|
IOError,
|
|
|
OSError,
|
|
@@ -937,7 +940,6 @@ class ReceivePackHandler(PackHandler):
|
|
|
zlib.error,
|
|
|
ObjectFormatException,
|
|
|
)
|
|
|
- status = []
|
|
|
will_send_pack = False
|
|
|
|
|
|
for command in refs:
|
|
@@ -950,15 +952,15 @@ class ReceivePackHandler(PackHandler):
|
|
|
try:
|
|
|
recv = getattr(self.proto, "recv", None)
|
|
|
self.repo.object_store.add_thin_pack(self.proto.read, recv)
|
|
|
- status.append((b"unpack", b"ok"))
|
|
|
+ yield (b"unpack", b"ok")
|
|
|
except all_exceptions as e:
|
|
|
- status.append((b"unpack", str(e).replace("\n", "").encode("utf-8")))
|
|
|
+ yield (b"unpack", str(e).replace("\n", "").encode("utf-8"))
|
|
|
# The pack may still have been moved in, but it may contain
|
|
|
# broken objects. We trust a later GC to clean it up.
|
|
|
else:
|
|
|
# The git protocol want to find a status entry related to unpack
|
|
|
# process even if no pack data has been sent.
|
|
|
- status.append((b"unpack", b"ok"))
|
|
|
+ yield (b"unpack", b"ok")
|
|
|
|
|
|
for oldsha, sha, ref in refs:
|
|
|
ref_status = b"ok"
|
|
@@ -979,9 +981,7 @@ class ReceivePackHandler(PackHandler):
|
|
|
ref_status = b"failed to write"
|
|
|
except KeyError:
|
|
|
ref_status = b"bad ref"
|
|
|
- status.append((ref, ref_status))
|
|
|
-
|
|
|
- return status
|
|
|
+ yield (ref, ref_status)
|
|
|
|
|
|
def _report_status(self, status: list[tuple[bytes, bytes]]) -> None:
|
|
|
if self.has_capability(CAPABILITY_SIDE_BAND_64K):
|
|
@@ -1007,7 +1007,7 @@ class ReceivePackHandler(PackHandler):
|
|
|
write(b"ok " + name + b"\n")
|
|
|
else:
|
|
|
write(b"ng " + name + b" " + msg + b"\n")
|
|
|
- write(None)
|
|
|
+ write(None) # type: ignore
|
|
|
flush()
|
|
|
|
|
|
def _on_post_receive(self, client_refs) -> None:
|
|
@@ -1033,7 +1033,7 @@ class ReceivePackHandler(PackHandler):
|
|
|
format_ref_line(
|
|
|
refs[0][0],
|
|
|
refs[0][1],
|
|
|
- self.capabilities() + symref_capabilities(symrefs),
|
|
|
+ list(self.capabilities()) + symref_capabilities(symrefs),
|
|
|
)
|
|
|
)
|
|
|
for i in range(1, len(refs)):
|
|
@@ -1056,11 +1056,12 @@ class ReceivePackHandler(PackHandler):
|
|
|
|
|
|
# client will now send us a list of (oldsha, newsha, ref)
|
|
|
while ref:
|
|
|
- client_refs.append(ref.split())
|
|
|
+ (oldsha, newsha, ref) = ref.split()
|
|
|
+ client_refs.append((oldsha, newsha, ref))
|
|
|
ref = self.proto.read_pkt_line()
|
|
|
|
|
|
# backend can now deal with this refs and read a pack using self.read
|
|
|
- status = self._apply_pack(client_refs)
|
|
|
+ status = list(self._apply_pack(client_refs))
|
|
|
|
|
|
self._on_post_receive(client_refs)
|
|
|
|
|
@@ -1088,7 +1089,7 @@ class UploadArchiveHandler(Handler):
|
|
|
prefix = b""
|
|
|
format = "tar"
|
|
|
i = 0
|
|
|
- store: ObjectContainer = self.repo.object_store
|
|
|
+ store: BaseObjectStore = self.repo.object_store
|
|
|
while i < len(arguments):
|
|
|
argument = arguments[i]
|
|
|
if argument == b"--prefix":
|
|
@@ -1099,12 +1100,16 @@ class UploadArchiveHandler(Handler):
|
|
|
format = arguments[i].decode("ascii")
|
|
|
else:
|
|
|
commit_sha = self.repo.refs[argument]
|
|
|
- tree = store[cast(Commit, store[commit_sha]).tree]
|
|
|
+ tree = cast(Tree, store[cast(Commit, store[commit_sha]).tree])
|
|
|
i += 1
|
|
|
self.proto.write_pkt_line(b"ACK")
|
|
|
self.proto.write_pkt_line(None)
|
|
|
for chunk in tar_stream(
|
|
|
- store, tree, mtime=time.time(), prefix=prefix, format=format
|
|
|
+ store,
|
|
|
+ tree,
|
|
|
+ mtime=int(time.time()),
|
|
|
+ prefix=prefix,
|
|
|
+ format=format, # type: ignore
|
|
|
):
|
|
|
write(chunk)
|
|
|
self.proto.write_pkt_line(None)
|
|
@@ -1130,7 +1135,7 @@ class TCPGitRequestHandler(socketserver.StreamRequestHandler):
|
|
|
|
|
|
cls = self.handlers.get(command, None)
|
|
|
if not callable(cls):
|
|
|
- raise GitProtocolError(f"Invalid service {command}")
|
|
|
+ raise GitProtocolError(f"Invalid service {command!r}")
|
|
|
h = cls(self.server.backend, args, proto) # type: ignore
|
|
|
h.handle()
|
|
|
|