comparison mercurial/revset.py @ 20703:e07b1fd30805

revset: added sort methods to generatorsets Method needed to propagate sort calls amongst lazy structures. The generated list (stored in the object) is sorted. If the generated list did not contain all elements from the generator, we take care of that before sorting the list.
author Lucas Moscovicz <lmoscovicz@fb.com>
date Mon, 24 Feb 2014 16:36:17 -0800
parents d99fcf4483f8
children 9cc2249a9461
comparison
equal deleted inserted replaced
20696:77ab0abb08a0 20703:e07b1fd30805
2346 self._gen = gen 2346 self._gen = gen
2347 self._iter = iter(gen) 2347 self._iter = iter(gen)
2348 self._cache = {} 2348 self._cache = {}
2349 self._genlist = baseset([]) 2349 self._genlist = baseset([])
2350 self._iterated = False 2350 self._iterated = False
2351 self._finished = False
2351 2352
2352 def __contains__(self, x): 2353 def __contains__(self, x):
2353 if x in self._cache: 2354 if x in self._cache:
2354 return self._cache[x] 2355 return self._cache[x]
2355 2356
2356 for l in self: 2357 for l in self:
2357 if l == x: 2358 if l == x:
2358 return True 2359 return True
2359 2360
2361 self._finished = True
2360 self._cache[x] = False 2362 self._cache[x] = False
2361 return False 2363 return False
2362 2364
2363 def __iter__(self): 2365 def __iter__(self):
2364 if self._iterated: 2366 if self._iterated:
2370 for item in self._gen: 2372 for item in self._gen:
2371 self._cache[item] = True 2373 self._cache[item] = True
2372 self._genlist.append(item) 2374 self._genlist.append(item)
2373 yield item 2375 yield item
2374 2376
2377 self._finished = True
2378
2375 def set(self): 2379 def set(self):
2376 return self 2380 return self
2381
2382 def sort(self, reverse=False):
2383 # Basic implementation to be changed in future patches
2384 if not self._finished:
2385 for i in self:
2386 continue
2387 self._genlist.sort(reverse=reverse)
2377 2388
2378 class ascgeneratorset(generatorset): 2389 class ascgeneratorset(generatorset):
2379 """ Same structure as generatorset but stops iterating after it goes past 2390 """ Same structure as generatorset but stops iterating after it goes past
2380 the value when asked for membership and the element is not contained 2391 the value when asked for membership and the element is not contained
2381 """ 2392 """