[PATCH 1 of 4] revset: added baseset class (still empty) to improve revset performance

Lucas Moscovicz lmoscovicz at fb.com
Mon Feb 3 13:44:32 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1390333166 28800
#      Tue Jan 21 11:39:26 2014 -0800
# Node ID f41001b383d8006c4e1949ffe2c377849767de47
# Parent  4bc8f4e3c00a608ec93f7f7c07fa3ccbdb759608
revset: added baseset class (still empty) to improve revset performance

This class is going to be used to cache the set that is created from this list
in many cases while evaluating a revset.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1132,7 +1132,7 @@
     elif follow:
         revs = repo.revs('reverse(:.)')
     else:
-        revs = list(repo)
+        revs = revset.baseset(repo)
         revs.reverse()
     if not revs:
         return []
@@ -1140,6 +1140,7 @@
     slowpath = match.anypats() or (match.files() and opts.get('removed'))
     fncache = {}
     change = repo.changectx
+    revs = revset.baseset(revs)
 
     # First step is to fill wanted, the set of revisions that we want to yield.
     # When it does not induce extra cost, we also fill fncache for revisions in
@@ -1471,10 +1472,11 @@
         if follow and len(repo) > 0:
             revs = repo.revs('reverse(:.)')
         else:
-            revs = list(repo.changelog)
+            revs = revset.baseset(repo.changelog)
             revs.reverse()
     if not revs:
         return [], None, None
+    revs = revset.baseset(revs)
     expr, filematcher = _makegraphlogrevset(repo, pats, opts, revs)
     if possiblyunsorted:
         revs.sort(reverse=True)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2527,7 +2527,7 @@
         if newtree != tree:
             ui.note(revset.prettyformat(newtree), "\n")
     func = revset.match(ui, expr)
-    for c in func(repo, range(len(repo))):
+    for c in func(repo, revset.baseset(range(len(repo)))):
         ui.write("%s\n" % c)
 
 @command('debugsetparents', [], _('REV1 [REV2]'))
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -187,7 +187,7 @@
 
         mfunc = revset.match(web.repo.ui, revdef)
         try:
-            revs = mfunc(web.repo, list(web.repo))
+            revs = mfunc(web.repo, revset.baseset(web.repo))
             return MODE_REVSET, revs
             # ParseError: wrongly placed tokens, wrongs arguments, etc
             # RepoLookupError: no such revision, e.g. in 'revision:'
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -438,7 +438,7 @@
         '''Return a list of revisions matching the given revset'''
         expr = revset.formatspec(expr, *args)
         m = revset.match(None, expr)
-        return [r for r in m(self, list(self))]
+        return revset.baseset([r for r in m(self, revset.baseset(self))])
 
     def set(self, expr, *args):
         '''
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -52,9 +52,9 @@
     """Return all paths between roots and heads, inclusive of both endpoint
     sets."""
     if not roots:
-        return []
+        return baseset([])
     parentrevs = repo.changelog.parentrevs
-    visit = heads[:]
+    visit = baseset(heads)
     reachable = set()
     seen = {}
     minroot = min(roots)
@@ -71,12 +71,12 @@
             if parent >= minroot and parent not in seen:
                 visit.append(parent)
     if not reachable:
-        return []
+        return baseset([])
     for rev in sorted(seen):
         for parent in seen[rev]:
             if parent in reachable:
                 reachable.add(rev)
-    return sorted(reachable)
+    return baseset(sorted(reachable))
 
 elements = {
     "(": (20, ("group", 1, ")"), ("func", 1, ")")),
@@ -194,7 +194,7 @@
 def getset(repo, subset, x):
     if not x:
         raise error.ParseError(_("missing argument"))
-    return methods[x[0]](repo, subset, *x[1:])
+    return baseset(methods[x[0]](repo, subset, *x[1:]))
 
 def _getrevsource(repo, r):
     extra = repo[r].extra()
@@ -211,10 +211,10 @@
 def stringset(repo, subset, x):
     x = repo[x].rev()
     if x == -1 and len(subset) == len(repo):
-        return [-1]
+        return baseset([-1])
     if len(subset) == len(repo) or x in subset:
-        return [x]
-    return []
+        return baseset([x])
+    return baseset([])
 
 def symbolset(repo, subset, x):
     if x in symbols:
@@ -222,12 +222,12 @@
     return stringset(repo, subset, x)
 
 def rangeset(repo, subset, x, y):
-    cl = repo.changelog
+    cl = baseset(repo.changelog)
     m = getset(repo, cl, x)
     n = getset(repo, cl, y)
 
     if not m or not n:
-        return []
+        return baseset([])
     m, n = m[0], n[-1]
 
     if m < n:
@@ -235,13 +235,13 @@
     else:
         r = range(m, n - 1, -1)
     s = set(subset)
-    return [x for x in r if x in s]
+    return baseset([x for x in r if x in s])
 
 def dagrange(repo, subset, x, y):
-    r = list(repo)
+    r = baseset(repo)
     xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
     s = set(subset)
-    return [r for r in xs if r in s]
+    return baseset([r for r in xs if r in s])
 
 def andset(repo, subset, x, y):
     return getset(repo, getset(repo, subset, x), y)
@@ -250,11 +250,11 @@
     xl = getset(repo, subset, x)
     s = set(xl)
     yl = getset(repo, [r for r in subset if r not in s], y)
-    return xl + yl
+    return baseset(xl + yl)
 
 def notset(repo, subset, x):
     s = set(getset(repo, subset, x))
-    return [r for r in subset if r not in s]
+    return baseset([r for r in subset if r not in s])
 
 def listset(repo, subset, a, b):
     raise error.ParseError(_("can't use a list in this context"))
@@ -284,7 +284,7 @@
     """
     # i18n: "ancestor" is a keyword
     l = getlist(x)
-    rl = list(repo)
+    rl = baseset(repo)
     anc = None
 
     # (getset(repo, rl, i) for i in l) generates a list of lists
@@ -299,15 +299,15 @@
                 anc = rev(ancestor(node(anc), node(r)))
 
     if anc is not None and anc in subset:
-        return [anc]
-    return []
+        return baseset([anc])
+    return baseset([])
 
 def _ancestors(repo, subset, x, followfirst=False):
-    args = getset(repo, list(repo), x)
+    args = getset(repo, baseset(repo), x)
     if not args:
-        return []
+        return baseset([])
     s = set(_revancestors(repo, args, followfirst)) | set(args)
-    return [r for r in subset if r in s]
+    return baseset([r for r in subset if r in s])
 
 def ancestors(repo, subset, x):
     """``ancestors(set)``
@@ -335,7 +335,7 @@
         for i in range(n):
             r = cl.parentrevs(r)[0]
         ps.add(r)
-    return [r for r in subset if r in ps]
+    return baseset([r for r in subset if r in ps])
 
 def author(repo, subset, x):
     """``author(string)``
@@ -344,7 +344,8 @@
     # i18n: "author" is a keyword
     n = encoding.lower(getstring(x, _("author requires a string")))
     kind, pattern, matcher = _substringmatcher(n)
-    return [r for r in subset if matcher(encoding.lower(repo[r].user()))]
+    return baseset([r for r in subset if
+        matcher(encoding.lower(repo[r].user()))])
 
 def bisect(repo, subset, x):
     """``bisect(string)``
@@ -361,7 +362,7 @@
     # i18n: "bisect" is a keyword
     status = getstring(x, _("bisect requires a string")).lower()
     state = set(hbisect.get(repo, status))
-    return [r for r in subset if r in state]
+    return baseset([r for r in subset if r in state])
 
 # Backward-compatibility
 # - no help entry so that we do not advertise it any more
@@ -388,7 +389,7 @@
             if not bmrev:
                 raise util.Abort(_("bookmark '%s' does not exist") % bm)
             bmrev = repo[bmrev].rev()
-            return [r for r in subset if r == bmrev]
+            return baseset([r for r in subset if r == bmrev])
         else:
             matchrevs = set()
             for name, bmrev in repo._bookmarks.iteritems():
@@ -400,11 +401,11 @@
             bmrevs = set()
             for bmrev in matchrevs:
                 bmrevs.add(repo[bmrev].rev())
-            return [r for r in subset if r in bmrevs]
+            return baseset([r for r in subset if r in bmrevs])
 
     bms = set([repo[r].rev()
                for r in repo._bookmarks.values()])
-    return [r for r in subset if r in bms]
+    return baseset([r for r in subset if r in bms])
 
 def branch(repo, subset, x):
     """``branch(string or set)``
@@ -426,16 +427,16 @@
             # note: falls through to the revspec case if no branch with
             # this name exists
             if pattern in repo.branchmap():
-                return [r for r in subset if matcher(repo[r].branch())]
+                return baseset([r for r in subset if matcher(repo[r].branch())])
         else:
-            return [r for r in subset if matcher(repo[r].branch())]
+            return baseset([r for r in subset if matcher(repo[r].branch())])
 
-    s = getset(repo, list(repo), x)
+    s = getset(repo, baseset(repo), x)
     b = set()
     for r in s:
         b.add(repo[r].branch())
     s = set(s)
-    return [r for r in subset if r in s or repo[r].branch() in b]
+    return baseset([r for r in subset if r in s or repo[r].branch() in b])
 
 def bumped(repo, subset, x):
     """``bumped()``
@@ -446,7 +447,7 @@
     # i18n: "bumped" is a keyword
     getargs(x, 0, 0, _("bumped takes no arguments"))
     bumped = obsmod.getrevs(repo, 'bumped')
-    return [r for r in subset if r in bumped]
+    return baseset([r for r in subset if r in bumped])
 
 def bundle(repo, subset, x):
     """``bundle()``
@@ -458,7 +459,7 @@
         bundlerevs = repo.changelog.bundlerevs
     except AttributeError:
         raise util.Abort(_("no bundle provided - specify with -R"))
-    return [r for r in subset if r in bundlerevs]
+    return baseset([r for r in subset if r in bundlerevs])
 
 def checkstatus(repo, subset, pat, field):
     m = None
@@ -489,12 +490,12 @@
                 if m(f):
                     s.append(r)
                     break
-    return s
+    return baseset(s)
 
 def _children(repo, narrow, parentset):
     cs = set()
     if not parentset:
-        return cs
+        return baseset(cs)
     pr = repo.changelog.parentrevs
     minrev = min(parentset)
     for r in narrow:
@@ -503,15 +504,15 @@
         for p in pr(r):
             if p in parentset:
                 cs.add(r)
-    return cs
+    return baseset(cs)
 
 def children(repo, subset, x):
     """``children(set)``
     Child changesets of changesets in set.
     """
-    s = set(getset(repo, list(repo), x))
+    s = set(getset(repo, baseset(repo), x))
     cs = _children(repo, subset, s)
-    return [r for r in subset if r in cs]
+    return baseset([r for r in subset if r in cs])
 
 def closed(repo, subset, x):
     """``closed()``
@@ -519,7 +520,7 @@
     """
     # i18n: "closed" is a keyword
     getargs(x, 0, 0, _("closed takes no arguments"))
-    return [r for r in subset if repo[r].closesbranch()]
+    return baseset([r for r in subset if repo[r].closesbranch()])
 
 def contains(repo, subset, x):
     """``contains(pattern)``
@@ -543,7 +544,7 @@
                 if m(f):
                     s.append(r)
                     break
-    return s
+    return baseset(s)
 
 def converted(repo, subset, x):
     """``converted([id])``
@@ -565,7 +566,7 @@
         source = repo[r].extra().get('convert_revision', None)
         return source is not None and (rev is None or source.startswith(rev))
 
-    return [r for r in subset if _matchvalue(r)]
+    return baseset([r for r in subset if _matchvalue(r)])
 
 def date(repo, subset, x):
     """``date(interval)``
@@ -574,7 +575,7 @@
     # i18n: "date" is a keyword
     ds = getstring(x, _("date requires a string"))
     dm = util.matchdate(ds)
-    return [r for r in subset if dm(repo[r].date()[0])]
+    return baseset([r for r in subset if dm(repo[r].date()[0])])
 
 def desc(repo, subset, x):
     """``desc(string)``
@@ -587,14 +588,14 @@
         c = repo[r]
         if ds in encoding.lower(c.description()):
             l.append(r)
-    return l
+    return baseset(l)
 
 def _descendants(repo, subset, x, followfirst=False):
-    args = getset(repo, list(repo), x)
+    args = getset(repo, baseset(repo), x)
     if not args:
-        return []
+        return baseset([])
     s = set(_revdescendants(repo, args, followfirst)) | set(args)
-    return [r for r in subset if r in s]
+    return baseset([r for r in subset if r in s])
 
 def descendants(repo, subset, x):
     """``descendants(set)``
@@ -614,9 +615,9 @@
     is the same as passing all().
     """
     if x is not None:
-        args = set(getset(repo, list(repo), x))
+        args = set(getset(repo, baseset(repo), x))
     else:
-        args = set(getall(repo, list(repo), x))
+        args = set(getall(repo, baseset(repo), x))
 
     dests = set()
 
@@ -649,7 +650,7 @@
             r = src
             src = _getrevsource(repo, r)
 
-    return [r for r in subset if r in dests]
+    return baseset([r for r in subset if r in dests])
 
 def divergent(repo, subset, x):
     """``divergent()``
@@ -658,7 +659,7 @@
     # i18n: "divergent" is a keyword
     getargs(x, 0, 0, _("divergent takes no arguments"))
     divergent = obsmod.getrevs(repo, 'divergent')
-    return [r for r in subset if r in divergent]
+    return baseset([r for r in subset if r in divergent])
 
 def draft(repo, subset, x):
     """``draft()``
@@ -666,7 +667,7 @@
     # i18n: "draft" is a keyword
     getargs(x, 0, 0, _("draft takes no arguments"))
     pc = repo._phasecache
-    return [r for r in subset if pc.phase(repo, r) == phases.draft]
+    return baseset([r for r in subset if pc.phase(repo, r) == phases.draft])
 
 def extinct(repo, subset, x):
     """``extinct()``
@@ -675,7 +676,7 @@
     # i18n: "extinct" is a keyword
     getargs(x, 0, 0, _("extinct takes no arguments"))
     extincts = obsmod.getrevs(repo, 'extinct')
-    return [r for r in subset if r in extincts]
+    return baseset([r for r in subset if r in extincts])
 
 def extra(repo, subset, x):
     """``extra(label, [value])``
@@ -702,7 +703,7 @@
         extra = repo[r].extra()
         return label in extra and (value is None or matcher(extra[label]))
 
-    return [r for r in subset if _matchvalue(r)]
+    return baseset([r for r in subset if _matchvalue(r)])
 
 def filelog(repo, subset, x):
     """``filelog(pattern)``
@@ -731,7 +732,7 @@
                 for fr in fl:
                     s.add(fl.linkrev(fr))
 
-    return [r for r in subset if r in s]
+    return baseset([r for r in subset if r in s])
 
 def first(repo, subset, x):
     """``first(set, [n])``
@@ -750,11 +751,11 @@
             # include the revision responsible for the most recent version
             s.add(cx.linkrev())
         else:
-            return []
+            return baseset([])
     else:
         s = set(_revancestors(repo, [c.rev()], followfirst)) | set([c.rev()])
 
-    return [r for r in subset if r in s]
+    return baseset([r for r in subset if r in s])
 
 def follow(repo, subset, x):
     """``follow([file])``
@@ -796,7 +797,7 @@
             if gr.search(e):
                 l.append(r)
                 break
-    return l
+    return baseset(l)
 
 def _matchfiles(repo, subset, x):
     # _matchfiles takes a revset list of prefixed arguments:
@@ -859,7 +860,7 @@
             if m(f):
                 s.append(r)
                 break
-    return s
+    return baseset(s)
 
 def hasfile(repo, subset, x):
     """``file(pattern)``
@@ -881,7 +882,7 @@
     hs = set()
     for b, ls in repo.branchmap().iteritems():
         hs.update(repo[h].rev() for h in ls)
-    return [r for r in subset if r in hs]
+    return baseset([r for r in subset if r in hs])
 
 def heads(repo, subset, x):
     """``heads(set)``
@@ -889,7 +890,7 @@
     """
     s = getset(repo, subset, x)
     ps = set(parents(repo, subset, x))
-    return [r for r in s if r not in ps]
+    return baseset([r for r in s if r not in ps])
 
 def hidden(repo, subset, x):
     """``hidden()``
@@ -898,7 +899,7 @@
     # i18n: "hidden" is a keyword
     getargs(x, 0, 0, _("hidden takes no arguments"))
     hiddenrevs = repoview.filterrevs(repo, 'visible')
-    return [r for r in subset if r in hiddenrevs]
+    return baseset([r for r in subset if r in hiddenrevs])
 
 def keyword(repo, subset, x):
     """``keyword(string)``
@@ -913,7 +914,7 @@
         if util.any(kw in encoding.lower(t)
                     for t in c.files() + [c.user(), c.description()]):
             l.append(r)
-    return l
+    return baseset(l)
 
 def limit(repo, subset, x):
     """``limit(set, [n])``
@@ -930,8 +931,8 @@
         # i18n: "limit" is a keyword
         raise error.ParseError(_("limit expects a number"))
     ss = set(subset)
-    os = getset(repo, list(repo), l[0])[:lim]
-    return [r for r in os if r in ss]
+    os = getset(repo, baseset(repo), l[0])[:lim]
+    return baseset([r for r in os if r in ss])
 
 def last(repo, subset, x):
     """``last(set, [n])``
@@ -948,19 +949,19 @@
         # i18n: "last" is a keyword
         raise error.ParseError(_("last expects a number"))
     ss = set(subset)
-    os = getset(repo, list(repo), l[0])[-lim:]
-    return [r for r in os if r in ss]
+    os = getset(repo, baseset(repo), l[0])[-lim:]
+    return baseset([r for r in os if r in ss])
 
 def maxrev(repo, subset, x):
     """``max(set)``
     Changeset with highest revision number in set.
     """
-    os = getset(repo, list(repo), x)
+    os = getset(repo, baseset(repo), x)
     if os:
         m = max(os)
         if m in subset:
-            return [m]
-    return []
+            return baseset([m])
+    return baseset([])
 
 def merge(repo, subset, x):
     """``merge()``
@@ -969,7 +970,7 @@
     # i18n: "merge" is a keyword
     getargs(x, 0, 0, _("merge takes no arguments"))
     cl = repo.changelog
-    return [r for r in subset if cl.parentrevs(r)[1] != -1]
+    return baseset([r for r in subset if cl.parentrevs(r)[1] != -1])
 
 def branchpoint(repo, subset, x):
     """``branchpoint()``
@@ -979,25 +980,25 @@
     getargs(x, 0, 0, _("branchpoint takes no arguments"))
     cl = repo.changelog
     if not subset:
-        return []
+        return baseset([])
     baserev = min(subset)
     parentscount = [0]*(len(repo) - baserev)
     for r in cl.revs(start=baserev + 1):
         for p in cl.parentrevs(r):
             if p >= baserev:
                 parentscount[p - baserev] += 1
-    return [r for r in subset if (parentscount[r - baserev] > 1)]
+    return baseset([r for r in subset if (parentscount[r - baserev] > 1)])
 
 def minrev(repo, subset, x):
     """``min(set)``
     Changeset with lowest revision number in set.
     """
-    os = getset(repo, list(repo), x)
+    os = getset(repo, baseset(repo), x)
     if os:
         m = min(os)
         if m in subset:
-            return [m]
-    return []
+            return baseset([m])
+    return baseset([])
 
 def modifies(repo, subset, x):
     """``modifies(pattern)``
@@ -1023,7 +1024,7 @@
         if pm is not None:
             rn = repo.changelog.rev(pm)
 
-    return [r for r in subset if r == rn]
+    return baseset([r for r in subset if r == rn])
 
 def obsolete(repo, subset, x):
     """``obsolete()``
@@ -1031,7 +1032,7 @@
     # i18n: "obsolete" is a keyword
     getargs(x, 0, 0, _("obsolete takes no arguments"))
     obsoletes = obsmod.getrevs(repo, 'obsolete')
-    return [r for r in subset if r in obsoletes]
+    return baseset([r for r in subset if r in obsoletes])
 
 def origin(repo, subset, x):
     """``origin([set])``
@@ -1042,9 +1043,9 @@
     for the first operation is selected.
     """
     if x is not None:
-        args = set(getset(repo, list(repo), x))
+        args = set(getset(repo, baseset(repo), x))
     else:
-        args = set(getall(repo, list(repo), x))
+        args = set(getall(repo, baseset(repo), x))
 
     def _firstsrc(rev):
         src = _getrevsource(repo, rev)
@@ -1059,7 +1060,7 @@
             src = prev
 
     o = set([_firstsrc(r) for r in args])
-    return [r for r in subset if r in o]
+    return baseset([r for r in subset if r in o])
 
 def outgoing(repo, subset, x):
     """``outgoing([path])``
@@ -1082,7 +1083,7 @@
     repo.ui.popbuffer()
     cl = repo.changelog
     o = set([cl.rev(r) for r in outgoing.missing])
-    return [r for r in subset if r in o]
+    return baseset([r for r in subset if r in o])
 
 def p1(repo, subset, x):
     """``p1([set])``
@@ -1090,13 +1091,13 @@
     """
     if x is None:
         p = repo[x].p1().rev()
-        return [r for r in subset if r == p]
+        return baseset([r for r in subset if r == p])
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, list(repo), x):
+    for r in getset(repo, baseset(repo), x):
         ps.add(cl.parentrevs(r)[0])
-    return [r for r in subset if r in ps]
+    return baseset([r for r in subset if r in ps])
 
 def p2(repo, subset, x):
     """``p2([set])``
@@ -1106,15 +1107,15 @@
         ps = repo[x].parents()
         try:
             p = ps[1].rev()
-            return [r for r in subset if r == p]
+            return baseset([r for r in subset if r == p])
         except IndexError:
-            return []
+            return baseset([])
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, list(repo), x):
+    for r in getset(repo, baseset(repo), x):
         ps.add(cl.parentrevs(r)[1])
-    return [r for r in subset if r in ps]
+    return baseset([r for r in subset if r in ps])
 
 def parents(repo, subset, x):
     """``parents([set])``
@@ -1122,13 +1123,13 @@
     """
     if x is None:
         ps = tuple(p.rev() for p in repo[x].parents())
-        return [r for r in subset if r in ps]
+        return baseset([r for r in subset if r in ps])
 
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, list(repo), x):
+    for r in getset(repo, baseset(repo), x):
         ps.update(cl.parentrevs(r))
-    return [r for r in subset if r in ps]
+    return baseset([r for r in subset if r in ps])
 
 def parentspec(repo, subset, x, n):
     """``set^0``
@@ -1144,7 +1145,7 @@
         raise error.ParseError(_("^ expects a number 0, 1, or 2"))
     ps = set()
     cl = repo.changelog
-    for r in getset(repo, cl, x):
+    for r in getset(repo, baseset(cl), x):
         if n == 0:
             ps.add(r)
         elif n == 1:
@@ -1153,7 +1154,7 @@
             parents = cl.parentrevs(r)
             if len(parents) > 1:
                 ps.add(parents[1])
-    return [r for r in subset if r in ps]
+    return baseset([r for r in subset if r in ps])
 
 def present(repo, subset, x):
     """``present(set)``
@@ -1167,7 +1168,7 @@
     try:
         return getset(repo, subset, x)
     except error.RepoLookupError:
-        return []
+        return baseset([])
 
 def public(repo, subset, x):
     """``public()``
@@ -1175,7 +1176,7 @@
     # i18n: "public" is a keyword
     getargs(x, 0, 0, _("public takes no arguments"))
     pc = repo._phasecache
-    return [r for r in subset if pc.phase(repo, r) == phases.public]
+    return baseset([r for r in subset if pc.phase(repo, r) == phases.public])
 
 def remote(repo, subset, x):
     """``remote([id [,path]])``
@@ -1209,8 +1210,8 @@
     if n in repo:
         r = repo[n].rev()
         if r in subset:
-            return [r]
-    return []
+            return baseset([r])
+    return baseset([])
 
 def removes(repo, subset, x):
     """``removes(pattern)``
@@ -1232,7 +1233,7 @@
     except (TypeError, ValueError):
         # i18n: "rev" is a keyword
         raise error.ParseError(_("rev expects a number"))
-    return [r for r in subset if r == l]
+    return baseset([r for r in subset if r == l])
 
 def matching(repo, subset, x):
     """``matching(revision [, field])``
@@ -1262,7 +1263,7 @@
     # i18n: "matching" is a keyword
     l = getargs(x, 1, 2, _("matching takes 1 or 2 arguments"))
 
-    revs = getset(repo, repo.changelog, l[0])
+    revs = getset(repo, baseset(repo.changelog), l[0])
 
     fieldlist = ['metadata']
     if len(l) > 1:
@@ -1344,7 +1345,7 @@
                     break
             if match:
                 matches.add(r)
-    return [r for r in subset if r in matches]
+    return baseset([r for r in subset if r in matches])
 
 def reverse(repo, subset, x):
     """``reverse(set)``
@@ -1352,7 +1353,7 @@
     """
     l = getset(repo, subset, x)
     if not isinstance(l, list):
-        l = list(l)
+        l = baseset(l)
     l.reverse()
     return l
 
@@ -1360,10 +1361,10 @@
     """``roots(set)``
     Changesets in set with no parent changeset in set.
     """
-    s = set(getset(repo, repo.changelog, x))
-    subset = [r for r in subset if r in s]
+    s = set(getset(repo, baseset(repo.changelog), x))
+    subset = baseset([r for r in subset if r in s])
     cs = _children(repo, subset, s)
-    return [r for r in subset if r not in cs]
+    return baseset([r for r in subset if r not in cs])
 
 def secret(repo, subset, x):
     """``secret()``
@@ -1371,7 +1372,7 @@
     # i18n: "secret" is a keyword
     getargs(x, 0, 0, _("secret takes no arguments"))
     pc = repo._phasecache
-    return [r for r in subset if pc.phase(repo, r) == phases.secret]
+    return baseset([r for r in subset if pc.phase(repo, r) == phases.secret])
 
 def sort(repo, subset, x):
     """``sort(set[, [-]key...])``
@@ -1427,7 +1428,7 @@
         e.append(r)
         l.append(e)
     l.sort()
-    return [e[-1] for e in l]
+    return baseset([e[-1] for e in l])
 
 def _stringmatcher(pattern):
     """
@@ -1496,7 +1497,7 @@
             s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
     else:
         s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
-    return [r for r in subset if r in s]
+    return baseset([r for r in subset if r in s])
 
 def tagged(repo, subset, x):
     return tag(repo, subset, x)
@@ -1508,7 +1509,7 @@
     # i18n: "unstable" is a keyword
     getargs(x, 0, 0, _("unstable takes no arguments"))
     unstables = obsmod.getrevs(repo, 'unstable')
-    return [r for r in subset if r in unstables]
+    return baseset([r for r in subset if r in unstables])
 
 
 def user(repo, subset, x):
@@ -1525,11 +1526,11 @@
 def _list(repo, subset, x):
     s = getstring(x, "internal error")
     if not s:
-        return []
+        return baseset([])
     if not isinstance(subset, set):
         subset = set(subset)
     ls = [repo[r].rev() for r in s.split('\0')]
-    return [r for r in ls if r in subset]
+    return baseset([r for r in ls if r in subset])
 
 symbols = {
     "adds": adds,
@@ -2023,5 +2024,8 @@
             funcs.add(tree[1][1])
         return funcs
 
+class baseset(list):
+    pass
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -524,11 +524,11 @@
 
         # fall through to new-style queries if old-style fails
         m = revset.match(repo.ui, spec)
-        dl = [r for r in m(repo, list(repo)) if r not in seen]
+        dl = [r for r in m(repo, revset.baseset(repo)) if r not in seen]
         l.extend(dl)
         seen.update(dl)
 
-    return l
+    return revset.baseset(l)
 
 def expandpats(pats):
     if not util.expandglobs:


More information about the Mercurial-devel mailing list