^c /DddlmZmZmZmZddlmZGddZdS))commandserror extensions registrar)tracingc\eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z dd ZdZd S) exthelperaM Helper for modular extension setup A single helper should be instantiated for each module of an extension, where a command or function needs to be wrapped, or a command, extension hook, fileset, revset or template needs to be registered. Helper methods are then used as decorators for these various purposes. If an extension spans multiple modules, all helper instances should be merged in the main module. All decorators return the original function and may be chained. Aside from the helper functions with examples below, several registrar method aliases are available for adding commands, configitems, filesets, revsets, and templates. Simply decorate the appropriate methods, and assign the corresponding exthelper variable to a module level variable of the extension. The extension loading mechanism will handle the rest. example:: # ext.py eh = exthelper.exthelper() # As needed (failure to do this will mean your registration will not # happen): cmdtable = eh.cmdtable configtable = eh.configtable filesetpredicate = eh.filesetpredicate revsetpredicate = eh.revsetpredicate templatekeyword = eh.templatekeyword # As needed (failure to do this will mean your eh.wrap*-decorated # functions will not wrap, and/or your eh.*setup-decorated functions # will not execute): uisetup = eh.finaluisetup extsetup = eh.finalextsetup reposetup = eh.finalreposetup uipopulate = eh.finaluipopulate @eh.command(b'mynewcommand', [(b'r', b'rev', [], _(b'operate on these revisions'))], _(b'-r REV...'), helpcategory=command.CATEGORY_XXX) def newcommand(ui, repo, *revs, **opts): # implementation goes here eh.configitem(b'experimental', b'foo', default=False, ) @eh.filesetpredicate(b'lfs()') def filesetbabar(mctx, x): return mctx.predicate(...) @eh.revsetpredicate(b'hidden') def revsetbabar(repo, subset, x): args = revset.getargs(x, 0, 0, b'babar accept no argument') return [r for r in subset if b'babar' in repo[r].description()] @eh.templatekeyword(b'babar') def kwbabar(ctx): return b'babar' cg|_g|_g|_g|_g|_g|_g|_i|_tj |j|_ i|_ tj |j |_ tj |_ tj |_ tj|_dSN)_uipopulatecallables _uicallables _extcallables_repocallables_commandwrappers_extcommandwrappers_functionwrapperscmdtablercommand configtable configitemfilesetpredicaterevsetpredicatetemplatekeyword)selfs 5/usr/lib/python3/dist-packages/mercurial/exthelper.py__init__zexthelper.__init__Xs$&!  "#% !#  (77 #.t/?@@ ) : < <(8::(8::cV|j|j|j|j|j|j|j|j|j|j|j|j|j|j|j |j |j |j |j |j |j |j |jD]9\}}||jvr!|j| |/||j|<:dSr )rextendr rrr_mergerrrrrrupdateritems)rothersectionr#s rmergezexthelper.mergehs   !3444 !(()CDDD !!%"5666 ""5#7888 $$U%;<<< ##E$9::: ##E$9::: $$U%;<<<  ''(ABBB %%e&=>>> U^,,,#/5577 2 2NGU$*** )007777,1 ))  2 2rc|jD]H\}}}tjtj||}|r |D]}|d|I|jD]\}}}tj||||jD]G} tj dt| 5| |dddn #1swxYwYHdS)aDMethod to be used as the extension uisetup The following operations belong here: - Changes to ui.__class__ . The ui object that will be used to run the command has not yet been created. Changes made here will affect ui objects created after this, and in particular the ui that will be passed to runcommand - Command wraps (extensions.wrapcommand) - Changes that need to be visible to other extensions: because initialization occurs in phases (all extensions run uisetup, then all run extsetup), a change made here will be visible to other extensions during extsetup - Monkeypatch or wrap function (extensions.wrapfunction) of dispatch module members - Setup of pre-* and post-* hooks - pushkey setup rzfinaluisetup: %sN) rr wrapcommandrtableappendr wrapfunctionrrlogrepr) ruirwrapperoptsentryoptcontfuncnamecs r finaluisetupzexthelper.finaluisetupzs-&'+&; ) ) "GWd*8>7GLLE )))C!HOOC(((('+'= = = #D(G  #D(G < < < <"  A/a99  "                 s B88B< ?B< c0|jD] }||dS)zMethod to be used as the extension uipopulate This is called once per ui instance to: - Set up additional ui members - Update configuration by ``ui.setconfig()`` - Extend the class dynamically N)r )rr.r5s rfinaluipopulatezexthelper.finaluipopulates/*  A AbEEEE  rci}|jD]y\}}}}||vr0 tj|}n#t$rY-wxYw|j||<tj||||}|r |D]} |d| z|jD]G} tj dt| 5| |dddn #1swxYwYHdS)zMethod to be used as the extension extsetup The following operations belong here: - Changes depending on the status of other extensions. (if extensions.find(b'mq')) - Add a global option to all commands rzfinalextsetup: %sN) rrfindKeyErrorrr(r*rrr,r-) rr. knownextsextrr/r0er1r2r5s r finalextsetupzexthelper.finalextsetupsU +/+C ) ) 'C'4)##",,AAH"# #*9S>7GLLE )))C!HOOC((((#  A0$q''::  "                 s+ 88/ CC C c|jD]H}tjdt|5|||dddn #1swxYwYIdS)zMethod to be used as the extension reposetup The following operations belong here: - All hooks but pre-* and post-* - Modify configuration variables - Changes to repo.__class__, repo.dirstate.__class__ zfinalreposetup: %sN)rrr,r-)rr.repor5s rfinalreposetupzexthelper.finalreposetups$  A1477;;  "d                  s AA A c:|j||S)a%Decorated function will be executed during uisetup example:: # Required, otherwise your uisetup function(s) will not execute. uisetup = eh.finaluisetup @eh.uisetup def setupbabar(ui): print('this is uisetup!') )rr*rcalls ruisetupzexthelper.uisetups    &&& rc:|j||S)a5Decorated function will be executed during uipopulate example:: # Required, otherwise your uipopulate function(s) will not execute. uipopulate = eh.finaluipopulate @eh.uipopulate def setupfoo(ui): print('this is uipopulate!') )r r*rDs r uipopulatezexthelper.uipopulates  !((... rc:|j||S)a/Decorated function will be executed during extsetup example:: # Required, otherwise your extsetup function(s) will not execute. extsetup = eh.finalextsetup @eh.extsetup def setupcelestine(ui): print('this is extsetup!') )rr*rDs rextsetupzexthelper.extsetups  !!$''' rc:|j||S)a8Decorated function will be executed during reposetup example:: # Required, otherwise your reposetup function(s) will not execute. reposetup = eh.finalreposetup @eh.reposetup def setupzephir(ui, repo): print('this is reposetup!') )rr*rDs r reposetupzexthelper.reposetups  ""4((( rNcgnUD]R}t|tstjdt |dvrd}tj|Sfd}|S)aVDecorated function is a command wrapper The name of the command must be given as the decorator argument. The wrapping is installed during `uisetup`. If the second option `extension` argument is provided, the wrapping will be applied in the extension commandtable. This argument must be a string that will be searched using `extension.find` if not found and Abort error is raised. If the wrapping applies to an extension, it is installed during `extsetup`. example:: # Required if `extension` is not provided uisetup = eh.finaluisetup # Required if `extension` is provided extsetup = eh.finalextsetup @eh.wrapcommand(b'summary') def wrapsummary(orig, ui, repo, *args, **kwargs): ui.note(b'Barry!') return orig(ui, repo, *args, **kwargs) The `opts` argument allows specifying a list of tuples for additional arguments for the command. See ``mercurial.fancyopts.fancyopts()`` for the format of the tuple. Nsopts must be list of tuples)s)each opt tuple must contain 4 or 5 valuescj|fnj|f|Sr )rr*r)r/r extensionr0rs rdecz"exthelper.wrapcommand..dec1sX %,,gw-EFFFF(//$7Nr) isinstancetuplerProgrammingErrorlen)rrrQr0r2msgrRs```` rr(zexthelper.wrapcommand s: <DD 6 6!#u--Q01OPPPs886))FC0555*         rcfd}|S)aLDecorated function is a function wrapper This function takes two arguments, the container and the name of the function to wrap. The wrapping is performed during `uisetup`. (there is no extension support) example:: # Required, otherwise the function will not be wrapped uisetup = eh.finaluisetup @eh.wrapfunction(discovery, b'checkheads') def wrapcheckheads(orig, *args, **kwargs): ui.note(b'His head smashed in and his heart cut out') return orig(*args, **kwargs) cBj|f|Sr )rr*)r/ containerr4rs rrRz#exthelper.wrapfunction..decNs&  " ) )9h*H I I INr)rrZr4rRs``` rr+zexthelper.wrapfunction<s/$        r)NN)__name__ __module__ __qualname____doc__rr&r6r8r?rBrFrHrJrLr(r+r[rrr r s>>@;;; 222$<   :               0000drr N)rrrrhgdemandimportrr r[rrrbs#"""""{{{{{{{{{{r