changeset 32442:e8c043375b53

revset: make `hg log -r 'wdir()^'` work (issue4905) This patch catches the WdirUnsupported exception to support wdir()^.
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 19 May 2017 20:06:45 +0530
parents a28c76e1cea9
children bdc4861ffe59
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Fri May 19 19:12:06 2017 +0530
+++ b/mercurial/revset.py	Fri May 19 20:06:45 2017 +0530
@@ -1408,7 +1408,10 @@
     ps = set()
     cl = repo.changelog
     for r in getset(repo, fullreposet(repo), x):
-        ps.add(cl.parentrevs(r)[0])
+        try:
+            ps.add(cl.parentrevs(r)[0])
+        except error.WdirUnsupported:
+            ps.add(repo[r].parents()[0].rev())
     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	Fri May 19 19:12:06 2017 +0530
+++ b/tests/test-revset.t	Fri May 19 20:06:45 2017 +0530
@@ -1221,6 +1221,15 @@
 Test working-directory revision
   $ hg debugrevspec 'wdir()'
   2147483647
+  $ hg debugrevspec 'wdir()^'
+  9
+  $ hg up 7
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg debugrevspec 'wdir()^'
+  7
+For tests consistency
+  $ hg up 9
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg debugrevspec 'tip or wdir()'
   9
   2147483647