mercurial/fileset.py
changeset 28448 7108834c76a2
parent 28447 4eb5496c2bd4
child 29987 d532ef155b0e
equal deleted inserted replaced
28447:4eb5496c2bd4 28448:7108834c76a2
    12 from .i18n import _
    12 from .i18n import _
    13 from . import (
    13 from . import (
    14     error,
    14     error,
    15     merge,
    15     merge,
    16     parser,
    16     parser,
       
    17     registrar,
    17     util,
    18     util,
    18 )
    19 )
    19 
    20 
    20 elements = {
    21 elements = {
    21     # token-type: binding-strength, primary, prefix, infix, suffix
    22     # token-type: binding-strength, primary, prefix, infix, suffix
   142 _statuscallers = set()
   143 _statuscallers = set()
   143 
   144 
   144 # filesets using matchctx.existing()
   145 # filesets using matchctx.existing()
   145 _existingcallers = set()
   146 _existingcallers = set()
   146 
   147 
   147 def predicate(decl, callstatus=False, callexisting=False):
   148 predicate = registrar.filesetpredicate()
   148     """Return a decorator for fileset predicate function
       
   149 
       
   150     'decl' argument is the declaration (including argument list like
       
   151     'adds(pattern)') or the name (for internal use only) of predicate.
       
   152 
       
   153     Optional 'callstatus' argument indicates whether predicate implies
       
   154     'matchctx.status()' at runtime or not (False, by default).
       
   155 
       
   156     Optional 'callexisting' argument indicates whether predicate
       
   157     implies 'matchctx.existing()' at runtime or not (False, by
       
   158     default).
       
   159     """
       
   160     def decorator(func):
       
   161         i = decl.find('(')
       
   162         if i > 0:
       
   163             name = decl[:i]
       
   164         else:
       
   165             name = decl
       
   166         symbols[name] = func
       
   167         if callstatus:
       
   168             _statuscallers.add(name)
       
   169         if callexisting:
       
   170             _existingcallers.add(name)
       
   171         if func.__doc__:
       
   172             func.__doc__ = "``%s``\n    %s" % (decl, func.__doc__.strip())
       
   173         return func
       
   174     return decorator
       
   175 
   149 
   176 @predicate('modified()', callstatus=True)
   150 @predicate('modified()', callstatus=True)
   177 def modified(mctx, x):
   151 def modified(mctx, x):
   178     """File that is modified according to :hg:`status`.
   152     """File that is modified according to :hg:`status`.
   179     """
   153     """
   568         if func._callstatus:
   542         if func._callstatus:
   569             _statuscallers.add(name)
   543             _statuscallers.add(name)
   570         if func._callexisting:
   544         if func._callexisting:
   571             _existingcallers.add(name)
   545             _existingcallers.add(name)
   572 
   546 
       
   547 # load built-in predicates explicitly to setup _statuscallers/_existingcallers
       
   548 loadpredicate(None, None, predicate)
       
   549 
   573 # tell hggettext to extract docstrings from these functions:
   550 # tell hggettext to extract docstrings from these functions:
   574 i18nfunctions = symbols.values()
   551 i18nfunctions = symbols.values()