evolve: move _orderrevs() function evolvecmd.py
authorPulkit Goyal <7895pulkit@gmail.com>
Sun, 21 Jan 2018 20:33:39 +0530
changeset 3469 e97bfd529e72
parent 3468 a3052824101d
child 3470 ece5cd58147d
evolve: move _orderrevs() function evolvecmd.py _orderrevs() is a function which is used to order the revs in which the instability needs to be solved if we have multiple revisions to resolve.
hgext3rd/evolve/__init__.py
hgext3rd/evolve/evolvecmd.py
--- a/hgext3rd/evolve/__init__.py	Sun Jan 21 20:28:06 2018 +0530
+++ b/hgext3rd/evolve/__init__.py	Sun Jan 21 20:33:39 2018 +0530
@@ -253,7 +253,6 @@
 """.strip()
 
 import sys
-import collections
 import struct
 
 try:
@@ -947,41 +946,6 @@
     _deprecatealias('gup', 'next')
     _deprecatealias('gdown', 'previous')
 
-def _orderrevs(repo, revs):
-    """Compute an ordering to solve instability for the given revs
-
-    revs is a list of unstable revisions.
-
-    Returns the same revisions ordered to solve their instability from the
-    bottom to the top of the stack that the stabilization process will produce
-    eventually.
-
-    This ensures the minimal number of stabilizations, as we can stabilize each
-    revision on its final stabilized destination.
-    """
-    # Step 1: Build the dependency graph
-    dependencies, rdependencies = utility.builddependencies(repo, revs)
-    # Step 2: Build the ordering
-    # Remove the revisions with no dependency(A) and add them to the ordering.
-    # Removing these revisions leads to new revisions with no dependency (the
-    # one depending on A) that we can remove from the dependency graph and add
-    # to the ordering. We progress in a similar fashion until the ordering is
-    # built
-    solvablerevs = collections.deque([r for r in sorted(dependencies.keys())
-                                      if not dependencies[r]])
-    ordering = []
-    while solvablerevs:
-        rev = solvablerevs.popleft()
-        for dependent in rdependencies[rev]:
-            dependencies[dependent].remove(rev)
-            if not dependencies[dependent]:
-                solvablerevs.append(dependent)
-        del dependencies[rev]
-        ordering.append(rev)
-
-    ordering.extend(sorted(dependencies))
-    return ordering
-
 @eh.command(
     '^evolve|stabilize|solve',
     [('n', 'dry-run', False,
@@ -1180,7 +1144,7 @@
     replacements = {}
     # Order the revisions
     if targetcat == 'orphan':
-        revs = _orderrevs(repo, revs)
+        revs = evolvecmd._orderrevs(repo, revs)
     for rev in revs:
         curctx = repo[rev]
         progresscb()
--- a/hgext3rd/evolve/evolvecmd.py	Sun Jan 21 20:28:06 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Sun Jan 21 20:33:39 2018 +0530
@@ -398,6 +398,41 @@
 class MergeFailure(error.Abort):
     pass
 
+def _orderrevs(repo, revs):
+    """Compute an ordering to solve instability for the given revs
+
+    revs is a list of unstable revisions.
+
+    Returns the same revisions ordered to solve their instability from the
+    bottom to the top of the stack that the stabilization process will produce
+    eventually.
+
+    This ensures the minimal number of stabilizations, as we can stabilize each
+    revision on its final stabilized destination.
+    """
+    # Step 1: Build the dependency graph
+    dependencies, rdependencies = utility.builddependencies(repo, revs)
+    # Step 2: Build the ordering
+    # Remove the revisions with no dependency(A) and add them to the ordering.
+    # Removing these revisions leads to new revisions with no dependency (the
+    # one depending on A) that we can remove from the dependency graph and add
+    # to the ordering. We progress in a similar fashion until the ordering is
+    # built
+    solvablerevs = collections.deque([r for r in sorted(dependencies.keys())
+                                      if not dependencies[r]])
+    ordering = []
+    while solvablerevs:
+        rev = solvablerevs.popleft()
+        for dependent in rdependencies[rev]:
+            dependencies[dependent].remove(rev)
+            if not dependencies[dependent]:
+                solvablerevs.append(dependent)
+        del dependencies[rev]
+        ordering.append(rev)
+
+    ordering.extend(sorted(dependencies))
+    return ordering
+
 def relocate(repo, orig, dest, pctx=None, keepbranch=False):
     """rewrites the orig rev on dest rev