mercurial/registrar.py
changeset 43076 2372284d9457
parent 42596 83666f011679
child 43077 687b865b95ad
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
    19 #
    19 #
    20 # We still add the official API to the registrar module for consistency with
    20 # We still add the official API to the registrar module for consistency with
    21 # the other items extensions want might to register.
    21 # the other items extensions want might to register.
    22 configitem = configitems.getitemregister
    22 configitem = configitems.getitemregister
    23 
    23 
       
    24 
    24 class _funcregistrarbase(object):
    25 class _funcregistrarbase(object):
    25     """Base of decorator to register a function for specific purpose
    26     """Base of decorator to register a function for specific purpose
    26 
    27 
    27     This decorator stores decorated functions into own dict 'table'.
    28     This decorator stores decorated functions into own dict 'table'.
    28 
    29 
    45     In this case:
    46     In this case:
    46 
    47 
    47     - 'barfunc' is stored as 'bar' in '_table' of an instance 'keyword' above
    48     - 'barfunc' is stored as 'bar' in '_table' of an instance 'keyword' above
    48     - 'barfunc.__doc__' becomes ":bar: Explanation of bar keyword"
    49     - 'barfunc.__doc__' becomes ":bar: Explanation of bar keyword"
    49     """
    50     """
       
    51 
    50     def __init__(self, table=None):
    52     def __init__(self, table=None):
    51         if table is None:
    53         if table is None:
    52             self._table = {}
    54             self._table = {}
    53         else:
    55         else:
    54             self._table = table
    56             self._table = table
   119         return self._docformat % (decl, doc)
   121         return self._docformat % (decl, doc)
   120 
   122 
   121     def _extrasetup(self, name, func):
   123     def _extrasetup(self, name, func):
   122         """Execute exra setup for registered function, if needed
   124         """Execute exra setup for registered function, if needed
   123         """
   125         """
       
   126 
   124 
   127 
   125 class command(_funcregistrarbase):
   128 class command(_funcregistrarbase):
   126     """Decorator to register a command function to table
   129     """Decorator to register a command function to table
   127 
   130 
   128     This class receives a command table as its argument. The table should
   131     This class receives a command table as its argument. The table should
   196     CATEGORY_REMOTE_REPO_MANAGEMENT = 'remote'
   199     CATEGORY_REMOTE_REPO_MANAGEMENT = 'remote'
   197     CATEGORY_COMMITTING = 'commit'
   200     CATEGORY_COMMITTING = 'commit'
   198     CATEGORY_CHANGE_MANAGEMENT = 'management'
   201     CATEGORY_CHANGE_MANAGEMENT = 'management'
   199     CATEGORY_CHANGE_ORGANIZATION = 'organization'
   202     CATEGORY_CHANGE_ORGANIZATION = 'organization'
   200     CATEGORY_FILE_CONTENTS = 'files'
   203     CATEGORY_FILE_CONTENTS = 'files'
   201     CATEGORY_CHANGE_NAVIGATION  = 'navigation'
   204     CATEGORY_CHANGE_NAVIGATION = 'navigation'
   202     CATEGORY_WORKING_DIRECTORY = 'wdir'
   205     CATEGORY_WORKING_DIRECTORY = 'wdir'
   203     CATEGORY_IMPORT_EXPORT = 'import'
   206     CATEGORY_IMPORT_EXPORT = 'import'
   204     CATEGORY_MAINTENANCE = 'maintenance'
   207     CATEGORY_MAINTENANCE = 'maintenance'
   205     CATEGORY_HELP = 'help'
   208     CATEGORY_HELP = 'help'
   206     CATEGORY_MISC = 'misc'
   209     CATEGORY_MISC = 'misc'
   207     CATEGORY_NONE = 'none'
   210     CATEGORY_NONE = 'none'
   208 
   211 
   209     def _doregister(self, func, name, options=(), synopsis=None,
   212     def _doregister(
   210                     norepo=False, optionalrepo=False, inferrepo=False,
   213         self,
   211                     intents=None, helpcategory=None, helpbasic=False):
   214         func,
       
   215         name,
       
   216         options=(),
       
   217         synopsis=None,
       
   218         norepo=False,
       
   219         optionalrepo=False,
       
   220         inferrepo=False,
       
   221         intents=None,
       
   222         helpcategory=None,
       
   223         helpbasic=False,
       
   224     ):
   212         func.norepo = norepo
   225         func.norepo = norepo
   213         func.optionalrepo = optionalrepo
   226         func.optionalrepo = optionalrepo
   214         func.inferrepo = inferrepo
   227         func.inferrepo = inferrepo
   215         func.intents = intents or set()
   228         func.intents = intents or set()
   216         func.helpcategory = helpcategory
   229         func.helpcategory = helpcategory
   219             self._table[name] = func, list(options), synopsis
   232             self._table[name] = func, list(options), synopsis
   220         else:
   233         else:
   221             self._table[name] = func, list(options)
   234             self._table[name] = func, list(options)
   222         return func
   235         return func
   223 
   236 
       
   237 
   224 INTENT_READONLY = b'readonly'
   238 INTENT_READONLY = b'readonly'
       
   239 
   225 
   240 
   226 class revsetpredicate(_funcregistrarbase):
   241 class revsetpredicate(_funcregistrarbase):
   227     """Decorator to register revset predicate
   242     """Decorator to register revset predicate
   228 
   243 
   229     Usage::
   244     Usage::
   261     extension, if an instance named as 'revsetpredicate' is used for
   276     extension, if an instance named as 'revsetpredicate' is used for
   262     decorating in extension.
   277     decorating in extension.
   263 
   278 
   264     Otherwise, explicit 'revset.loadpredicate()' is needed.
   279     Otherwise, explicit 'revset.loadpredicate()' is needed.
   265     """
   280     """
       
   281 
   266     _getname = _funcregistrarbase._parsefuncdecl
   282     _getname = _funcregistrarbase._parsefuncdecl
   267     _docformat = "``%s``\n    %s"
   283     _docformat = "``%s``\n    %s"
   268 
   284 
   269     def _extrasetup(self, name, func, safe=False, takeorder=False, weight=1):
   285     def _extrasetup(self, name, func, safe=False, takeorder=False, weight=1):
   270         func._safe = safe
   286         func._safe = safe
   271         func._takeorder = takeorder
   287         func._takeorder = takeorder
   272         func._weight = weight
   288         func._weight = weight
       
   289 
   273 
   290 
   274 class filesetpredicate(_funcregistrarbase):
   291 class filesetpredicate(_funcregistrarbase):
   275     """Decorator to register fileset predicate
   292     """Decorator to register fileset predicate
   276 
   293 
   277     Usage::
   294     Usage::
   310     extension, if an instance named as 'filesetpredicate' is used for
   327     extension, if an instance named as 'filesetpredicate' is used for
   311     decorating in extension.
   328     decorating in extension.
   312 
   329 
   313     Otherwise, explicit 'fileset.loadpredicate()' is needed.
   330     Otherwise, explicit 'fileset.loadpredicate()' is needed.
   314     """
   331     """
       
   332 
   315     _getname = _funcregistrarbase._parsefuncdecl
   333     _getname = _funcregistrarbase._parsefuncdecl
   316     _docformat = "``%s``\n    %s"
   334     _docformat = "``%s``\n    %s"
   317 
   335 
   318     def _extrasetup(self, name, func, callstatus=False, weight=1):
   336     def _extrasetup(self, name, func, callstatus=False, weight=1):
   319         func._callstatus = callstatus
   337         func._callstatus = callstatus
   320         func._weight = weight
   338         func._weight = weight
   321 
   339 
       
   340 
   322 class _templateregistrarbase(_funcregistrarbase):
   341 class _templateregistrarbase(_funcregistrarbase):
   323     """Base of decorator to register functions as template specific one
   342     """Base of decorator to register functions as template specific one
   324     """
   343     """
       
   344 
   325     _docformat = ":%s: %s"
   345     _docformat = ":%s: %s"
       
   346 
   326 
   347 
   327 class templatekeyword(_templateregistrarbase):
   348 class templatekeyword(_templateregistrarbase):
   328     """Decorator to register template keyword
   349     """Decorator to register template keyword
   329 
   350 
   330     Usage::
   351     Usage::
   354     """
   375     """
   355 
   376 
   356     def _extrasetup(self, name, func, requires=()):
   377     def _extrasetup(self, name, func, requires=()):
   357         func._requires = requires
   378         func._requires = requires
   358 
   379 
       
   380 
   359 class templatefilter(_templateregistrarbase):
   381 class templatefilter(_templateregistrarbase):
   360     """Decorator to register template filer
   382     """Decorator to register template filer
   361 
   383 
   362     Usage::
   384     Usage::
   363 
   385 
   384     Otherwise, explicit 'templatefilters.loadkeyword()' is needed.
   406     Otherwise, explicit 'templatefilters.loadkeyword()' is needed.
   385     """
   407     """
   386 
   408 
   387     def _extrasetup(self, name, func, intype=None):
   409     def _extrasetup(self, name, func, intype=None):
   388         func._intype = intype
   410         func._intype = intype
       
   411 
   389 
   412 
   390 class templatefunc(_templateregistrarbase):
   413 class templatefunc(_templateregistrarbase):
   391     """Decorator to register template function
   414     """Decorator to register template function
   392 
   415 
   393     Usage::
   416     Usage::
   417     extension, if an instance named as 'templatefunc' is used for
   440     extension, if an instance named as 'templatefunc' is used for
   418     decorating in extension.
   441     decorating in extension.
   419 
   442 
   420     Otherwise, explicit 'templatefuncs.loadfunction()' is needed.
   443     Otherwise, explicit 'templatefuncs.loadfunction()' is needed.
   421     """
   444     """
       
   445 
   422     _getname = _funcregistrarbase._parsefuncdecl
   446     _getname = _funcregistrarbase._parsefuncdecl
   423 
   447 
   424     def _extrasetup(self, name, func, argspec=None, requires=()):
   448     def _extrasetup(self, name, func, argspec=None, requires=()):
   425         func._argspec = argspec
   449         func._argspec = argspec
   426         func._requires = requires
   450         func._requires = requires
       
   451 
   427 
   452 
   428 class internalmerge(_funcregistrarbase):
   453 class internalmerge(_funcregistrarbase):
   429     """Decorator to register in-process merge tool
   454     """Decorator to register in-process merge tool
   430 
   455 
   431     Usage::
   456     Usage::
   478     extension, if an instance named as 'internalmerge' is used for
   503     extension, if an instance named as 'internalmerge' is used for
   479     decorating in extension.
   504     decorating in extension.
   480 
   505 
   481     Otherwise, explicit 'filemerge.loadinternalmerge()' is needed.
   506     Otherwise, explicit 'filemerge.loadinternalmerge()' is needed.
   482     """
   507     """
       
   508 
   483     _docformat = "``:%s``\n    %s"
   509     _docformat = "``:%s``\n    %s"
   484 
   510 
   485     # merge type definitions:
   511     # merge type definitions:
   486     nomerge = None
   512     nomerge = None
   487     mergeonly = 'mergeonly'  # just the full merge, no premerge
   513     mergeonly = 'mergeonly'  # just the full merge, no premerge
   488     fullmerge = 'fullmerge'  # both premerge and merge
   514     fullmerge = 'fullmerge'  # both premerge and merge
   489 
   515 
   490     def _extrasetup(self, name, func, mergetype,
   516     def _extrasetup(
   491                     onfailure=None, precheck=None,
   517         self,
   492                     binary=False, symlink=False):
   518         name,
       
   519         func,
       
   520         mergetype,
       
   521         onfailure=None,
       
   522         precheck=None,
       
   523         binary=False,
       
   524         symlink=False,
       
   525     ):
   493         func.mergetype = mergetype
   526         func.mergetype = mergetype
   494         func.onfailure = onfailure
   527         func.onfailure = onfailure
   495         func.precheck = precheck
   528         func.precheck = precheck
   496 
   529 
   497         binarycap = binary or mergetype == self.nomerge
   530         binarycap = binary or mergetype == self.nomerge