obsolete: move merge logic on the smaller object
authorBoris Feld <boris.feld@octobus.net>
Mon, 03 Jul 2017 03:54:24 +0200
changeset 33941 c0bbaefc2c5a
parent 33940 2a37459aedf2
child 33942 54c21114e41d
obsolete: move merge logic on the smaller object Refactor some logic in _succs in order to clean successorssets code. Differential Revision: https://phab.mercurial-scm.org/D530
mercurial/obsutil.py
--- a/mercurial/obsutil.py	Mon Aug 28 04:11:58 2017 +0530
+++ b/mercurial/obsutil.py	Mon Jul 03 03:54:24 2017 +0200
@@ -339,6 +339,14 @@
         new.markers = self.markers.copy()
         return new
 
+    @util.propertycache
+    def _set(self):
+        # immutable
+        return set(self)
+
+    def canmerge(self, other):
+        return self._set.issubset(other._set)
+
 def successorssets(repo, initialnode, closest=False, cache=None):
     """Return set of all latest successors of initial nodes
 
@@ -554,16 +562,16 @@
                 # remove duplicated and subset
                 seen = []
                 final = []
-                candidate = sorted(((set(s), s) for s in succssets if s),
-                                   key=lambda x: len(x[1]), reverse=True)
-                for setversion, listversion in candidate:
-                    for seenset, seensuccs in seen:
-                        if setversion.issubset(seenset):
-                            seensuccs.markers.update(listversion.markers)
+                candidate = sorted((s for s in succssets if s),
+                                   key=len, reverse=True)
+                for cand in candidate:
+                    for seensuccs in seen:
+                        if cand.canmerge(seensuccs):
+                            seensuccs.markers.update(cand.markers)
                             break
                     else:
-                        final.append(listversion)
-                        seen.append((setversion, listversion))
+                        final.append(cand)
+                        seen.append(cand)
                 final.reverse() # put small successors set first
                 cache[current] = final
     return cache[initialnode]