mercurial/revset.py
changeset 28015 a036e1ae1fbe
parent 28008 86c4cbdaffee
parent 27987 b19d8d5d6b51
child 28139 5476a7a039c0
equal deleted inserted replaced
28014:83fc0c055664 28015:a036e1ae1fbe
   317 
   317 
   318 def getlist(x):
   318 def getlist(x):
   319     if not x:
   319     if not x:
   320         return []
   320         return []
   321     if x[0] == 'list':
   321     if x[0] == 'list':
   322         return getlist(x[1]) + [x[2]]
   322         return list(x[1:])
   323     return [x]
   323     return [x]
   324 
   324 
   325 def getargs(x, min, max, err):
   325 def getargs(x, min, max, err):
   326     l = getlist(x)
   326     l = getlist(x)
   327     if len(l) < min or (max >= 0 and len(l) > max):
   327     if len(l) < min or (max >= 0 and len(l) > max):
   446     return a + b
   446     return a + b
   447 
   447 
   448 def notset(repo, subset, x):
   448 def notset(repo, subset, x):
   449     return subset - getset(repo, subset, x)
   449     return subset - getset(repo, subset, x)
   450 
   450 
   451 def listset(repo, subset, a, b):
   451 def listset(repo, subset, *xs):
   452     raise error.ParseError(_("can't use a list in this context"),
   452     raise error.ParseError(_("can't use a list in this context"),
   453                            hint=_('see hg help "revsets.x or y"'))
   453                            hint=_('see hg help "revsets.x or y"'))
   454 
   454 
   455 def keyvaluepair(repo, subset, k, v):
   455 def keyvaluepair(repo, subset, k, v):
   456     raise error.ParseError(_("can't use a key-value pair in this context"))
   456     raise error.ParseError(_("can't use a key-value pair in this context"))
  2251     elif op == 'parentpost':
  2251     elif op == 'parentpost':
  2252         o = optimize(x[1], small)
  2252         o = optimize(x[1], small)
  2253         return o[0], (op, o[1])
  2253         return o[0], (op, o[1])
  2254     elif op == 'group':
  2254     elif op == 'group':
  2255         return optimize(x[1], small)
  2255         return optimize(x[1], small)
  2256     elif op in 'dagrange range list parent ancestorspec':
  2256     elif op in 'dagrange range parent ancestorspec':
  2257         if op == 'parent':
  2257         if op == 'parent':
  2258             # x^:y means (x^) : y, not x ^ (:y)
  2258             # x^:y means (x^) : y, not x ^ (:y)
  2259             post = ('parentpost', x[1])
  2259             post = ('parentpost', x[1])
  2260             if x[2][0] == 'dagrangepre':
  2260             if x[2][0] == 'dagrangepre':
  2261                 return optimize(('dagrange', post, x[2][1]), small)
  2261                 return optimize(('dagrange', post, x[2][1]), small)
  2263                 return optimize(('range', post, x[2][1]), small)
  2263                 return optimize(('range', post, x[2][1]), small)
  2264 
  2264 
  2265         wa, ta = optimize(x[1], small)
  2265         wa, ta = optimize(x[1], small)
  2266         wb, tb = optimize(x[2], small)
  2266         wb, tb = optimize(x[2], small)
  2267         return wa + wb, (op, ta, tb)
  2267         return wa + wb, (op, ta, tb)
       
  2268     elif op == 'list':
       
  2269         ws, ts = zip(*(optimize(y, small) for y in x[1:]))
       
  2270         return sum(ws), (op,) + ts
  2268     elif op == 'func':
  2271     elif op == 'func':
  2269         f = getstring(x[1], _("not a symbol"))
  2272         f = getstring(x[1], _("not a symbol"))
  2270         wa, ta = optimize(x[2], small)
  2273         wa, ta = optimize(x[2], small)
  2271         if f in ("author branch closed date desc file grep keyword "
  2274         if f in ("author branch closed date desc file grep keyword "
  2272                  "outgoing user"):
  2275                  "outgoing user"):
  2364     p = parser.parser(elements)
  2367     p = parser.parser(elements)
  2365     try:
  2368     try:
  2366         tree, pos = p.parse(_tokenizealias(decl))
  2369         tree, pos = p.parse(_tokenizealias(decl))
  2367         if (pos != len(decl)):
  2370         if (pos != len(decl)):
  2368             raise error.ParseError(_('invalid token'), pos)
  2371             raise error.ParseError(_('invalid token'), pos)
       
  2372         tree = parser.simplifyinfixops(tree, ('list',))
  2369 
  2373 
  2370         if isvalidsymbol(tree):
  2374         if isvalidsymbol(tree):
  2371             # "name = ...." style
  2375             # "name = ...." style
  2372             name = getsymbol(tree)
  2376             name = getsymbol(tree)
  2373             if name.startswith('$'):
  2377             if name.startswith('$'):
  2454 
  2458 
  2455     p = parser.parser(elements)
  2459     p = parser.parser(elements)
  2456     tree, pos = p.parse(tokenizedefn(defn))
  2460     tree, pos = p.parse(tokenizedefn(defn))
  2457     if pos != len(defn):
  2461     if pos != len(defn):
  2458         raise error.ParseError(_('invalid token'), pos)
  2462         raise error.ParseError(_('invalid token'), pos)
  2459     return parser.simplifyinfixops(tree, ('or',))
  2463     return parser.simplifyinfixops(tree, ('list', 'or'))
  2460 
  2464 
  2461 class revsetalias(object):
  2465 class revsetalias(object):
  2462     # whether own `error` information is already shown or not.
  2466     # whether own `error` information is already shown or not.
  2463     # this avoids showing same warning multiple times at each `findaliases`.
  2467     # this avoids showing same warning multiple times at each `findaliases`.
  2464     warned = False
  2468     warned = False
  2585 def parse(spec, lookup=None):
  2589 def parse(spec, lookup=None):
  2586     p = parser.parser(elements)
  2590     p = parser.parser(elements)
  2587     tree, pos = p.parse(tokenize(spec, lookup=lookup))
  2591     tree, pos = p.parse(tokenize(spec, lookup=lookup))
  2588     if pos != len(spec):
  2592     if pos != len(spec):
  2589         raise error.ParseError(_("invalid token"), pos)
  2593         raise error.ParseError(_("invalid token"), pos)
  2590     return parser.simplifyinfixops(tree, ('or',))
  2594     return parser.simplifyinfixops(tree, ('list', 'or'))
  2591 
  2595 
  2592 def posttreebuilthook(tree, repo):
  2596 def posttreebuilthook(tree, repo):
  2593     # hook for extensions to execute code on the optimized tree
  2597     # hook for extensions to execute code on the optimized tree
  2594     pass
  2598     pass
  2595 
  2599