stablesort: simplify processing of non-merge changesets
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 25 Nov 2017 18:53:23 -0500
changeset 3266 bc173e7f3b6f
parent 3265 70b5bc95efbe
child 3267 f9206b009f48
stablesort: simplify processing of non-merge changesets As long as a changeset as only one parent, the next element in the sort (starting from the head) has to be that parent. We detect and take advantage of that shortcut in the non-merge case.
hgext3rd/evolve/stablesort.py
--- a/hgext3rd/evolve/stablesort.py	Sat Nov 25 18:42:23 2017 -0500
+++ b/hgext3rd/evolve/stablesort.py	Sat Nov 25 18:53:23 2017 -0500
@@ -314,8 +314,23 @@
         return result
 
     def _revsfrom(self, repo, head):
-        for rev in stablesort_mergepoint_head(repo, head)[::-1]:
-            yield rev
+        parentsfunc = repo.changelog.parentrevs
+
+        def parents(rev):
+            return [p for p in parentsfunc(current) if p is not nodemod.nullrev]
+
+        current = head
+        ps = parents(current)
+        while len(ps) == 1:
+            yield current
+            current = ps[0]
+            ps = parents(current)
+
+        if not ps:
+            yield current
+        elif len(ps) == 2:
+            for rev in stablesort_mergepoint_head(repo, current)[::-1]:
+                yield rev
 
 _methodmap = {
     'branchpoint': stablesort_branchpoint,