comparison mercurial/revset.py @ 20749:c3e49b127de0

revset: added _orderedsetmixin class This class has utility methods for any ordered class to get the min and the max values.
author Lucas Moscovicz <lmoscovicz@fb.com>
date Wed, 12 Mar 2014 16:40:18 -0700
parents 6b731b29e154
children d4f2f2d74210
comparison
equal deleted inserted replaced
20748:6b731b29e154 20749:c3e49b127de0
2252 boolean. 2252 boolean.
2253 2253
2254 This is part of the mandatory API for smartset.""" 2254 This is part of the mandatory API for smartset."""
2255 return lazyset(self, condition) 2255 return lazyset(self, condition)
2256 2256
2257 class _orderedsetmixin(object):
2258 """Mixin class with utility methods for smartsets
2259
2260 This should be extended by smartsets which have the isascending(),
2261 isdescending() and reverse() methods"""
2262
2263 def _first(self):
2264 """return the first revision in the set"""
2265 for r in self:
2266 return r
2267 return None
2268
2269 def _last(self):
2270 """return the last revision in the set"""
2271 self.reverse()
2272 m = self._first()
2273 self.reverse()
2274 return m
2275
2276 def min(self):
2277 """return the smallest element in the set"""
2278 if self.isascending():
2279 return self._first()
2280 return self._last()
2281
2282 def max(self):
2283 """return the largest element in the set"""
2284 if self.isascending():
2285 return self._last()
2286 return self._first()
2287
2257 class lazyset(object): 2288 class lazyset(object):
2258 """Duck type for baseset class which iterates lazily over the revisions in 2289 """Duck type for baseset class which iterates lazily over the revisions in
2259 the subset and contains a function which tests for membership in the 2290 the subset and contains a function which tests for membership in the
2260 revset 2291 revset
2261 """ 2292 """