Mercurial > public > mercurial-scm > hg-stable
diff mercurial/revset.py @ 33417:d1b13d4995ed
revset: add experimental ancestors/descendants relation subscript
The relation name is 'generations' now, which may be changed in future.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 08 Jul 2017 13:15:17 +0900 |
parents | 9467d5337292 |
children | 9dcc3529e002 |
line wrap: on
line diff
--- a/mercurial/revset.py Sat Jul 08 13:07:59 2017 +0900 +++ b/mercurial/revset.py Sat Jul 08 13:15:17 2017 +0900 @@ -155,7 +155,23 @@ raise error.ParseError(_("can't use a relation in this context")) def relsubscriptset(repo, subset, x, y, z, order): - raise error.ParseError(_("can't use a relation in this context")) + # this is pretty basic implementation of 'x#y[z]' operator, still + # experimental so undocumented. see the wiki for further ideas. + # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan + rel = getsymbol(y) + n = getinteger(z, _("relation subscript must be an integer")) + + # TODO: perhaps this should be a table of relation functions + if rel in ('g', 'generations'): + # TODO: support range, rewrite tests, and drop startdepth argument + # from ancestors() and descendants() predicates + if n <= 0: + n = -n + return _ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1) + else: + return _descendants(repo, subset, x, startdepth=n, stopdepth=n + 1) + + raise error.UnknownIdentifier(rel, ['generations']) def subscriptset(repo, subset, x, y, order): raise error.ParseError(_("can't use a subscript in this context"))