[PATCH] revset: added smartset attribute to new classes to test at mfunc and getset

Lucas Moscovicz lmoscovicz at fb.com
Tue Feb 18 18:13:10 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1392767686 28800
#      Tue Feb 18 15:54:46 2014 -0800
# Node ID d9813f85f80e36e413da7bd1b5edd3a2118bc715
# Parent  c29948fed40a2d9755ecaa01ec05bfa542f65670
revset: added smartset attribute to new classes to test at mfunc and getset

Now extensions shouldn't break when adding new revsets.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -195,7 +195,10 @@
 def getset(repo, subset, x):
     if not x:
         raise error.ParseError(_("missing argument"))
-    return methods[x[0]](repo, subset, *x[1:])
+    s = methods[x[0]](repo, subset, *x[1:])
+    if util.safehasattr(s, 'smartset'):
+        return s
+    return baseset(s)
 
 def _getrevsource(repo, r):
     extra = repo[r].extra()
@@ -1919,7 +1922,9 @@
         tree = findaliases(ui, tree)
     weight, tree = optimize(tree, True)
     def mfunc(repo, subset):
-        return getset(repo, subset, tree)
+        if util.safehasattr(subset, 'smartset'):
+            return getset(repo, subset, tree)
+        return getset(repo, baseset(subset), tree)
     return mfunc
 
 def formatspec(expr, *args):
@@ -2052,6 +2057,8 @@
     """Basic data structure that represents a revset and contains the basic
     operation that it should be able to perform.
     """
+    smartset = True
+
     def __init__(self, data):
         super(baseset, self).__init__(data)
         self._set = None
@@ -2083,6 +2090,8 @@
     the subset and contains a function which tests for membership in the
     revset
     """
+    smartset = True
+
     def __init__(self, subset, condition):
         self._subset = subset
         self._condition = condition
@@ -2135,6 +2144,8 @@
     """Duck type for baseset class which represents a range of revisions and
     can work lazily and without having all the range in memory
     """
+    smartset = True
+
     def __init__(self, repo, start=0, end=None):
         self._start = start
         if end is not None:


More information about the Mercurial-devel mailing list