comparison mercurial/revset.py @ 29346:38e0c83c7ee4

revset: record if a set is in topographical order A later revision adds actual topographical sorting. Recording if a set is in this order allows hg log -G to avoid re-sorting the revset.
author Martijn Pieters <mjpieters@fb.com>
date Tue, 14 Jun 2016 11:05:36 +0100
parents 5e32852fa4bd
children 98535ad46fc0
comparison
equal deleted inserted replaced
29345:62b890496de5 29346:38e0c83c7ee4
2506 2506
2507 def isdescending(self): 2507 def isdescending(self):
2508 """True if the set will iterate in descending order""" 2508 """True if the set will iterate in descending order"""
2509 raise NotImplementedError() 2509 raise NotImplementedError()
2510 2510
2511 def istopo(self):
2512 """True if the set will iterate in topographical order"""
2513 raise NotImplementedError()
2514
2511 @util.cachefunc 2515 @util.cachefunc
2512 def min(self): 2516 def min(self):
2513 """return the minimum element in the set""" 2517 """return the minimum element in the set"""
2514 if self.fastasc is not None: 2518 if self.fastasc is not None:
2515 for r in self.fastasc(): 2519 for r in self.fastasc():
2591 """Basic data structure that represents a revset and contains the basic 2595 """Basic data structure that represents a revset and contains the basic
2592 operation that it should be able to perform. 2596 operation that it should be able to perform.
2593 2597
2594 Every method in this class should be implemented by any smartset class. 2598 Every method in this class should be implemented by any smartset class.
2595 """ 2599 """
2596 def __init__(self, data=(), datarepr=None): 2600 def __init__(self, data=(), datarepr=None, istopo=False):
2597 """ 2601 """
2598 datarepr: a tuple of (format, obj, ...), a function or an object that 2602 datarepr: a tuple of (format, obj, ...), a function or an object that
2599 provides a printable representation of the given data. 2603 provides a printable representation of the given data.
2600 """ 2604 """
2601 self._ascending = None 2605 self._ascending = None
2606 self._istopo = istopo
2602 if not isinstance(data, list): 2607 if not isinstance(data, list):
2603 if isinstance(data, set): 2608 if isinstance(data, set):
2604 self._set = data 2609 self._set = data
2605 # set has no order we pick one for stability purpose 2610 # set has no order we pick one for stability purpose
2606 self._ascending = True 2611 self._ascending = True
2639 def __nonzero__(self): 2644 def __nonzero__(self):
2640 return bool(self._list) 2645 return bool(self._list)
2641 2646
2642 def sort(self, reverse=False): 2647 def sort(self, reverse=False):
2643 self._ascending = not bool(reverse) 2648 self._ascending = not bool(reverse)
2649 self._istopo = False
2644 2650
2645 def reverse(self): 2651 def reverse(self):
2646 if self._ascending is None: 2652 if self._ascending is None:
2647 self._list.reverse() 2653 self._list.reverse()
2648 else: 2654 else:
2649 self._ascending = not self._ascending 2655 self._ascending = not self._ascending
2656 self._istopo = False
2650 2657
2651 def __len__(self): 2658 def __len__(self):
2652 return len(self._list) 2659 return len(self._list)
2653 2660
2654 def isascending(self): 2661 def isascending(self):
2664 2671
2665 This is part of the mandatory API for smartset.""" 2672 This is part of the mandatory API for smartset."""
2666 if len(self) <= 1: 2673 if len(self) <= 1:
2667 return True 2674 return True
2668 return self._ascending is not None and not self._ascending 2675 return self._ascending is not None and not self._ascending
2676
2677 def istopo(self):
2678 """Is the collection is in topographical order or not.
2679
2680 This is part of the mandatory API for smartset."""
2681 if len(self) <= 1:
2682 return True
2683 return self._istopo
2669 2684
2670 def first(self): 2685 def first(self):
2671 if self: 2686 if self:
2672 if self._ascending is None: 2687 if self._ascending is None:
2673 return self._list[0] 2688 return self._list[0]
2779 def isascending(self): 2794 def isascending(self):
2780 return self._subset.isascending() 2795 return self._subset.isascending()
2781 2796
2782 def isdescending(self): 2797 def isdescending(self):
2783 return self._subset.isdescending() 2798 return self._subset.isdescending()
2799
2800 def istopo(self):
2801 return self._subset.istopo()
2784 2802
2785 def first(self): 2803 def first(self):
2786 for x in self: 2804 for x in self:
2787 return x 2805 return x
2788 return None 2806 return None
3026 return self._ascending is not None and self._ascending 3044 return self._ascending is not None and self._ascending
3027 3045
3028 def isdescending(self): 3046 def isdescending(self):
3029 return self._ascending is not None and not self._ascending 3047 return self._ascending is not None and not self._ascending
3030 3048
3049 def istopo(self):
3050 # not worth the trouble asserting if the two sets combined are still
3051 # in topographical order. Use the sort() predicate to explicitly sort
3052 # again instead.
3053 return False
3054
3031 def reverse(self): 3055 def reverse(self):
3032 if self._ascending is None: 3056 if self._ascending is None:
3033 self._list.reverse() 3057 self._list.reverse()
3034 else: 3058 else:
3035 self._ascending = not self._ascending 3059 self._ascending = not self._ascending
3193 return self._ascending 3217 return self._ascending
3194 3218
3195 def isdescending(self): 3219 def isdescending(self):
3196 return not self._ascending 3220 return not self._ascending
3197 3221
3222 def istopo(self):
3223 # not worth the trouble asserting if the two sets combined are still
3224 # in topographical order. Use the sort() predicate to explicitly sort
3225 # again instead.
3226 return False
3227
3198 def first(self): 3228 def first(self):
3199 if self._ascending: 3229 if self._ascending:
3200 it = self.fastasc 3230 it = self.fastasc
3201 else: 3231 else:
3202 it = self.fastdesc 3232 it = self.fastdesc
3254 def sort(self, reverse=False): 3284 def sort(self, reverse=False):
3255 self._ascending = not reverse 3285 self._ascending = not reverse
3256 3286
3257 def reverse(self): 3287 def reverse(self):
3258 self._ascending = not self._ascending 3288 self._ascending = not self._ascending
3289
3290 def istopo(self):
3291 # not worth the trouble asserting if the two sets combined are still
3292 # in topographical order. Use the sort() predicate to explicitly sort
3293 # again instead.
3294 return False
3259 3295
3260 def _iterfilter(self, iterrange): 3296 def _iterfilter(self, iterrange):
3261 s = self._hiddenrevs 3297 s = self._hiddenrevs
3262 for r in iterrange: 3298 for r in iterrange:
3263 if r not in s: 3299 if r not in s: