فهرست منبع

Added cache to ProtocolGraphWalker to cope with several iterations on the commands received from the net

Roland Mas 15 سال پیش
والد
کامیت
05703d5d83
1فایلهای تغییر یافته به همراه21 افزوده شده و 0 حذف شده
  1. 21 0
      dulwich/server.py

+ 21 - 0
dulwich/server.py

@@ -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