Patchwork [07,of,10] revset: add support for using ~ operator on wdir() predicate

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

Comments

Pulkit Goyal - May 22, 2017, 8:52 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1495481899 -19800
#      Tue May 23 01:08:19 2017 +0530
# Node ID 6ed3d53be6963cbd841fd2c04b4311a27a3c4b65
# Parent  b358980b7e88e2aafb79eefd456fe8c492d013ec
revset: add support for using ~ operator on wdir() predicate

We catch the WdirUnsupported exception and handles the wdir() case here.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -383,7 +383,10 @@ 
     cl = repo.changelog
     for r in getset(repo, fullreposet(repo), x):
         for i in range(n):
-            r = cl.parentrevs(r)[0]
+            try:
+                r = cl.parentrevs(r)[0]
+            except error.WdirUnsupported:
+                r = repo[r].parents()[0].rev()
         ps.add(r)
     return subset & ps
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1229,6 +1229,8 @@ 
   7
   $ hg debugrevspec 'wdir()^0'
   2147483647
+  $ hg debugrevspec 'wdir()~3'
+  5
   $ hg debugrevspec 'wdir()~0'
   2147483647
   $ hg debugrevspec 'p1(wdir())'