comparison 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
comparison
equal deleted inserted replaced
33416:9467d5337292 33417:d1b13d4995ed
153 153
154 def relationset(repo, subset, x, y, order): 154 def relationset(repo, subset, x, y, order):
155 raise error.ParseError(_("can't use a relation in this context")) 155 raise error.ParseError(_("can't use a relation in this context"))
156 156
157 def relsubscriptset(repo, subset, x, y, z, order): 157 def relsubscriptset(repo, subset, x, y, z, order):
158 raise error.ParseError(_("can't use a relation in this context")) 158 # this is pretty basic implementation of 'x#y[z]' operator, still
159 # experimental so undocumented. see the wiki for further ideas.
160 # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan
161 rel = getsymbol(y)
162 n = getinteger(z, _("relation subscript must be an integer"))
163
164 # TODO: perhaps this should be a table of relation functions
165 if rel in ('g', 'generations'):
166 # TODO: support range, rewrite tests, and drop startdepth argument
167 # from ancestors() and descendants() predicates
168 if n <= 0:
169 n = -n
170 return _ancestors(repo, subset, x, startdepth=n, stopdepth=n + 1)
171 else:
172 return _descendants(repo, subset, x, startdepth=n, stopdepth=n + 1)
173
174 raise error.UnknownIdentifier(rel, ['generations'])
159 175
160 def subscriptset(repo, subset, x, y, order): 176 def subscriptset(repo, subset, x, y, order):
161 raise error.ParseError(_("can't use a subscript in this context")) 177 raise error.ParseError(_("can't use a subscript in this context"))
162 178
163 def listset(repo, subset, *xs): 179 def listset(repo, subset, *xs):