mercurial/revset.py
changeset 28395 0383f7a5e86c
parent 28393 ac11ba7c2e56
child 28423 0d79d91ba7e3
equal deleted inserted replaced
28394:dcb4209bd30d 28395:0383f7a5e86c
   480 # symbols which can't be used for a DoS attack for any given input
   480 # symbols which can't be used for a DoS attack for any given input
   481 # (e.g. those which accept regexes as plain strings shouldn't be included)
   481 # (e.g. those which accept regexes as plain strings shouldn't be included)
   482 # functions that just return a lot of changesets (like all) don't count here
   482 # functions that just return a lot of changesets (like all) don't count here
   483 safesymbols = set()
   483 safesymbols = set()
   484 
   484 
   485 class predicate(registrar.funcregistrar):
   485 predicate = registrar.revsetpredicate()
   486     """Decorator to register revset predicate
       
   487 
       
   488     Usage::
       
   489 
       
   490         @predicate('mypredicate(arg1, arg2[, arg3])')
       
   491         def mypredicatefunc(repo, subset, x):
       
   492             '''Explanation of this revset predicate ....
       
   493             '''
       
   494             pass
       
   495 
       
   496     The first string argument of the constructor is used also in
       
   497     online help.
       
   498 
       
   499     Use 'extpredicate' instead of this to register revset predicate in
       
   500     extensions.
       
   501     """
       
   502     table = symbols
       
   503     formatdoc = "``%s``\n    %s"
       
   504     getname = registrar.funcregistrar.parsefuncdecl
       
   505 
       
   506     def __init__(self, decl, safe=False):
       
   507         """'safe' indicates whether a predicate is safe for DoS attack
       
   508         """
       
   509         super(predicate, self).__init__(decl)
       
   510         self.safe = safe
       
   511 
       
   512     def extraaction(self, name, func):
       
   513         if self.safe:
       
   514             safesymbols.add(name)
       
   515 
   486 
   516 class extpredicate(registrar.delayregistrar):
   487 class extpredicate(registrar.delayregistrar):
   517     """Decorator to register revset predicate in extensions
   488     """Decorator to register revset predicate in extensions
   518 
   489 
   519     Usage::
   490     Usage::
  3634     for name, func in registrarobj._table.iteritems():
  3605     for name, func in registrarobj._table.iteritems():
  3635         symbols[name] = func
  3606         symbols[name] = func
  3636         if func._safe:
  3607         if func._safe:
  3637             safesymbols.add(name)
  3608             safesymbols.add(name)
  3638 
  3609 
       
  3610 # load built-in predicates explicitly to setup safesymbols
       
  3611 loadpredicate(None, None, predicate)
       
  3612 
  3639 # tell hggettext to extract docstrings from these functions:
  3613 # tell hggettext to extract docstrings from these functions:
  3640 i18nfunctions = symbols.values()
  3614 i18nfunctions = symbols.values()