changeset 32440:c8fb2a82b5f9

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.
author Pulkit Goyal <7895pulkit@gmail.com>
date Mon, 22 May 2017 02:14:22 +0530
parents e72c5263ccaf
children 018f638ad88e
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Mon May 22 02:03:43 2017 +0530
+++ b/mercurial/revset.py	Mon May 22 02:14:22 2017 +0530
@@ -1434,7 +1434,12 @@
     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.
--- a/tests/test-revset.t	Mon May 22 02:03:43 2017 +0530
+++ b/tests/test-revset.t	Mon May 22 02:14:22 2017 +0530
@@ -1233,6 +1233,7 @@
   2147483647
   $ hg debugrevspec 'p1(wdir())'
   7
+  $ hg debugrevspec 'p2(wdir())'
   $ hg debugrevspec 'parents(wdir())'
   7
   $ hg debugrevspec 'wdir()^1'