Patchwork D530: obsolete: move merge logic on the smaller object

login
register
mail settings
Submitter phabricator
Date Aug. 28, 2017, 2:40 p.m.
Message ID <88278b5565dac7a29e59d88923c4aff9@localhost.localdomain>
Download mbox | patch
Permalink /patch/23400/
State Not Applicable
Headers show

Comments

phabricator - Aug. 28, 2017, 2:40 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGc0bbaefc2c5a: obsolete: move merge logic on the smaller object (authored by lothiraldan).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D530?vs=1334&id=1353

REVISION DETAIL
  https://phab.mercurial-scm.org/D530

AFFECTED FILES
  mercurial/obsutil.py

CHANGE DETAILS




To: lothiraldan, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py
--- a/mercurial/obsutil.py
+++ b/mercurial/obsutil.py
@@ -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]