builddependencies: build inverse dict from forward dict
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 25 Jul 2018 14:33:48 -0700
changeset 3904 d2d03df3956f
parent 3903 038cdaca7145
child 3905 4806d1339c30
builddependencies: build inverse dict from forward dict It's error-prone to keep "dependencies" and "rdependencies" in sync (we don't do it correctly when there are multiple successors or a node). It's easier to just create "rependencies" from "dependencies" after it's complete.
hgext3rd/evolve/utility.py
--- a/hgext3rd/evolve/utility.py	Wed Jul 25 14:21:49 2018 -0700
+++ b/hgext3rd/evolve/utility.py	Wed Jul 25 14:33:48 2018 -0700
@@ -92,8 +92,6 @@
     # dependencies = {3: [6], 6:[]}
     # Means that: 6 has no dependency, 3 depends on 6 to be solved
     dependencies = {}
-    # rdependencies is the inverted dict of dependencies
-    rdependencies = {r: set() for r in revs}
 
     for r in revs:
         dependencies[r] = set()
@@ -111,7 +109,13 @@
                 continue
             if succ in revs:
                 dependencies[r].add(succ)
-                rdependencies[succ].add(r)
+
+    # rdependencies is the inverted dict of dependencies
+    rdependencies = {r: set() for r in revs}
+    for r, deps in dependencies.items():
+        for dep in deps:
+            rdependencies[dep].add(r)
+
     return dependencies, rdependencies
 
 def _singlesuccessor(repo, p):