smartset: preserve istopo for baseset operations
authorJun Wu <quark@fb.com>
Tue, 21 Feb 2017 16:29:31 -0800
changeset 35956 c962bb6af90965263dd265f73d939cb66688f3d1
parent 35955 88203f26ea57627cabd7cf9c4f7843661d6c43ae
child 35957 a0bde5ec3a46ecd791fdf8de828d372e2d2572c0
push id461
push usergszorc@mozilla.com
push dateThu, 02 Mar 2017 23:57:55 +0000
smartset: preserve istopo for baseset operations This is a follow-up of "smartset: use native set operations as fast paths". It's more correct to just preserve the "istopo" information for "&" and "-" operations, like what filteredset does.
mercurial/smartset.py
--- a/mercurial/smartset.py
+++ b/mercurial/smartset.py
@@ -198,16 +198,24 @@ class baseset(abstractsmartset):
     >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
     ['addset', 'baseset', 'baseset']
 
     >>> ys.sort()
     >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]]
     [[7, 6, 4, 0, 3, 5], [7, 6], [4, 0]]
     >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]]
     ['addset', 'baseset', 'baseset']
+
+    istopo is preserved across set operations
+    >>> xs = baseset(set(x), istopo=True)
+    >>> rs = xs & ys
+    >>> type(rs).__name__
+    'baseset'
+    >>> rs._istopo
+    True
     """
     def __init__(self, data=(), datarepr=None, istopo=False):
         """
         datarepr: a tuple of (format, obj, ...), a function or an object that
                   provides a printable representation of the given data.
         """
         self._ascending = None
         self._istopo = istopo
@@ -321,17 +329,18 @@ class baseset(abstractsmartset):
             else:
                 return self._asclist[0]
         return None
 
     def _fastsetop(self, other, op):
         # try to use native set operations as fast paths
         if (type(other) is baseset and '_set' in other.__dict__ and '_set' in
             self.__dict__ and self._ascending is not None):
-            s = baseset(data=getattr(self._set, op)(other._set))
+            s = baseset(data=getattr(self._set, op)(other._set),
+                        istopo=self._istopo)
             s._ascending = self._ascending
         else:
             s = getattr(super(baseset, self), op)(other)
         return s
 
     def __and__(self, other):
         return self._fastsetop(other, '__and__')