stablesort: extract a '_revsfrom' method
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 25 Nov 2017 18:42:23 -0500
changeset 3265 70b5bc95efbe
parent 3264 383ec26247b3
child 3266 bc173e7f3b6f
stablesort: extract a '_revsfrom' method Walking from the revision is usually simple unless the revision is a merge. Having this walking logic isolated will help us refine it.
hgext3rd/evolve/stablesort.py
--- a/hgext3rd/evolve/stablesort.py	Sun Dec 10 01:48:32 2017 +0100
+++ b/hgext3rd/evolve/stablesort.py	Sat Nov 25 18:42:23 2017 -0500
@@ -305,10 +305,17 @@
 class stablesortcache(object):
 
     def get(self, repo, rev, limit=None):
-        revs = stablesort_mergepoint_head(repo, rev)
-        if limit is None:
-            return revs
-        return revs[-limit:]
+        result = []
+        for r in self._revsfrom(repo, rev):
+            result.append(r)
+            if limit is not None and limit <= len(result):
+                break
+        result.reverse()
+        return result
+
+    def _revsfrom(self, repo, head):
+        for rev in stablesort_mergepoint_head(repo, head)[::-1]:
+            yield rev
 
 _methodmap = {
     'branchpoint': stablesort_branchpoint,