# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2017-05-21 20:44:22 # Node ID c8fb2a82b5f9841b16e065fa3a71f0654a791823 # Parent e72c5263ccaf2754f4c5d170f82829a8881b3144 revset: add support for p2(wdir()) to get second parent of working directory This adds support for finding the second parent of working directory using the p2 predicate. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1434,7 +1434,12 @@ def p2(repo, subset, x): ps = set() cl = repo.changelog for r in getset(repo, fullreposet(repo), x): - ps.add(cl.parentrevs(r)[1]) + try: + ps.add(cl.parentrevs(r)[1]) + except error.WdirUnsupported: + parents = repo[r].parents() + if len(parents) == 2: + ps.add(parents[1]) ps -= {node.nullrev} # XXX we should turn this into a baseset instead of a set, smartset may do # some optimizations from the fact this is a baseset. diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -1233,6 +1233,7 @@ Test working-directory revision 2147483647 $ hg debugrevspec 'p1(wdir())' 7 + $ hg debugrevspec 'p2(wdir())' $ hg debugrevspec 'parents(wdir())' 7 $ hg debugrevspec 'wdir()^1'