shrink-revlog: factor out suboptimal computation
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Wed, 10 Mar 2010 09:51:07 +0100
changeset 10626 3fc95c3bc3ba
parent 10625 add562abc28a
child 10627 adcd5bcb37ab
shrink-revlog: factor out suboptimal computation
contrib/shrink-revlog.py
--- a/contrib/shrink-revlog.py	Wed Mar 10 09:48:15 2010 +0100
+++ b/contrib/shrink-revlog.py	Wed Mar 10 09:51:07 2010 +0100
@@ -56,7 +56,6 @@
     visit = list(heads)
     visit.sort(reverse=True)
     finished = set()
-    suboptimal = 0
 
     while visit:
         cur = visit[-1]
@@ -65,16 +64,10 @@
                 visit.append(p)
                 break
         else:
-            curparents = rl.parentrevs(cur)
-            if result and result[-1] != curparents[0]:
-                suboptimal += 1
-
             result.append(cur)
             finished.add(cur)
             visit.pop()
 
-    ui.note(_('%d suboptimal nodes\n') % suboptimal)
-
     return result
 
 def toposort_postorderreverse(ui, rl):
@@ -104,7 +97,6 @@
     visit = list(roots)
     visit.sort()
     finished = set()
-    suboptimal = 0
 
     while visit:
         cur = visit[-1]
@@ -113,19 +105,10 @@
                 visit.append(p)
                 break
         else:
-            # if cur is not the first parent of its successor, then the
-            # successor is a suboptimal node
-            if result:
-                succparents = rl.parentrevs(result[-1])
-                if succparents[0] != cur:
-                    suboptimal += 1
-
             result.append(cur)
             finished.add(cur)
             visit.pop()
 
-    ui.note(_('%d suboptimal nodes\n') % suboptimal)
-
     result.reverse()
     return result
 
@@ -259,6 +242,15 @@
     try:
         try:
             order = toposort(ui, r1)
+
+            suboptimal = 0
+            for i in xrange(1, len(order)):
+                parents = [p for p in r1.parentrevs(order[i])
+                           if p != node.nullrev]
+                if parents and order[i-1] not in parents:
+                    suboptimal += 1
+            ui.note(_('%d suboptimal nodes\n') % suboptimal)
+
             writerevs(ui, r1, r2, order, tr)
             report(ui, r1, r2)
             tr.close()