# HG changeset patch # User Wagner Bruna # Date 2010-10-15 06:30:38 # Node ID 9aae04f4fcf6984e1ca8ea24ddd14b6622114884 # Parent c7d23b4ca4ba6ccb4839fcb1c4e4e5da5de2e4a0 revset: disable subset optimization for parents() and children() (issue2437) For the boolean operators, the subset optimization works by calculating the cheaper argument first, and passing the subset to the second argument to restrict the revision domain. This works well for filtering predicates. But parents() don't work like a filter: it may return revisions outside the specified set. So, combining it with boolean operators may easily yield incorrect results. For instance, for the following revision graph: 0 -- 1 the expression '0 and parents(1)' should evaluate as follows: 0 and parents(1) -> 0 and 0 -> 0 But since [0] is passed to parents() as a subset, we get instead: 0 and parents(1 and 0) -> 0 and parents([]) -> 0 and [] -> [] This also affects children(), p1() and p2(), for the same reasons. Predicates that call these (like heads()) are also affected. We work around this issue by ignoring the subset when propagating the call inside those predicates. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -193,21 +193,21 @@ def rev(repo, subset, x): def p1(repo, subset, x): ps = set() cl = repo.changelog - for r in getset(repo, subset, x): + for r in getset(repo, range(len(repo)), x): ps.add(cl.parentrevs(r)[0]) return [r for r in subset if r in ps] def p2(repo, subset, x): ps = set() cl = repo.changelog - for r in getset(repo, subset, x): + for r in getset(repo, range(len(repo)), x): ps.add(cl.parentrevs(r)[1]) return [r for r in subset if r in ps] def parents(repo, subset, x): ps = set() cl = repo.changelog - for r in getset(repo, subset, x): + for r in getset(repo, range(len(repo)), x): ps.update(cl.parentrevs(r)) return [r for r in subset if r in ps] @@ -238,7 +238,7 @@ def limit(repo, subset, x): def children(repo, subset, x): cs = set() cl = repo.changelog - s = set(getset(repo, subset, x)) + s = set(getset(repo, range(len(repo)), x)) for r in xrange(0, len(repo)): for p in cl.parentrevs(r): if p in s: diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -339,3 +339,20 @@ quoting needed 0 $ log '4::8 - 8' 4 + +issue2437 + + $ log '3 and p1(5)' + 3 + $ log '4 and p2(6)' + 4 + $ log '1 and parents(:2)' + 1 + $ log '2 and children(1:)' + 2 + $ log 'roots(all()) or roots(all())' + 0 + $ log 'heads(branch(é)) or heads(branch(é))' + 9 + $ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(é)))' + 4