comparison mercurial/revset.py @ 22829:36e09c25f870

baseset: explicitly track order of the baseset A baseset starts without an explicit order. But as soon as a sort is requested, we simply register that the baseset has an order and use the ordered version of the list to behave accordingly. We will want to properly record the order at creation time in the future. This would unlock more optimisation and avoid some sorting.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 03 Oct 2014 03:29:55 -0500
parents 966860f7a1a8
children 1d1da8abe130
comparison
equal deleted inserted replaced
22828:966860f7a1a8 22829:36e09c25f870
2370 2370
2371 def __nonzero__(self): 2371 def __nonzero__(self):
2372 return bool(self._list) 2372 return bool(self._list)
2373 2373
2374 def sort(self, reverse=False): 2374 def sort(self, reverse=False):
2375 self._list.sort(reverse=reverse) 2375 self._ascending = not bool(reverse)
2376 2376
2377 def reverse(self): 2377 def reverse(self):
2378 self._list.reverse() 2378 if self._ascending is None:
2379 self._list.reverse()
2380 else:
2381 self._ascending = not self._ascending
2379 2382
2380 def __len__(self): 2383 def __len__(self):
2381 return len(self._list) 2384 return len(self._list)
2382 2385
2383 def __sub__(self, other): 2386 def __sub__(self, other):
2419 This is part of the mandatory API for smartset.""" 2422 This is part of the mandatory API for smartset."""
2420 return self._ascending is not None and not self._ascending 2423 return self._ascending is not None and not self._ascending
2421 2424
2422 def first(self): 2425 def first(self):
2423 if self: 2426 if self:
2424 return self._list[0] 2427 if self._ascending is None:
2428 return self._list[0]
2429 elif self._ascending:
2430 return self._asclist[0]
2431 else:
2432 return self._asclist[-1]
2425 return None 2433 return None
2426 2434
2427 def last(self): 2435 def last(self):
2428 if self: 2436 if self:
2429 return self._list[-1] 2437 if self._ascending is None:
2438 return self._list[-1]
2439 elif self._ascending:
2440 return self._asclist[-1]
2441 else:
2442 return self._asclist[0]
2430 return None 2443 return None
2431 2444
2432 class filteredset(abstractsmartset): 2445 class filteredset(abstractsmartset):
2433 """Duck type for baseset class which iterates lazily over the revisions in 2446 """Duck type for baseset class which iterates lazily over the revisions in
2434 the subset and contains a function which tests for membership in the 2447 the subset and contains a function which tests for membership in the