mercurial/fileset.py
changeset 14676 e80fa502b8cf
parent 14673 b0566467c492
child 14677 2a758ffc821e
equal deleted inserted replaced
14675:cfc89398f710 14676:e80fa502b8cf
     3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
     3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     5 # This software may be used and distributed according to the terms of the
     6 # GNU General Public License version 2 or any later version.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 import parser, error
     8 import parser, error, util
     9 from i18n import _
     9 from i18n import _
    10 
    10 
    11 elements = {
    11 elements = {
    12     "(": (20, ("group", 1, ")"), ("func", 1, ")")),
    12     "(": (20, ("group", 1, ")"), ("func", 1, ")")),
    13     "-": (5, ("negate", 19), ("minus", 5)),
    13     "-": (5, ("negate", 19), ("minus", 5)),
   108     return [r for r in mctx.subset if r not in s]
   108     return [r for r in mctx.subset if r not in s]
   109 
   109 
   110 def listset(mctx, a, b):
   110 def listset(mctx, a, b):
   111     raise error.ParseError(_("can't use a list in this context"))
   111     raise error.ParseError(_("can't use a list in this context"))
   112 
   112 
       
   113 def func(mctx, a, b):
       
   114     if a[0] == 'symbol' and a[1] in symbols:
       
   115         return symbols[a[1]](mctx, b)
       
   116     raise error.ParseError(_("not a function: %s") % a[1])
       
   117 
       
   118 def getlist(x):
       
   119     if not x:
       
   120         return []
       
   121     if x[0] == 'list':
       
   122         return getlist(x[1]) + [x[2]]
       
   123     return [x]
       
   124 
       
   125 def getargs(x, min, max, err):
       
   126     l = getlist(x)
       
   127     if len(l) < min or len(l) > max:
       
   128         raise error.ParseError(err)
       
   129     return l
       
   130 
       
   131 def binary(mctx, x):
       
   132     getargs(x, 0, 0, _("binary takes no arguments"))
       
   133     return [f for f in mctx.subset if util.binary(mctx.ctx[f].data())]
       
   134 
       
   135 def exec_(mctx, x):
       
   136     getargs(x, 0, 0, _("exec takes no arguments"))
       
   137     return [f for f in mctx.subset if mctx.ctx.flags(f) == 'x']
       
   138 
       
   139 def symlink(mctx, x):
       
   140     getargs(x, 0, 0, _("symlink takes no arguments"))
       
   141     return [f for f in mctx.subset if mctx.ctx.flags(f) == 'l']
       
   142 
       
   143 symbols = {
       
   144     'binary': binary,
       
   145     'exec': exec_,
       
   146     'symlink': symlink,
       
   147 }
       
   148 
   113 methods = {
   149 methods = {
   114     'string': stringset,
   150     'string': stringset,
   115     'symbol': stringset,
   151     'symbol': stringset,
   116     'and': andset,
   152     'and': andset,
   117     'or': orset,
   153     'or': orset,
   118     'list': listset,
   154     'list': listset,
   119     'group': getset,
   155     'group': getset,
   120     'not': notset
   156     'not': notset,
       
   157     'func': func,
   121 }
   158 }
   122 
   159 
   123 class matchctx(object):
   160 class matchctx(object):
   124     def __init__(self, ctx, subset=None):
   161     def __init__(self, ctx, subset=None):
   125         self.ctx = ctx
   162         self.ctx = ctx