296 class stablerangecached(abstractstablerange): |
296 class stablerangecached(abstractstablerange): |
297 """an implementation of stablerange using caching""" |
297 """an implementation of stablerange using caching""" |
298 |
298 |
299 __metaclass__ = abc.ABCMeta |
299 __metaclass__ = abc.ABCMeta |
300 |
300 |
|
301 def __init__(self): |
|
302 # cache the standard stable subranges or a range |
|
303 self._subrangescache = {} |
|
304 super(stablerangecached, self).__init__() |
|
305 |
301 def depthrev(self, repo, rev): |
306 def depthrev(self, repo, rev): |
302 return repo.depthcache.get(rev) |
307 return repo.depthcache.get(rev) |
303 |
308 |
304 def rangelength(self, repo, rangeid): |
309 def rangelength(self, repo, rangeid): |
305 """number of revision in <range>""" |
310 """number of revision in <range>""" |
306 headrev, index = rangeid[0], rangeid[1] |
311 headrev, index = rangeid[0], rangeid[1] |
307 return self.depthrev(repo, headrev) - index |
312 return self.depthrev(repo, headrev) - index |
|
313 |
|
314 def subranges(self, repo, rangeid): |
|
315 cached = self._getsub(rangeid) |
|
316 if cached is not None: |
|
317 return cached |
|
318 value = self._subranges(repo, rangeid) |
|
319 self._setsub(rangeid, value) |
|
320 return value |
|
321 |
|
322 def _getsub(self, rev): |
|
323 """utility function used to access the subranges cache |
|
324 |
|
325 This mostly exist to help the on disk persistence""" |
|
326 return self._subrangescache.get(rev) |
|
327 |
|
328 def _setsub(self, rev, value): |
|
329 """utility function used to set the subranges cache |
|
330 |
|
331 This mostly exist to help the on disk persistence.""" |
|
332 self._subrangescache[rev] = value |
308 |
333 |
309 class stablerange_mergepoint(stablerangecached, stablerangebasic): |
334 class stablerange_mergepoint(stablerangecached, stablerangebasic): |
310 """Stablerange implementation using 'mergepoint' based sorting |
335 """Stablerange implementation using 'mergepoint' based sorting |
311 """ |
336 """ |
312 |
337 |
348 else: |
373 else: |
349 tiebreaker = stablesort._mergepoint_tie_breaker(repo) |
374 tiebreaker = stablesort._mergepoint_tie_breaker(repo) |
350 relevant_parent = min(p1, p2, key=tiebreaker) |
375 relevant_parent = min(p1, p2, key=tiebreaker) |
351 return relevant_parent |
376 return relevant_parent |
352 |
377 |
353 def subranges(self, repo, rangeid): |
378 def _subranges(self, repo, rangeid): |
354 headrev, initial_index = rangeid |
379 headrev, initial_index = rangeid |
355 # size 1 range can't be sliced |
380 # size 1 range can't be sliced |
356 if self.rangelength(repo, rangeid) == 1: |
381 if self.rangelength(repo, rangeid) == 1: |
357 return [] |
382 return [] |
358 # find were we need to slice |
383 # find were we need to slice |
435 |
460 |
436 def __init__(self, lrusize=2000): |
461 def __init__(self, lrusize=2000): |
437 # The point up to which we have data in cache |
462 # The point up to which we have data in cache |
438 self._tiprev = None |
463 self._tiprev = None |
439 self._tipnode = None |
464 self._tipnode = None |
440 # cache the standard stable subranges or a range |
|
441 self._subrangescache = {} |
|
442 # To slices merge, we need to walk their descendant in reverse stable |
465 # To slices merge, we need to walk their descendant in reverse stable |
443 # sort order. For now we perform a full stable sort their descendant |
466 # sort order. For now we perform a full stable sort their descendant |
444 # and then use the relevant top most part. This order is going to be |
467 # and then use the relevant top most part. This order is going to be |
445 # the same for all ranges headed at the same merge. So we cache these |
468 # the same for all ranges headed at the same merge. So we cache these |
446 # value to reuse them accross the same invocation. |
469 # value to reuse them accross the same invocation. |
453 # The first part of the stable sorted list of revision of a merge will |
476 # The first part of the stable sorted list of revision of a merge will |
454 # shared with the one of others. This means we can reuse subranges |
477 # shared with the one of others. This means we can reuse subranges |
455 # computed from that point to compute some of the subranges from the |
478 # computed from that point to compute some of the subranges from the |
456 # merge. |
479 # merge. |
457 self._inheritancecache = {} |
480 self._inheritancecache = {} |
|
481 super(stablerange, self).__init__() |
458 |
482 |
459 def warmup(self, repo, upto=None): |
483 def warmup(self, repo, upto=None): |
460 """warm the cache up""" |
484 """warm the cache up""" |
461 repo = repo.unfiltered() |
485 repo = repo.unfiltered() |
462 repo.depthcache.update(repo) |
486 repo.depthcache.update(repo) |