
    6h./                    H    S SK Jr  SSKJrJrJrJr  S SKJr   " S S5      r	g)    )annotations   )commandserror
extensions	registrar)tracingc                  d    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rSS jrS rSrg)	exthelper   a  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'
c                   / U l         / U l        / U l        / U l        / U l        / U l        / U l        0 U l        [        R                  " U R                  5      U l	        0 U l
        [        R                  " U R                  5      U l        [        R                  " 5       U l        [        R                  " 5       U l        [        R                  " 5       U l        g N)_uipopulatecallables_uicallables_extcallables_repocallables_commandwrappers_extcommandwrappers_functionwrapperscmdtabler   commandconfigtable
configitemfilesetpredicaterevsetpredicatetemplatekeyword)selfs    5/usr/lib/python3/dist-packages/mercurial/exthelper.py__init__exthelper.__init__Y   s    $&!  "#% !# ((7#..t/?/?@ ) : : <(88:(88:    c                   U R                   R                  UR                   5        U R                  R                  UR                  5        U R                  R                  UR                  5        U R                  R                  UR                  5        U R
                  R                  UR
                  5        U R                  R                  UR                  5        U R                  R                  UR                  5        U R                  R                  UR                  5        U R                  R                  UR                  5        U R                  R                  UR                  5        U R                  R                  UR                  5        UR                  R                  5        HB  u  p#X R                  ;   a   U R                  U   R                  U5        M4  X0R                  U'   MD     g r   )r   extendr   r   r   r   _merger   r   r   r   r   r   updater   items)r   othersectionr&   s       r   mergeexthelper.mergei   sj     !3!34!!(()C)CD!!%"5"56""5#7#78$$U%;%;<##E$9$9:##E$9$9:$$U%;%;<  ''(A(AB%%e&=&=>U^^,#//557NG***  )007,1  )	 8r!   c                   U R                    HQ  u  p#n[        R                  " [        R                  X#5      nU(       d  M4  U H  nUS   R                  U5        M     MS     U R                   H  u  pxn[        R                  " XxU5        M     U R                   H4  n	[        R                  " S[        U	5      5         U	" U5        SSS5        M6     g! , (       d  f       MH  = f)a  Method 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
r   zfinaluisetup: %sN)r   r   wrapcommandr   tableappendr   wrapfunctionr   r	   logrepr)
r   uir   wrapperoptsentryoptcontfuncnamecs
             r   finaluisetupexthelper.finaluisetup{   s    & '+&;&;"Gd**8>>7LEtC!HOOC(   '<
 (,'='=#DG##DG< (>""A/a9" :9 #99s   >	C
C#	c                :    U R                    H  nU" U5        M     g)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   )r   r2   r9   s      r   finaluipopulateexthelper.finaluipopulate   s     **AbE +r!   c                   0 nU R                    Ho  u  p4pVX2;  a%   [        R                  " U5      nUR                  X#'   [        R
                  " X#   XE5      nU(       d  MR  U H  n	US   R                  U	5        M     Mq     U R                   H4  n
[        R                  " S[        U
5      5         U
" U5        SSS5        M6     g! [         a     M  f = f! , (       d  f       MY  = f)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
r   zfinalextsetup: %sN)r   r   findKeyErrorr   r,   r.   r   r	   r0   r1   )r   r2   	knownextsextr   r3   r4   er5   r6   r9   s              r   finalextsetupexthelper.finalextsetup   s     	+/+C+C'C'#",A
 "#	**9>7LEtC!HOOC(   ,D ##A0$q':" ;: $     ;:s   C1	C
CC
C'	c                    U R                    H4  n[        R                  " S[        U5      5         U" X5        SSS5        M6     g! , (       d  f       MH  = f)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__
zfinalreposetup: %sN)r   r	   r0   r1   )r   r2   repor9   s       r   finalreposetupexthelper.finalreposetup   s=     $$A147;" <; %;;s   	A
A	c                <    U R                   R                  U5        U$ )zDecorated 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!')
)r   r.   r   calls     r   uisetupexthelper.uisetup   s     	  &r!   c                <    U R                   R                  U5        U$ )zDecorated 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.   rL   s     r   
uipopulateexthelper.uipopulate   s     	!!((.r!   c                <    U R                   R                  U5        U$ )zDecorated 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!')
)r   r.   rL   s     r   extsetupexthelper.extsetup   s     	!!$'r!   c                <    U R                   R                  U5        U$ )a   Decorated 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!')
)r   r.   rL   s     r   	reposetupexthelper.reposetup   s     	""4(r!   Nc                   ^ ^^^ Tc  / mO[T HU  n[        U[        5      (       d  [        R                  " S5      e[	        U5      S;  d  M?  Sn[        R                  " U5      e   UUUU 4S jnU$ )a  Decorated 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.

s   opts must be list of tuples)      s)   each opt tuple must contain 4 or 5 valuesc                   > Tc   TR                   R                  TU T45        U $ TR                  R                  TTU T45        U $ r   )r   r.   r   )r3   r   	extensionr4   r   s    r   dec"exthelper.wrapcommand.<locals>.dec2  sT     %%,,gw-EF
 N ((//$7 Nr!   )
isinstancetupler   ProgrammingErrorlen)r   r   r]   r4   r6   msgr^   s   ````   r   r,   exthelper.wrapcommand  sk    : <D!#u--001OPPs86)FC0055 	 	 
r!   c                   ^ ^^ UUU 4S jnU$ )a  Decorated 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, 'checkheads')
    def wrapcheckheads(orig, *args, **kwargs):
        ui.note(b'His head smashed in and his heart cut out')
        return orig(*args, **kwargs)
c                D   > TR                   R                  TTU 45        U $ r   )r   r.   )r3   	containerr8   r   s    r   r^   #exthelper.wrapfunction.<locals>.decO  s#    ""))9h*HINr!    )r   rh   r8   r^   s   ``` r   r/   exthelper.wrapfunction=  s    $	 
r!   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   )NN)__name__
__module____qualname____firstlineno____doc__r   r)   r:   r=   rE   rI   rN   rQ   rT   rW   r,   r/   __static_attributes__rj   r!   r   r   r      sE    >@; 2$<
:0dr!   r   N)

__future__r    r   r   r   r   hgdemandimportr	   r   rj   r!   r   <module>ru      s%    #  #{ {r!   