# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1495395105 -19800 # Node ID f064e2f72c49825536d373ded1f48dbb589dbc0e # Parent bb5dc19484b8579c2a0091c78572cb7417580d60 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. diff -r bb5dc19484b8 -r f064e2f72c49 mercurial/revset.py --- 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) diff -r bb5dc19484b8 -r f064e2f72c49 tests/test-revset.t --- 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