Commits

Erik van Zijst committed 372f898

Took out the defunct inline behind counter and refactored to make ahead and behind separated, parallel pipelines.

  • Participants
  • Parent commits 0834073

Comments (0)

Files changed (1)

     b2c = {}
     c2b = defaultdict(set)
     for bh in [bh for bh in branches if bh != main]:
-        b2c[bh.name] = (set(bh.heads()), 0, 0)
+        b2c[bh.name] = (set(bh.heads()), 0)
         for head in bh.heads():
             c2b[head].add(bh.name)
     mcount = 0
     exclude = set(main.heads())
     include = heads - exclude
 
-    for cs in walker:
+    class Done(Exception):
+        pass
+
+    def ahead(cs):
         if cs in exclude:
-#            print 'exclude', cs.hash, mcount, cs.desc.split('\n')[:1][:30]
             parents = cs.parents()
             include.difference_update(parents)
             exclude.remove(cs)
             exclude.update(parents)
 
             for b in c2b.pop(cs, tuple()):
-                parents, ahead, behind = b2c[b]
+                parents, ahead = b2c[b]
                 parents.remove(cs)
-                b2c[b] = (parents, ahead, mcount)
+                b2c[b] = (parents, ahead)
             if not c2b:
                 # all branches have been terminated
-#                print 'breaking out'
-                break
-            mcount += 1
+                raise Done
 
         elif cs in include:
-#            print 'include', cs.hash, mcount, cs.desc.split('\n')[:1][:30]
             include.remove(cs)
             bnames = c2b.pop(cs)
             liveparents = set(cs.parents()) - exclude
 
             for b in bnames:
-                next, ahead, behind = b2c[b]
+                next, ahead = b2c[b]
                 next.remove(cs)
                 next.update(liveparents)
-                b2c[b] = (next, ahead + 1, mcount)
+                b2c[b] = (next, ahead + 1)
 
             for p in liveparents:
-#                print 'add live parent', p.hash, mcount, p.desc.split('\n')[:1][:30]
                 c2b[p].update(bnames)
-#            else:
-#                print 'dead parents', cs.parents(), exclude
             include.update(liveparents)
         else:
             print 'WTF', cs.hash, cs.desc.split('\n')[:1][:30]
 
+    funcs = {ahead}
+    dead = set()
+
+    for cs in walker:
+        if not funcs:
+            break
+        for func in funcs:
+            try:
+                func(cs)
+            except Done:
+                dead.add(func)
+
+        while dead:
+            funcs.remove(dead.pop())
+
 duration = time.time() - start
 for bname, stats in b2c.items():
-    print '%s [%d ahead] [%s behind] on %s' % (bname, stats[1], stats[2], main.name)
+    print '%s [%d ahead] on %s' % (bname, stats[1], main.name)
     if stats[0]:
         print 'ERROR: parent nodes left for branch %s: %s' % (bname, stats[0])
 print 'runtime: %.3f seconds' % duration