# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 2017-05-21 19:31:45 # 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 --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1502,11 +1502,19 @@ def parentspec(repo, subset, x, n, order 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 --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -1227,6 +1227,12 @@ Test working-directory revision 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