[PATCH stable] revset: directly use __contains__ instead of a lambda
pierre-yves.david at ens-lyon.org
pierre-yves.david at ens-lyon.org
Thu May 1 16:14:02 CDT 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1398978424 25200
# Thu May 01 14:07:04 2014 -0700
# Branch stable
# Node ID e50eb80951709b86f3aa8b91c4072f15180812b2
# Parent f7c5fe7a29485ec20d41d7e00020102a0d84840c
revset: directly use __contains__ instead of a lambda
We get rid of lambda in a bunch of other place. This is equivalent and much
faster. (no new timing as this is the same change as three other changesets)
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -281,11 +281,11 @@ def rangeset(repo, subset, x, y):
def dagrange(repo, subset, x, y):
r = spanset(repo)
xs = _revsbetween(repo, getset(repo, r, x), getset(repo, r, y))
s = subset.set()
- return xs.filter(lambda r: r in s)
+ return xs.filter(s.__contains__)
def andset(repo, subset, x, y):
return getset(repo, getset(repo, subset, x), y)
def orset(repo, subset, x, y):
@@ -346,11 +346,11 @@ def ancestor(repo, subset, x):
def _ancestors(repo, subset, x, followfirst=False):
args = getset(repo, spanset(repo), x)
if not args:
return baseset([])
s = _revancestors(repo, args, followfirst)
- return subset.filter(lambda r: r in s)
+ return subset.filter(s.__contains__)
def ancestors(repo, subset, x):
"""``ancestors(set)``
Changesets that are ancestors of a changeset in set.
"""
@@ -374,11 +374,11 @@ def ancestorspec(repo, subset, x, n):
cl = repo.changelog
for r in getset(repo, baseset(cl), x):
for i in range(n):
r = cl.parentrevs(r)[0]
ps.add(r)
- return subset.filter(lambda r: r in ps)
+ return subset.filter(ps.__contains__)
def author(repo, subset, x):
"""``author(string)``
Alias for ``user(string)``.
"""
@@ -404,11 +404,11 @@ def only(repo, subset, x):
if not rev in descendants and not rev in include]
else:
exclude = getset(repo, spanset(repo), args[1])
results = set(ancestormod.missingancestors(include, exclude, cl.parentrevs))
- return lazyset(subset, lambda x: x in results)
+ return lazyset(subset, results.__contains__)
def bisect(repo, subset, x):
"""``bisect(string)``
Changesets marked in the specified bisect status:
@@ -421,11 +421,11 @@ def bisect(repo, subset, x):
- ``current`` : the cset currently being bisected
"""
# i18n: "bisect" is a keyword
status = getstring(x, _("bisect requires a string")).lower()
state = set(hbisect.get(repo, status))
- return subset.filter(lambda r: r in state)
+ return subset.filter(state.__contains__)
# Backward-compatibility
# - no help entry so that we do not advertise it any more
def bisected(repo, subset, x):
return bisect(repo, subset, x)
@@ -464,11 +464,11 @@ def bookmark(repo, subset, x):
bmrevs.add(repo[bmrev].rev())
return subset & bmrevs
bms = set([repo[r].rev()
for r in repo._bookmarks.values()])
- return subset.filter(lambda r: r in bms)
+ return subset.filter(bms.__contains__)
def branch(repo, subset, x):
"""``branch(string or set)``
All changesets belonging to the given branch or the branches of the given
changesets.
@@ -723,20 +723,20 @@ def destination(repo, subset, x):
break
r = src
src = _getrevsource(repo, r)
- return subset.filter(lambda r: r in dests)
+ return subset.filter(dests.__contains__)
def divergent(repo, subset, x):
"""``divergent()``
Final successors of changesets with an alternative set of final successors.
"""
# i18n: "divergent" is a keyword
getargs(x, 0, 0, _("divergent takes no arguments"))
divergent = obsmod.getrevs(repo, 'divergent')
- return subset.filter(lambda r: r in divergent)
+ return subset.filter(divergent.__contains__)
def draft(repo, subset, x):
"""``draft()``
Changeset in draft phase."""
# i18n: "draft" is a keyword
@@ -809,11 +809,11 @@ def filelog(repo, subset, x):
if m(f):
fl = repo.file(f)
for fr in fl:
s.add(fl.linkrev(fr))
- return subset.filter(lambda r: r in s)
+ return subset.filter(s.__contains__)
def first(repo, subset, x):
"""``first(set, [n])``
An alias for limit().
"""
@@ -832,11 +832,11 @@ def _follow(repo, subset, x, name, follo
else:
return baseset([])
else:
s = _revancestors(repo, baseset([c.rev()]), followfirst)
- return subset.filter(lambda r: r in s)
+ return subset.filter(s.__contains__)
def follow(repo, subset, x):
"""``follow([file])``
An alias for ``::.`` (ancestors of the working copy's first parent).
If a filename is specified, the history of the given file is followed,
@@ -1174,11 +1174,11 @@ def origin(repo, subset, x):
if prev is None:
return src
src = prev
o = set([_firstsrc(r) for r in args])
- return subset.filter(lambda r: r in o)
+ return subset.filter(o.__contains__)
def outgoing(repo, subset, x):
"""``outgoing([path])``
Changesets not found in the specified destination repository, or the
default push location.
@@ -1197,11 +1197,11 @@ def outgoing(repo, subset, x):
repo.ui.pushbuffer()
outgoing = discovery.findcommonoutgoing(repo, other, onlyheads=revs)
repo.ui.popbuffer()
cl = repo.changelog
o = set([cl.rev(r) for r in outgoing.missing])
- return subset.filter(lambda r: r in o)
+ return subset.filter(o.__contains__)
def p1(repo, subset, x):
"""``p1([set])``
First parent of changesets in set, or the working directory.
"""
More information about the Mercurial-devel
mailing list