Added cache to ProtocolGraphWalker to cope with several iterations on the commands...
authorRoland Mas <lolando@debian.org>
Thu, 10 Sep 2009 12:30:13 +0000 (14:30 +0200)
committerRoland Mas <lolando@debian.org>
Thu, 10 Sep 2009 12:30:13 +0000 (14:30 +0200)
dulwich/server.py

index 15e9116c7dc4d262b75814612c59f9d087bf33b1..bd4e16c2e97506baf77709f414a36181e9257714 100644 (file)
@@ -142,15 +142,36 @@ class UploadPackHandler(Handler):
             def __init__(self, proto):
                 self.proto = proto
                 self._last_sha = None
+                self._cached = False
+                self._cache = []
+                self._cache_index = 0
 
             def ack(self, have_ref):
                 self.proto.write_pkt_line("ACK %s continue\n" % have_ref)
 
+            def reset(self):
+                self._cached = True
+                self._cache_index = 0
+
             def next(self):
+                if not self._cached:
+                    return self.next_from_proto()
+                self._cache_index = self._cache_index + 1
+                if self._cache_index > len(self._cache):
+                    return None
+                return self._cache[self._cache_index]
+
+            def next_from_proto(self):
                 have = self.proto.read_pkt_line()
+                if have is None:
+                    self.proto.write_pkt_line("ACK %s\n" % self._last_sha)
+                    return None
+
                 if have[:4] == 'have':
+                    self._cache.append(have[5:45])
                     return have[5:45]
 
+
                 #if have[:4] == 'done':
                 #    return None