File: //usr/lib/python3/dist-packages/mercurial/__pycache__/exthelper.cpython-310.pyc
o
�]LbU/ � @ sH d dl mZ ddlmZmZmZmZmZ d dlm Z G dd� de
�ZdS )� )�absolute_import� )�commands�error�
extensions�pycompat� registrar)�tracingc @ sr e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zdd� Zdd� Z
ddd�Zdd� ZdS )� 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'
c C st g | _ g | _g | _g | _g | _g | _g | _i | _t� | j�| _ i | _
t�| j
�| _t�� | _t�
� | _
t�� | _d S �N)�_uipopulatecallables�_uicallables�
_extcallables�_repocallables�_commandwrappers�_extcommandwrappers�_functionwrappers�cmdtabler �command�configtable�
configitem�filesetpredicate�revsetpredicate�templatekeyword)�self� r �5/usr/lib/python3/dist-packages/mercurial/exthelper.py�__init__Z s
zexthelper.__init__c C s� | j �|j � | j�|j� | j�|j� | j�|j� | j�|j� | j�|j� | j�|j� | j �|j � | j
�|j
� | j�|j� | j�
|j� t�|j�D ]\}}|| jv re| j| �
|� qS|| j|<