changeset 33959:c0bbaefc2c5a

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
author Boris Feld <boris.feld@octobus.net>
date Mon, 03 Jul 2017 03:54:24 +0200
parents 2a37459aedf2
children 54c21114e41d
files mercurial/obsutil.py
diffstat 1 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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]