瀏覽代碼

Support activity reporting.

Jelmer Vernooij 16 年之前
父節點
當前提交
e62cb12a42
共有 3 個文件被更改,包括 26 次插入3 次删除
  1. 6 0
      NEWS
  2. 13 2
      dulwich/client.py
  3. 7 1
      dulwich/protocol.py

+ 6 - 0
NEWS

@@ -1,3 +1,9 @@
+0.2.0	UNRELEASED
+
+ FEATURES
+
+  * Support for activity reporting in smart protocol client.
+
 0.1.1	2009-03-13
 
  BUG FIXES

+ 13 - 2
dulwich/client.py

@@ -72,8 +72,19 @@ class GitClient(object):
 
     """
 
-    def __init__(self, can_read, read, write, thin_packs=True):
-        self.proto = Protocol(read, write)
+    def __init__(self, can_read, read, write, thin_packs=True, 
+        report_activity=None):
+        """Create a new GitClient instance.
+
+        :param can_read: Function that returns True if there is data available
+            to be read.
+        :param read: Callback for reading data, takes number of bytes to read
+        :param write: Callback for writing data
+        :param thin_packs: Whether or not thin packs should be retrieved
+        :param report_activity: Optional callback for reporting transport
+            activity.
+        """
+        self.proto = Protocol(read, write, report_activity)
         self._can_read = can_read
         self._capabilities = list(CAPABILITIES)
         if thin_packs:

+ 7 - 1
dulwich/protocol.py

@@ -47,9 +47,10 @@ class ProtocolFile(object):
 
 class Protocol(object):
 
-    def __init__(self, read, write):
+    def __init__(self, read, write, report_activity=None):
         self.read = read
         self.write = write
+        self.report_activity = report_activity
 
     def read_pkt_line(self):
         """
@@ -63,7 +64,10 @@ class Protocol(object):
                 raise HangupException()
             size = int(sizestr, 16)
             if size == 0:
+                self.report_activity(4, 'read')
                 return None
+            if self.report_activity:
+                self.report_activity(size, 'read')
             return self.read(size-4)
         except socket.error, e:
             raise GitProtocolError(e)
@@ -83,8 +87,10 @@ class Protocol(object):
         try:
             if line is None:
                 self.write("0000")
+                self.report_activity(4, 'write')
             else:
                 self.write("%04x%s" % (len(line)+4, line))
+                self.report_activity(4+len(line), 'write')
         except socket.error, e:
             raise GitProtocolError(e)