Patchwork [06,of,10] revset: add support for p2(wdir()) to get second parent of working directory

login
register
mail settings
Submitter Pulkit Goyal
Date May 22, 2017, 8:52 p.m.
Message ID <b358980b7e88e2aafb79.1495486336@workspace>
Download mbox | patch
Permalink /patch/20847/
State Accepted
Headers show

Comments

Pulkit Goyal - May 22, 2017, 8:52 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1495399462 -19800
#      Mon May 22 02:14:22 2017 +0530
# Node ID b358980b7e88e2aafb79eefd456fe8c492d013ec
# Parent  05143c5cb16a9e50b40321d5417e0c91ba6afb16
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.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -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.
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 @@ 
   2147483647
   $ hg debugrevspec 'p1(wdir())'
   7
+  $ hg debugrevspec 'p2(wdir())'
   $ hg debugrevspec 'parents(wdir())'
   7
   $ hg debugrevspec 'wdir()^1'