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