فهرست منبع

Add object-format capability advertisement to server

Jelmer Vernooij 1 ماه پیش
والد
کامیت
4da04ef743
2فایلهای تغییر یافته به همراه28 افزوده شده و 9 حذف شده
  1. 15 0
      dulwich/protocol.py
  2. 13 9
      dulwich/server.py

+ 15 - 0
dulwich/protocol.py

@@ -39,6 +39,7 @@ __all__ = [
     "CAPABILITY_MULTI_ACK_DETAILED",
     "CAPABILITY_NO_DONE",
     "CAPABILITY_NO_PROGRESS",
+    "CAPABILITY_OBJECT_FORMAT",
     "CAPABILITY_OFS_DELTA",
     "CAPABILITY_QUIET",
     "CAPABILITY_REPORT_STATUS",
@@ -78,6 +79,7 @@ __all__ = [
     "ack_type",
     "agent_string",
     "capability_agent",
+    "capability_object_format",
     "capability_symref",
     "extract_capabilities",
     "extract_capability_names",
@@ -171,6 +173,7 @@ CAPABILITY_ALLOW_TIP_SHA1_IN_WANT = b"allow-tip-sha1-in-want"
 CAPABILITY_ALLOW_REACHABLE_SHA1_IN_WANT = b"allow-reachable-sha1-in-want"
 CAPABILITY_FETCH = b"fetch"
 CAPABILITY_FILTER = b"filter"
+CAPABILITY_OBJECT_FORMAT = b"object-format"
 
 # Magic ref that is used to attach capabilities to when
 # there are no refs. Should always be ste to ZERO_SHA.
@@ -233,6 +236,18 @@ def capability_agent() -> bytes:
     return CAPABILITY_AGENT + b"=" + agent_string()
 
 
+def capability_object_format(fmt: str) -> bytes:
+    """Generate the object-format capability string.
+
+    Args:
+      fmt: Object format name (e.g., "sha1" or "sha256")
+
+    Returns:
+      Object-format capability with format name
+    """
+    return CAPABILITY_OBJECT_FORMAT + b"=" + fmt.encode("ascii")
+
+
 def capability_symref(from_ref: bytes, to_ref: bytes) -> bytes:
     """Generate a symref capability string.
 

+ 13 - 9
dulwich/server.py

@@ -136,6 +136,7 @@ from .protocol import (
     ReceivableProtocol,
     ack_type,
     capability_agent,
+    capability_object_format,
     extract_capabilities,
     extract_want_line_capabilities,
     format_ack_line,
@@ -341,10 +342,9 @@ class PackHandler(Handler):
         self._done_received = False
         self.advertise_refs = False
 
-    @classmethod
-    def capabilities(cls) -> Iterable[bytes]:
+    def capabilities(self) -> Iterable[bytes]:
         """Return a list of capabilities supported by this handler."""
-        raise NotImplementedError(cls.capabilities)
+        raise NotImplementedError(self.capabilities)
 
     @classmethod
     def innocuous_capabilities(cls) -> Iterable[bytes]:
@@ -440,9 +440,12 @@ class UploadPackHandler(PackHandler):
         # data (such as side-band, see the progress method here).
         self._processing_have_lines = False
 
-    @classmethod
-    def capabilities(cls) -> list[bytes]:
-        """Return the list of capabilities supported by upload-pack."""
+    def capabilities(self) -> list[bytes]:
+        """Return the list of capabilities supported by upload-pack.
+
+        Returns:
+            List of capabilities including object-format for the repository
+        """
         return [
             CAPABILITY_MULTI_ACK_DETAILED,
             CAPABILITY_MULTI_ACK,
@@ -453,6 +456,7 @@ class UploadPackHandler(PackHandler):
             CAPABILITY_INCLUDE_TAG,
             CAPABILITY_SHALLOW,
             CAPABILITY_NO_DONE,
+            capability_object_format(self.repo.object_format.name),
         ]
 
     @classmethod
@@ -1297,12 +1301,11 @@ class ReceivePackHandler(PackHandler):
         self.repo = backend.open_repository(args[0])
         self.advertise_refs = advertise_refs
 
-    @classmethod
-    def capabilities(cls) -> Iterable[bytes]:
+    def capabilities(self) -> Iterable[bytes]:
         """Return supported capabilities.
 
         Returns:
-            List of capability names
+            List of capability names including object-format for the repository
         """
         return [
             CAPABILITY_REPORT_STATUS,
@@ -1311,6 +1314,7 @@ class ReceivePackHandler(PackHandler):
             CAPABILITY_OFS_DELTA,
             CAPABILITY_SIDE_BAND_64K,
             CAPABILITY_NO_DONE,
+            capability_object_format(self.repo.object_format.name),
         ]
 
     def _apply_pack(