Prechádzať zdrojové kódy

Add constants for sideband channels.

Jelmer Vernooij 10 rokov pred
rodič
commit
dcd2212097
3 zmenil súbory, kde vykonal 23 pridanie a 5 odobranie
  1. 10 2
      dulwich/client.py
  2. 7 0
      dulwich/protocol.py
  3. 6 3
      dulwich/server.py

+ 10 - 2
dulwich/client.py

@@ -67,6 +67,9 @@ from dulwich.protocol import (
     CAPABILITY_REPORT_STATUS,
     CAPABILITY_SIDE_BAND_64K,
     CAPABILITY_THIN_PACK,
+    SIDE_BAND_CHANNEL_DATA,
+    SIDE_BAND_CHANNEL_PROGRESS,
+    SIDE_BAND_CHANNEL_FATAL,
     PktLineParser,
     Protocol,
     ProtocolFile,
@@ -413,7 +416,10 @@ class GitClient(object):
             if progress is None:
                 # Just ignore progress data
                 progress = lambda x: None
-            self._read_side_band64k_data(proto, {1: pack_data, 2: progress})
+            self._read_side_band64k_data(proto, {
+                SIDE_BAND_CHANNEL_DATA: pack_data,
+                SIDE_BAND_CHANNEL_PROGRESS: progress}
+            )
         else:
             while True:
                 data = proto.read(rbufsize)
@@ -562,7 +568,9 @@ class TraditionalGitClient(GitClient):
             if ret is not None:
                 raise AssertionError("expected pkt tail")
             self._read_side_band64k_data(proto, {
-                1: write_data, 2: progress, 3: write_error})
+                SIDE_BAND_CHANNEL_DATA: write_data,
+                SIDE_BAND_CHANNEL_PROGRESS: progress,
+                SIDE_BAND_CHANNEL_FATAL: write_error})
 
 
 class TCPGitClient(TraditionalGitClient):

+ 7 - 0
dulwich/protocol.py

@@ -38,6 +38,13 @@ SINGLE_ACK = 0
 MULTI_ACK = 1
 MULTI_ACK_DETAILED = 2
 
+# pack data
+SIDE_BAND_CHANNEL_DATA = 1
+# progress messages
+SIDE_BAND_CHANNEL_PROGRESS = 2
+# fatal error message just before stream aborts
+SIDE_BAND_CHANNEL_FATAL = 3
+
 CAPABILITY_DELETE_REFS = b'delete-refs'
 CAPABILITY_INCLUDE_TAG = b'include-tag'
 CAPABILITY_MULTI_ACK = b'multi_ack'

+ 6 - 3
dulwich/server.py

@@ -83,6 +83,9 @@ from dulwich.protocol import (
     Protocol,
     ProtocolFile,
     ReceivableProtocol,
+    SIDE_BAND_CHANNEL_DATA,
+    SIDE_BAND_CHANNEL_PROGRESS,
+    SIDE_BAND_CHANNEL_FATAL,
     SINGLE_ACK,
     TCP_GIT_PORT,
     ZERO_SHA,
@@ -260,7 +263,7 @@ class UploadPackHandler(Handler):
     def progress(self, message):
         if self.has_capability(CAPABILITY_NO_PROGRESS) or self._processing_have_lines:
             return
-        self.proto.write_sideband(2, message)
+        self.proto.write_sideband(SIDE_BAND_CHANNEL_PROGRESS, message)
 
     def get_tagged(self, refs=None, repo=None):
         """Get a dict of peeled values of tags to their original tag shas.
@@ -292,7 +295,7 @@ class UploadPackHandler(Handler):
         return tagged
 
     def handle(self):
-        write = lambda x: self.proto.write_sideband(1, x)
+        write = lambda x: self.proto.write_sideband(SIDE_BAND_CHANNEL_DATA, x)
 
         graph_walker = ProtocolGraphWalker(self, self.repo.object_store,
             self.repo.get_peeled)
@@ -798,7 +801,7 @@ class ReceivePackHandler(Handler):
     def _report_status(self, status):
         if self.has_capability(CAPABILITY_SIDE_BAND_64K):
             writer = BufferedPktLineWriter(
-              lambda d: self.proto.write_sideband(1, d))
+              lambda d: self.proto.write_sideband(SIDE_BAND_CHANNEL_DATA, d))
             write = writer.write
 
             def flush():