revset: add support for p2(wdir()) to get second parent of working directory
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 22 May 2017 02:14:22 +0530
changeset 32478 c8fb2a82b5f9
parent 32477 e72c5263ccaf
child 32479 018f638ad88e
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.
mercurial/revset.py
tests/test-revset.t
--- 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'