bisect: merge ancestor lists when pushing to children
authorMatt Mackall <mpm@selenic.com>
Mon, 31 Dec 2007 18:20:34 -0600
changeset 5773 2f6105ab4c54
parent 5772 4c46636eafe5
child 5774 c850a8640981
bisect: merge ancestor lists when pushing to children - eliminate some redundant tests and assignments - move ancestor list merging to child update
hgext/hbisect.py
--- a/hgext/hbisect.py	Mon Dec 31 18:20:34 2007 -0600
+++ b/hgext/hbisect.py	Mon Dec 31 18:20:34 2007 -0600
@@ -64,39 +64,31 @@
             for c in children.get(rev, []):
                 poison[c] = True # poison children
             continue
-        l = ancestors[rev]
+
+        a = ancestors[rev] or [rev]
         ancestors[rev] = None
-        if l != None:
-            if not l:
-                a = [rev]
-            elif len(l) == 1:
-                a = l[0] + [rev]
-            else:
-                a = {}
-                for s in l:
-                    a.update(dict.fromkeys(s))
-                a[rev] = None
-                a = a.keys()
+
+        x = len(a) # number of ancestors
+        y = tot - x # number of non-ancestors
+        value = min(x, y) # how good is this test?
+        if value > best_len and rev not in skip:
+            best_len = value
+            best_rev = rev
+            if value == perfect: # found a perfect candidate? quit early
+                break
 
-            x = len(a) # number of ancestors
-            y = tot - x # number of non-ancestors
-            value = min(x, y) # how good is this test?
-            if value > best_len and rev not in skip:
-                best_len = value
-                best_rev = rev
-                if value == perfect: # found a perfect candidate? quit early
-                    break
+        if y < perfect: # all downhill from here?
+            for c in children.get(rev, []):
+                poison[c] = True # poison children
+            continue
 
-            if y < perfect: # all downhill from here?
-                for c in children.get(rev, []):
-                    poison[c] = True # poison children
-                continue
-
-            for c in children.get(rev, []):
-                if ancestors[c]:
-                    ancestors[c].append(a)
-                else:
-                    ancestors[c] = [a]
+        for c in children.get(rev, []):
+            if ancestors[c]:
+                s = dict.fromkeys(ancestors[c])
+                s.update(dict.fromkeys(a))
+                ancestors[c] = s.keys()
+            else:
+                ancestors[c] = a + [c]
 
     assert best_rev is not None
     best_node = changelog.node(best_rev)