mercurial/revset.py
changeset 22726 169aa5e74b52
parent 22725 88e5483bfb20
child 22727 0f3e240a1c35
equal deleted inserted replaced
22725:88e5483bfb20 22726:169aa5e74b52
   407             if not rev in descendants and not rev in include]
   407             if not rev in descendants and not rev in include]
   408     else:
   408     else:
   409         exclude = getset(repo, spanset(repo), args[1])
   409         exclude = getset(repo, spanset(repo), args[1])
   410 
   410 
   411     results = set(ancestormod.missingancestors(include, exclude, cl.parentrevs))
   411     results = set(ancestormod.missingancestors(include, exclude, cl.parentrevs))
   412     return lazyset(subset, results.__contains__)
   412     return filteredset(subset, results.__contains__)
   413 
   413 
   414 def bisect(repo, subset, x):
   414 def bisect(repo, subset, x):
   415     """``bisect(string)``
   415     """``bisect(string)``
   416     Changesets marked in the specified bisect status:
   416     Changesets marked in the specified bisect status:
   417 
   417 
   666     # in the correct order.
   666     # in the correct order.
   667     args.ascending()
   667     args.ascending()
   668     result = (orderedlazyset(s, subset.__contains__, ascending=True) +
   668     result = (orderedlazyset(s, subset.__contains__, ascending=True) +
   669               orderedlazyset(args, subset.__contains__, ascending=True))
   669               orderedlazyset(args, subset.__contains__, ascending=True))
   670 
   670 
   671     # Wrap result in a lazyset since it's an _addset, which doesn't implement
   671     # Wrap result in a filteredset since it's an _addset, which doesn't
   672     # all the necessary functions to be consumed by callers.
   672     # implement all the necessary functions to be consumed by callers.
   673     return orderedlazyset(result, lambda r: True, ascending=True)
   673     return orderedlazyset(result, lambda r: True, ascending=True)
   674 
   674 
   675 def descendants(repo, subset, x):
   675 def descendants(repo, subset, x):
   676     """``descendants(set)``
   676     """``descendants(set)``
   677     Changesets which are descendants of changesets in set.
   677     Changesets which are descendants of changesets in set.
  2328     def __sub__(self, other):
  2328     def __sub__(self, other):
  2329         """Returns a new object with the substraction of the two collections.
  2329         """Returns a new object with the substraction of the two collections.
  2330 
  2330 
  2331         This is part of the mandatory API for smartset."""
  2331         This is part of the mandatory API for smartset."""
  2332         # If we are operating on 2 baseset, do the computation now since all
  2332         # If we are operating on 2 baseset, do the computation now since all
  2333         # data is available. The alternative is to involve a lazyset, which
  2333         # data is available. The alternative is to involve a filteredset, which
  2334         # may be slow.
  2334         # may be slow.
  2335         if isinstance(other, baseset):
  2335         if isinstance(other, baseset):
  2336             other = other.set()
  2336             other = other.set()
  2337             return baseset([x for x in self if x not in other])
  2337             return baseset([x for x in self if x not in other])
  2338 
  2338 
  2369 
  2369 
  2370         `condition` is a callable which takes a revision number and returns a
  2370         `condition` is a callable which takes a revision number and returns a
  2371         boolean.
  2371         boolean.
  2372 
  2372 
  2373         This is part of the mandatory API for smartset."""
  2373         This is part of the mandatory API for smartset."""
  2374         return lazyset(self, condition)
  2374         return filteredset(self, condition)
  2375 
  2375 
  2376 class _orderedsetmixin(object):
  2376 class _orderedsetmixin(object):
  2377     """Mixin class with utility methods for smartsets
  2377     """Mixin class with utility methods for smartsets
  2378 
  2378 
  2379     This should be extended by smartsets which have the isascending(),
  2379     This should be extended by smartsets which have the isascending(),
  2402         """return the largest element in the set"""
  2402         """return the largest element in the set"""
  2403         if self.isascending():
  2403         if self.isascending():
  2404             return self._last()
  2404             return self._last()
  2405         return self._first()
  2405         return self._first()
  2406 
  2406 
  2407 class lazyset(abstractsmartset):
  2407 class filteredset(abstractsmartset):
  2408     """Duck type for baseset class which iterates lazily over the revisions in
  2408     """Duck type for baseset class which iterates lazily over the revisions in
  2409     the subset and contains a function which tests for membership in the
  2409     the subset and contains a function which tests for membership in the
  2410     revset
  2410     revset
  2411     """
  2411     """
  2412     def __init__(self, subset, condition=lambda x: True, ascending=None):
  2412     def __init__(self, subset, condition=lambda x: True, ascending=None):
  2450         if it is None:
  2450         if it is None:
  2451             return None
  2451             return None
  2452         return lambda: self._iterfilter(it())
  2452         return lambda: self._iterfilter(it())
  2453 
  2453 
  2454     def __and__(self, x):
  2454     def __and__(self, x):
  2455         return lazyset(self, x.__contains__)
  2455         return filteredset(self, x.__contains__)
  2456 
  2456 
  2457     def __sub__(self, x):
  2457     def __sub__(self, x):
  2458         return lazyset(self, lambda r: r not in x)
  2458         return filteredset(self, lambda r: r not in x)
  2459 
  2459 
  2460     def __add__(self, x):
  2460     def __add__(self, x):
  2461         return _addset(self, x)
  2461         return _addset(self, x)
  2462 
  2462 
  2463     def __nonzero__(self):
  2463     def __nonzero__(self):
  2497 
  2497 
  2498     def isdescending(self):
  2498     def isdescending(self):
  2499         return self._ascending is not None and not self._ascending
  2499         return self._ascending is not None and not self._ascending
  2500 
  2500 
  2501     def filter(self, l):
  2501     def filter(self, l):
  2502         return lazyset(self, l)
  2502         return filteredset(self, l)
  2503 
  2503 
  2504 class orderedlazyset(_orderedsetmixin, lazyset):
  2504 class orderedlazyset(_orderedsetmixin, filteredset):
  2505     """Subclass of lazyset which subset can be ordered either ascending or
  2505     """Subclass of filteredset which subset can be ordered either ascending or
  2506     descendingly
  2506     descendingly
  2507     """
  2507     """
  2508     def __init__(self, subset, condition, ascending=True):
  2508     def __init__(self, subset, condition, ascending=True):
  2509         super(orderedlazyset, self).__init__(subset, condition)
  2509         super(orderedlazyset, self).__init__(subset, condition)
  2510         self._ascending = ascending
  2510         self._ascending = ascending
  2585         return self._genlist
  2585         return self._genlist
  2586 
  2586 
  2587     def filter(self, condition):
  2587     def filter(self, condition):
  2588         if self._ascending is not None:
  2588         if self._ascending is not None:
  2589             return orderedlazyset(self, condition, ascending=self._ascending)
  2589             return orderedlazyset(self, condition, ascending=self._ascending)
  2590         return lazyset(self, condition)
  2590         return filteredset(self, condition)
  2591 
  2591 
  2592     def ascending(self):
  2592     def ascending(self):
  2593         if self._ascending is None:
  2593         if self._ascending is None:
  2594             self.sort()
  2594             self.sort()
  2595             self._ascending = True
  2595             self._ascending = True
  2607 
  2607 
  2608     def __and__(self, other):
  2608     def __and__(self, other):
  2609         filterfunc = other.__contains__
  2609         filterfunc = other.__contains__
  2610         if self._ascending is not None:
  2610         if self._ascending is not None:
  2611             return orderedlazyset(self, filterfunc, ascending=self._ascending)
  2611             return orderedlazyset(self, filterfunc, ascending=self._ascending)
  2612         return lazyset(self, filterfunc)
  2612         return filteredset(self, filterfunc)
  2613 
  2613 
  2614     def __sub__(self, other):
  2614     def __sub__(self, other):
  2615         filterfunc = lambda r: r not in other
  2615         filterfunc = lambda r: r not in other
  2616         if self._ascending is not None:
  2616         if self._ascending is not None:
  2617             return orderedlazyset(self, filterfunc, ascending=self._ascending)
  2617             return orderedlazyset(self, filterfunc, ascending=self._ascending)
  2618         return lazyset(self, filterfunc)
  2618         return filteredset(self, filterfunc)
  2619 
  2619 
  2620     def __add__(self, other):
  2620     def __add__(self, other):
  2621         """When both collections are ascending or descending, preserve the order
  2621         """When both collections are ascending or descending, preserve the order
  2622         """
  2622         """
  2623         kwargs = {}
  2623         kwargs = {}