revset: add support for "wdir()^n"
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 22 May 2017 01:01:45 +0530
changeset 32474 f064e2f72c49
parent 32473 bb5dc19484b8
child 32475 f03dcb3f95a5
revset: add support for "wdir()^n" This patch catches the WdirUnsupported exception raised, and adds support for wdir^n which will give us the nth parent of the working directory.
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Mon May 22 00:54:02 2017 +0530
+++ b/mercurial/revset.py	Mon May 22 01:01:45 2017 +0530
@@ -1502,11 +1502,19 @@
         if n == 0:
             ps.add(r)
         elif n == 1:
-            ps.add(cl.parentrevs(r)[0])
+            try:
+                ps.add(cl.parentrevs(r)[0])
+            except error.WdirUnsupported:
+                ps.add(repo[r].parents()[0].rev())
         elif n == 2:
-            parents = cl.parentrevs(r)
-            if parents[1] != node.nullrev:
-                ps.add(parents[1])
+            try:
+                parents = cl.parentrevs(r)
+                if parents[1] != node.nullrev:
+                    ps.add(parents[1])
+            except error.WdirUnsupported:
+                parents = repo[r].parents()
+                if len(parents) == 2:
+                    ps.add(parents[1].rev())
     return subset & ps
 
 @predicate('present(set)', safe=True)
--- a/tests/test-revset.t	Mon May 22 00:54:02 2017 +0530
+++ b/tests/test-revset.t	Mon May 22 01:01:45 2017 +0530
@@ -1227,6 +1227,12 @@
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg debugrevspec 'wdir()^'
   7
+  $ hg debugrevspec 'wdir()^1'
+  7
+  $ hg debugrevspec 'wdir()^2'
+  $ hg debugrevspec 'wdir()^3'
+  hg: parse error: ^ expects a number 0, 1, or 2
+  [255]
 For tests consistency
   $ hg up 9
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved