Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master, master-1, and master-0

Make object iterator lazy.

Changeset 04e981907518

Parent 9e24871f503f

by Jelmer Vernooij

Changes to one file · Browse files at 04e981907518 Showing diff from parent 9e24871f503f Diff from another changeset...

 
21
22
23
 
24
25
26
27
28
29
 
30
31
32
33
34
35
36
37
38
 
233
234
235
236
 
 
237
238
239
 
 
240
241
242
243
244
 
 
 
 
 
 
 
245
246
247
248
249
250
251
 
252
253
254
 
259
260
261
262
263
264
 
 
21
22
23
24
25
26
 
27
28
29
30
31
32
33
34
35
 
36
37
38
 
233
234
235
 
236
237
238
239
 
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
 
260
261
262
263
 
268
269
270
 
 
 
271
@@ -21,18 +21,18 @@
 import urllib2    from dulwich.objects import ( + ShaFile,   hex_to_sha,   sha_to_hex, - ShaFile,   )  from dulwich.pack import (   Pack, + PackData,   iter_sha1,   load_packs,   write_pack,   write_pack_data,   write_pack_index_v2, - PackData,   )    PACKDIR = 'pack' @@ -233,22 +233,31 @@
    def __init__(self, store, sha_iter):   self.store = store - self.shas = list(sha_iter) + self.sha_iter = sha_iter + self._shas = []     def __iter__(self): - return ((self.store[sha], path) for sha, path in self.shas) + for sha, path in self.itershas(): + yield self.store[sha], path     def iterobjects(self):   for o, path in self:   yield o   + def itershas(self): + for sha in self._shas: + yield sha + for sha in self.sha_iter: + self._shas.append(sha) + yield sha +   def __contains__(self, needle):   """Check if an object is present.     :param needle: SHA1 of the object to check for   """   # FIXME: This could be more efficient - for sha, path in self.shas: + for sha, path in self.itershas():   if sha == needle:   return True   return False @@ -259,6 +268,4 @@
    def __len__(self):   """Return the number of objects.""" - return len(self.shas) - - + return len(list(self.itershas()))