comparison mercurial/revset.py @ 41563:13f7a6a4f0db

revset: leverage getintrange() helper in relation-subscript operation (API) Now a range expression is parsed by a relation function itself since the upper layer have no knowledge about the default first/last bounds.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 27 Jan 2019 13:37:37 +0900
parents 1c04894e8fe1
children 0531dff73d0b
comparison
equal deleted inserted replaced
41562:1c04894e8fe1 41563:13f7a6a4f0db
41 getsymbol = revsetlang.getsymbol 41 getsymbol = revsetlang.getsymbol
42 getstring = revsetlang.getstring 42 getstring = revsetlang.getstring
43 getinteger = revsetlang.getinteger 43 getinteger = revsetlang.getinteger
44 getboolean = revsetlang.getboolean 44 getboolean = revsetlang.getboolean
45 getlist = revsetlang.getlist 45 getlist = revsetlang.getlist
46 getrange = revsetlang.getrange
47 getintrange = revsetlang.getintrange 46 getintrange = revsetlang.getintrange
48 getargs = revsetlang.getargs 47 getargs = revsetlang.getargs
49 getargsdict = revsetlang.getargsdict 48 getargsdict = revsetlang.getargsdict
50 49
51 baseset = smartset.baseset 50 baseset = smartset.baseset
254 ancdepths = (-min(b, 0), -a + 1) 253 ancdepths = (-min(b, 0), -a + 1)
255 if b > 0: 254 if b > 0:
256 descdepths = (max(a, 0), b + 1) 255 descdepths = (max(a, 0), b + 1)
257 return ancdepths, descdepths 256 return ancdepths, descdepths
258 257
259 def generationsrel(repo, subset, x, rel, a, b, order): 258 def generationsrel(repo, subset, x, rel, z, order):
260 # TODO: rewrite tests, and drop startdepth argument from ancestors() and 259 # TODO: rewrite tests, and drop startdepth argument from ancestors() and
261 # descendants() predicates 260 # descendants() predicates
262 if a is None: 261 a, b = getintrange(z,
263 a = -(dagop.maxlogdepth - 1) 262 _('relation subscript must be an integer or a range'),
264 if b is None: 263 _('relation subscript bounds must be integers'),
265 b = +(dagop.maxlogdepth - 1) 264 deffirst=-(dagop.maxlogdepth - 1),
266 265 deflast=+(dagop.maxlogdepth - 1))
267 (ancstart, ancstop), (descstart, descstop) = _splitrange(a, b) 266 (ancstart, ancstop), (descstart, descstop) = _splitrange(a, b)
268 267
269 if ancstart is None and descstart is None: 268 if ancstart is None and descstart is None:
270 return baseset() 269 return baseset()
271 270
286 def relsubscriptset(repo, subset, x, y, z, order): 285 def relsubscriptset(repo, subset, x, y, z, order):
287 # this is pretty basic implementation of 'x#y[z]' operator, still 286 # this is pretty basic implementation of 'x#y[z]' operator, still
288 # experimental so undocumented. see the wiki for further ideas. 287 # experimental so undocumented. see the wiki for further ideas.
289 # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan 288 # https://www.mercurial-scm.org/wiki/RevsetOperatorPlan
290 rel = getsymbol(y) 289 rel = getsymbol(y)
291 try:
292 a, b = getrange(z, '')
293 except error.ParseError:
294 a = getinteger(z, _("relation subscript must be an integer"))
295 b = a
296 else:
297 def getbound(i):
298 if i is None:
299 return None
300 msg = _("relation subscript bounds must be integers")
301 return getinteger(i, msg)
302 a, b = [getbound(i) for i in (a, b)]
303
304 if rel in subscriptrelations: 290 if rel in subscriptrelations:
305 return subscriptrelations[rel](repo, subset, x, rel, a, b, order) 291 return subscriptrelations[rel](repo, subset, x, rel, z, order)
306 292
307 relnames = [r for r in subscriptrelations.keys() if len(r) > 1] 293 relnames = [r for r in subscriptrelations.keys() if len(r) > 1]
308 raise error.UnknownIdentifier(rel, relnames) 294 raise error.UnknownIdentifier(rel, relnames)
309 295
310 def subscriptset(repo, subset, x, y, order): 296 def subscriptset(repo, subset, x, y, order):