comparison mercurial/revset.py @ 20724:e9a64b3f2925

revset: added sort method in addset We need this method to duck-type generatorset since this class is not going to be used outside revset.py and we don't need to duck-type baseset. This sort method will only do something when the addset is not already sorted or is not sorted in the way we want it to be.
author Lucas Moscovicz <lmoscovicz@fb.com>
date Tue, 11 Mar 2014 17:03:43 -0700
parents fb9852c46a42
children cf628b50afbb
comparison
equal deleted inserted replaced
20723:fb9852c46a42 20724:e9a64b3f2925
2407 return x in self._r1 or x in self._r2 2407 return x in self._r1 or x in self._r2
2408 2408
2409 def set(self): 2409 def set(self):
2410 return self 2410 return self
2411 2411
2412 def sort(self, reverse=False):
2413 """Sort the added set
2414
2415 For this we use the cached list with all the generated values and if we
2416 know they are ascending or descending we can sort them in a smart way.
2417 """
2418 if self._ascending is None:
2419 self._list.sort(reverse=reverse)
2420 self._ascending = not reverse
2421 else:
2422 if bool(self._ascending) == bool(reverse):
2423 self.reverse()
2424
2412 def reverse(self): 2425 def reverse(self):
2413 self._list.reverse() 2426 self._list.reverse()
2414 if self._ascending is not None: 2427 if self._ascending is not None:
2415 self._ascending = not self._ascending 2428 self._ascending = not self._ascending
2416 2429