# HG changeset patch # User Wagner Bruna # Date 1287124238 10800 # 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 -r c7d23b4ca4ba -r 9aae04f4fcf6 mercurial/revset.py --- a/mercurial/revset.py Wed Oct 20 14:57:36 2010 -0500 +++ b/mercurial/revset.py Fri Oct 15 03:30:38 2010 -0300 @@ -193,21 +193,21 @@ 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 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 -r c7d23b4ca4ba -r 9aae04f4fcf6 tests/test-revset.t --- a/tests/test-revset.t Wed Oct 20 14:57:36 2010 -0500 +++ b/tests/test-revset.t Fri Oct 15 03:30:38 2010 -0300 @@ -339,3 +339,20 @@ 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