Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revset.py @ 38624:5460926352ee
revsets: add commonancestors revset
This is a method to reproduce "::x and ::y" such that a set can be sent
in. For instance, it'd be convenient to have "::heads()" work like this
but that already means "::x + ::y + ..." for each element in the
"heads()" set.
Therefore, we add the "commonancestors" method to mean "::x and ::y ..."
for each head in the given set.
author | Sean Farley <sean@farley.io> |
---|---|
date | Mon, 18 Jun 2018 19:41:54 -0700 |
parents | 1c93e0237a24 |
children | 52f19a840543 |
line wrap: on
line diff
--- a/mercurial/revset.py Mon Jul 09 10:07:20 2018 -0400 +++ b/mercurial/revset.py Mon Jun 18 19:41:54 2018 -0700 @@ -608,6 +608,22 @@ return subset.filter(lambda r: repo[r].closesbranch(), condrepr='<branch closed>') +@predicate('commonancestors(set)', safe=True) +def commonancestors(repo, subset, x): + """Returns all common ancestors of the set. + + This method is for calculating "::x and ::y" (i.e. all the ancestors that + are common to both x and y) in an easy and optimized way. We can't quite + use "::head()" because that revset returns "::x + ::y + ..." for each head + in the repo (whereas we want "::x *and* ::y"). + + """ + # only wants the heads of the set passed in + for r in heads(repo, fullreposet(repo), x, defineorder): + subset &= dagop.revancestors(repo, baseset([r])) + + return subset + @predicate('contains(pattern)', weight=100) def contains(repo, subset, x): """The revision's manifest contains a file matching pattern (but might not