--- a/hgext3rd/evolve/stablerange.py Sun Mar 19 03:07:01 2017 +0100
+++ b/hgext3rd/evolve/stablerange.py Sun Mar 19 04:39:00 2017 +0100
@@ -236,6 +236,43 @@
# this class reach.
return self._subrangescache.get(rangeid)
+ def _slicesrangeat(self, repo, rangeid, globalindex):
+ localindex = globalindex - rangeid.index
+
+ cl = repo.changelog
+
+ result = []
+ bottom = rangeid._revs[:localindex]
+ top = stablerange(repo, rangeid.head, globalindex, rangeid._revs[localindex:])
+ #
+ toprootdepth = repo.stablerange.depthrev(repo, top._revs[0])
+ if toprootdepth + len(top) == rangeid.depth + 1:
+ bheads = [bottom[-1]]
+ else:
+ bheads = set(bottom)
+ parentrevs = cl.parentrevs
+ du = bheads.difference_update
+ for r in bottom:
+ du(parentrevs(r))
+ # if len(bheads) == 1:
+ # assert 1 == len(repo.revs('roots(%ld)', top._revs))
+ if len(bheads) == 1:
+ newhead = bottom[-1]
+ bottomdepth = repo.stablerange.depthrev(repo, newhead)
+ newstart = bottomdepth - len(bottom)
+ result.append(stablerange(repo, newhead, newstart, bottom))
+ else:
+ # assert 1 < len(bheads), (toprootdepth, len(top), len(rangeid))
+ cl = repo.changelog
+ for h in bheads:
+ subset = cl.ancestors([h], inclusive=True)
+ hrevs = [r for r in bottom if r in subset]
+ start = repo.stablerange.depthrev(repo, h) - len(hrevs)
+ entry = stablerange(repo, h, start, [r for r in bottom if r in subset])
+ result.append(entry)
+ result.append(top)
+ return result
+
def _hlp2(i):
"""return highest power of two lower than 'i'"""
return 2 ** int(math.log(i - 1, 2))
@@ -287,45 +324,9 @@
assert len(r) == len(self), (self.head, self.index, len(r), len(self))
return r
- def _slicesat(self, globalindex):
- localindex = globalindex - self.index
-
- cl = self._repo.changelog
-
- result = []
- bottom = self._revs[:localindex]
- top = stablerange(self._repo, self.head, globalindex, self._revs[localindex:])
- #
- toprootdepth = self._repo.stablerange.depthrev(self._repo, top._revs[0])
- if toprootdepth + len(top) == self.depth + 1:
- bheads = [bottom[-1]]
- else:
- bheads = set(bottom)
- parentrevs = cl.parentrevs
- du = bheads.difference_update
- for r in bottom:
- du(parentrevs(r))
- # if len(bheads) == 1:
- # assert 1 == len(self._repo.revs('roots(%ld)', top._revs))
- if len(bheads) == 1:
- newhead = bottom[-1]
- bottomdepth = self._repo.stablerange.depthrev(self._repo, newhead)
- newstart = bottomdepth - len(bottom)
- result.append(stablerange(self._repo, newhead, newstart, bottom))
- else:
- # assert 1 < len(bheads), (toprootdepth, len(top), len(self))
- cl = self._repo.changelog
- for h in bheads:
- subset = cl.ancestors([h], inclusive=True)
- hrevs = [r for r in bottom if r in subset]
- start = self._repo.stablerange.depthrev(self._repo, h) - len(hrevs)
- entry = stablerange(self._repo, h, start, [r for r in bottom if r in subset])
- result.append(entry)
- result.append(top)
- return result
-
def subranges(self):
- cached = self._repo.stablerange.subranges(self._repo, self)
+ cache = self._repo.stablerange
+ cached = cache.subranges(self._repo, self)
if cached is not None:
return cached
step = _hlp2(self.depth)
@@ -340,7 +341,7 @@
else:
assert standard_start < self.depth
slicepoint = standard_start
- result = self._slicesat(slicepoint)
+ result = cache._slicesrangeat(self._repo, self, slicepoint)
self._repo.stablerange.setsubranges(self, result)
return result