mercurial/exthelper.py
author Simon Sapin <simon.sapin@octobus.net>
Tue, 09 Nov 2021 19:09:57 +0100
changeset 48339 a2e278b5e265
parent 46871 887f89b100ac
child 48875 6000f5b25c9b
permissions -rw-r--r--
rhg: [encode] and [decode] config sections are not supported Differential Revision: https://phab.mercurial-scm.org/D11761
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     1
# Copyright 2012 Logilab SA        <contact@logilab.fr>
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     2
#                Pierre-Yves David <pierre-yves.david@ens-lyon.org>
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     3
#                Octobus <contact@octobus.net>
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     4
#
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     7
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     8
#####################################################################
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
     9
### Extension helper                                              ###
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    10
#####################################################################
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    11
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    12
from __future__ import absolute_import
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    13
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    14
from . import (
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    15
    commands,
41060
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
    16
    error,
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    17
    extensions,
42316
c07dcf7a0247 exthelper: add some semi-useful trace logs
Augie Fackler <augie@google.com>
parents: 41279
diff changeset
    18
    pycompat,
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    19
    registrar,
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    20
)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    21
42316
c07dcf7a0247 exthelper: add some semi-useful trace logs
Augie Fackler <augie@google.com>
parents: 41279
diff changeset
    22
from hgdemandimport import tracing
c07dcf7a0247 exthelper: add some semi-useful trace logs
Augie Fackler <augie@google.com>
parents: 41279
diff changeset
    23
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42316
diff changeset
    24
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    25
class exthelper(object):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    26
    """Helper for modular extension setup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    27
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    28
    A single helper should be instantiated for each module of an
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    29
    extension, where a command or function needs to be wrapped, or a
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    30
    command, extension hook, fileset, revset or template needs to be
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    31
    registered.  Helper methods are then used as decorators for
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    32
    these various purposes.  If an extension spans multiple modules,
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    33
    all helper instances should be merged in the main module.
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    34
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    35
    All decorators return the original function and may be chained.
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    36
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    37
    Aside from the helper functions with examples below, several
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    38
    registrar method aliases are available for adding commands,
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    39
    configitems, filesets, revsets, and templates.  Simply decorate
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    40
    the appropriate methods, and assign the corresponding exthelper
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    41
    variable to a module level variable of the extension.  The
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    42
    extension loading mechanism will handle the rest.
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    43
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    44
    example::
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    45
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    46
        # ext.py
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    47
        eh = exthelper.exthelper()
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    48
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    49
        # As needed (failure to do this will mean your registration will not
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    50
        # happen):
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    51
        cmdtable = eh.cmdtable
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    52
        configtable = eh.configtable
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    53
        filesetpredicate = eh.filesetpredicate
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    54
        revsetpredicate = eh.revsetpredicate
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    55
        templatekeyword = eh.templatekeyword
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    56
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    57
        # As needed (failure to do this will mean your eh.wrap*-decorated
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    58
        # functions will not wrap, and/or your eh.*setup-decorated functions
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    59
        # will not execute):
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    60
        uisetup = eh.finaluisetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    61
        extsetup = eh.finalextsetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    62
        reposetup = eh.finalreposetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    63
        uipopulate = eh.finaluipopulate
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
    64
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    65
        @eh.command(b'mynewcommand',
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    66
            [(b'r', b'rev', [], _(b'operate on these revisions'))],
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    67
            _(b'-r REV...'),
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    68
            helpcategory=command.CATEGORY_XXX)
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    69
        def newcommand(ui, repo, *revs, **opts):
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    70
            # implementation goes here
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    71
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    72
        eh.configitem(b'experimental', b'foo',
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    73
            default=False,
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    74
        )
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    75
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    76
        @eh.filesetpredicate(b'lfs()')
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    77
        def filesetbabar(mctx, x):
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    78
            return mctx.predicate(...)
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    79
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    80
        @eh.revsetpredicate(b'hidden')
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    81
        def revsetbabar(repo, subset, x):
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    82
            args = revset.getargs(x, 0, 0, b'babar accept no argument')
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    83
            return [r for r in subset if b'babar' in repo[r].description()]
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    84
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    85
        @eh.templatekeyword(b'babar')
41071
c81bb97b0cac exthelper: add some examples for using registrar aliases
Matt Harbison <matt_harbison@yahoo.com>
parents: 41070
diff changeset
    86
        def kwbabar(ctx):
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
    87
            return b'babar'
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    88
    """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    89
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    90
    def __init__(self):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    91
        self._uipopulatecallables = []
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    92
        self._uicallables = []
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    93
        self._extcallables = []
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    94
        self._repocallables = []
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    95
        self._commandwrappers = []
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    96
        self._extcommandwrappers = []
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    97
        self._functionwrappers = []
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    98
        self.cmdtable = {}
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
    99
        self.command = registrar.command(self.cmdtable)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   100
        self.configtable = {}
41045
c1476d095d57 exthelper: simplify configitem registration
Matt Harbison <matt_harbison@yahoo.com>
parents: 41044
diff changeset
   101
        self.configitem = registrar.configitem(self.configtable)
41070
8f40e21ca842 exthelper: reintroduce the ability to register filesets
Matt Harbison <matt_harbison@yahoo.com>
parents: 41069
diff changeset
   102
        self.filesetpredicate = registrar.filesetpredicate()
41066
0358cca1dccf exthelper: reintroduce the ability to register revsets
Matt Harbison <matt_harbison@yahoo.com>
parents: 41060
diff changeset
   103
        self.revsetpredicate = registrar.revsetpredicate()
41069
70ca0e846d25 exthelper: reintroduce the ability to register templates
Matt Harbison <matt_harbison@yahoo.com>
parents: 41066
diff changeset
   104
        self.templatekeyword = registrar.templatekeyword()
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   105
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   106
    def merge(self, other):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   107
        self._uicallables.extend(other._uicallables)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   108
        self._uipopulatecallables.extend(other._uipopulatecallables)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   109
        self._extcallables.extend(other._extcallables)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   110
        self._repocallables.extend(other._repocallables)
41082
4d40f6bb4cef exthelper: switch to using the registrar merging method
Matt Harbison <matt_harbison@yahoo.com>
parents: 41071
diff changeset
   111
        self.filesetpredicate._merge(other.filesetpredicate)
4d40f6bb4cef exthelper: switch to using the registrar merging method
Matt Harbison <matt_harbison@yahoo.com>
parents: 41071
diff changeset
   112
        self.revsetpredicate._merge(other.revsetpredicate)
4d40f6bb4cef exthelper: switch to using the registrar merging method
Matt Harbison <matt_harbison@yahoo.com>
parents: 41071
diff changeset
   113
        self.templatekeyword._merge(other.templatekeyword)
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   114
        self._commandwrappers.extend(other._commandwrappers)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   115
        self._extcommandwrappers.extend(other._extcommandwrappers)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   116
        self._functionwrappers.extend(other._functionwrappers)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   117
        self.cmdtable.update(other.cmdtable)
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43077
diff changeset
   118
        for section, items in pycompat.iteritems(other.configtable):
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   119
            if section in self.configtable:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   120
                self.configtable[section].update(items)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   121
            else:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   122
                self.configtable[section] = items
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   123
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   124
    def finaluisetup(self, ui):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   125
        """Method to be used as the extension uisetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   126
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   127
        The following operations belong here:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   128
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   129
        - Changes to ui.__class__ . The ui object that will be used to run the
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   130
          command has not yet been created. Changes made here will affect ui
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   131
          objects created after this, and in particular the ui that will be
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   132
          passed to runcommand
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   133
        - Command wraps (extensions.wrapcommand)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   134
        - Changes that need to be visible to other extensions: because
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   135
          initialization occurs in phases (all extensions run uisetup, then all
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   136
          run extsetup), a change made here will be visible to other extensions
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   137
          during extsetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   138
        - Monkeypatch or wrap function (extensions.wrapfunction) of dispatch
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   139
          module members
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   140
        - Setup of pre-* and post-* hooks
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   141
        - pushkey setup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   142
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   143
        for command, wrapper, opts in self._commandwrappers:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   144
            entry = extensions.wrapcommand(commands.table, command, wrapper)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   145
            if opts:
41060
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   146
                for opt in opts:
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   147
                    entry[1].append(opt)
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   148
        for cont, funcname, wrapper in self._functionwrappers:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   149
            extensions.wrapfunction(cont, funcname, wrapper)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   150
        for c in self._uicallables:
43238
101ae8bbfa02 cleanup: hgdemandimport.tracing accepts strings, not bytes
Augie Fackler <augie@google.com>
parents: 43106
diff changeset
   151
            with tracing.log('finaluisetup: %s', repr(c)):
42316
c07dcf7a0247 exthelper: add some semi-useful trace logs
Augie Fackler <augie@google.com>
parents: 41279
diff changeset
   152
                c(ui)
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   153
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   154
    def finaluipopulate(self, ui):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   155
        """Method to be used as the extension uipopulate
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   156
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   157
        This is called once per ui instance to:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   158
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   159
        - Set up additional ui members
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   160
        - Update configuration by ``ui.setconfig()``
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   161
        - Extend the class dynamically
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   162
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   163
        for c in self._uipopulatecallables:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   164
            c(ui)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   165
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   166
    def finalextsetup(self, ui):
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   167
        """Method to be used as the extension extsetup
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   168
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   169
        The following operations belong here:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   170
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   171
        - Changes depending on the status of other extensions. (if
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
   172
          extensions.find(b'mq'))
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   173
        - Add a global option to all commands
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   174
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   175
        knownexts = {}
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   176
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   177
        for ext, command, wrapper, opts in self._extcommandwrappers:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   178
            if ext not in knownexts:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   179
                try:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   180
                    e = extensions.find(ext)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   181
                except KeyError:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   182
                    # Extension isn't enabled, so don't bother trying to wrap
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   183
                    # it.
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   184
                    continue
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   185
                knownexts[ext] = e.cmdtable
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   186
            entry = extensions.wrapcommand(knownexts[ext], command, wrapper)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   187
            if opts:
41060
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   188
                for opt in opts:
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   189
                    entry[1].append(opt)
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   190
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   191
        for c in self._extcallables:
43238
101ae8bbfa02 cleanup: hgdemandimport.tracing accepts strings, not bytes
Augie Fackler <augie@google.com>
parents: 43106
diff changeset
   192
            with tracing.log('finalextsetup: %s', repr(c)):
42316
c07dcf7a0247 exthelper: add some semi-useful trace logs
Augie Fackler <augie@google.com>
parents: 41279
diff changeset
   193
                c(ui)
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   194
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   195
    def finalreposetup(self, ui, repo):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   196
        """Method to be used as the extension reposetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   197
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   198
        The following operations belong here:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   199
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   200
        - All hooks but pre-* and post-*
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   201
        - Modify configuration variables
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   202
        - Changes to repo.__class__, repo.dirstate.__class__
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   203
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   204
        for c in self._repocallables:
43238
101ae8bbfa02 cleanup: hgdemandimport.tracing accepts strings, not bytes
Augie Fackler <augie@google.com>
parents: 43106
diff changeset
   205
            with tracing.log('finalreposetup: %s', repr(c)):
42316
c07dcf7a0247 exthelper: add some semi-useful trace logs
Augie Fackler <augie@google.com>
parents: 41279
diff changeset
   206
                c(ui, repo)
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   207
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   208
    def uisetup(self, call):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   209
        """Decorated function will be executed during uisetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   210
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   211
        example::
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   212
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   213
            # Required, otherwise your uisetup function(s) will not execute.
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   214
            uisetup = eh.finaluisetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   215
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   216
            @eh.uisetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   217
            def setupbabar(ui):
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
   218
                print('this is uisetup!')
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   219
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   220
        self._uicallables.append(call)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   221
        return call
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   222
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   223
    def uipopulate(self, call):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   224
        """Decorated function will be executed during uipopulate
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   225
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   226
        example::
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   227
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   228
            # Required, otherwise your uipopulate function(s) will not execute.
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   229
            uipopulate = eh.finaluipopulate
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   230
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   231
            @eh.uipopulate
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   232
            def setupfoo(ui):
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
   233
                print('this is uipopulate!')
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   234
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   235
        self._uipopulatecallables.append(call)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   236
        return call
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   237
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   238
    def extsetup(self, call):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   239
        """Decorated function will be executed during extsetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   240
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   241
        example::
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   242
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   243
            # Required, otherwise your extsetup function(s) will not execute.
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   244
            extsetup = eh.finalextsetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   245
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   246
            @eh.extsetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   247
            def setupcelestine(ui):
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
   248
                print('this is extsetup!')
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   249
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   250
        self._extcallables.append(call)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   251
        return call
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   252
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   253
    def reposetup(self, call):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   254
        """Decorated function will be executed during reposetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   255
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   256
        example::
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   257
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   258
            # Required, otherwise your reposetup function(s) will not execute.
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   259
            reposetup = eh.finalreposetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   260
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   261
            @eh.reposetup
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   262
            def setupzephir(ui, repo):
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
   263
                print('this is reposetup!')
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   264
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   265
        self._repocallables.append(call)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   266
        return call
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   267
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   268
    def wrapcommand(self, command, extension=None, opts=None):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   269
        """Decorated function is a command wrapper
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   270
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   271
        The name of the command must be given as the decorator argument.
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   272
        The wrapping is installed during `uisetup`.
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   273
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   274
        If the second option `extension` argument is provided, the wrapping
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   275
        will be applied in the extension commandtable. This argument must be a
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   276
        string that will be searched using `extension.find` if not found and
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   277
        Abort error is raised. If the wrapping applies to an extension, it is
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   278
        installed during `extsetup`.
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   279
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   280
        example::
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   281
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   282
            # Required if `extension` is not provided
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   283
            uisetup = eh.finaluisetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   284
            # Required if `extension` is provided
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   285
            extsetup = eh.finalextsetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   286
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
   287
            @eh.wrapcommand(b'summary')
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   288
            def wrapsummary(orig, ui, repo, *args, **kwargs):
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
   289
                ui.note(b'Barry!')
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   290
                return orig(ui, repo, *args, **kwargs)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   291
41060
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   292
        The `opts` argument allows specifying a list of tuples for additional
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   293
        arguments for the command.  See ``mercurial.fancyopts.fancyopts()`` for
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   294
        the format of the tuple.
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   295
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   296
        """
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   297
        if opts is None:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   298
            opts = []
41060
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   299
        else:
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   300
            for opt in opts:
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   301
                if not isinstance(opt, tuple):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   302
                    raise error.ProgrammingError(b'opts must be list of tuples')
41060
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   303
                if len(opt) not in (4, 5):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   304
                    msg = b'each opt tuple must contain 4 or 5 values'
41060
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   305
                    raise error.ProgrammingError(msg)
7250cbaabde0 exthelper: support the option argument when registering a command
Matt Harbison <matt_harbison@yahoo.com>
parents: 41057
diff changeset
   306
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   307
        def dec(wrapper):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   308
            if extension is None:
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   309
                self._commandwrappers.append((command, wrapper, opts))
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   310
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42316
diff changeset
   311
                self._extcommandwrappers.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42316
diff changeset
   312
                    (extension, command, wrapper, opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42316
diff changeset
   313
                )
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   314
            return wrapper
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42316
diff changeset
   315
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   316
        return dec
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   317
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   318
    def wrapfunction(self, container, funcname):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   319
        """Decorated function is a function wrapper
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   320
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   321
        This function takes two arguments, the container and the name of the
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   322
        function to wrap. The wrapping is performed during `uisetup`.
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   323
        (there is no extension support)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   324
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   325
        example::
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   326
46871
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   327
            # Required, otherwise the function will not be wrapped
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   328
            uisetup = eh.finaluisetup
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   329
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   330
            @eh.wrapfunction(discovery, b'checkheads')
887f89b100ac exthelper: improve docs to indicate what module vars are needed
Kyle Lippincott <spectral@google.com>
parents: 45932
diff changeset
   331
            def wrapcheckheads(orig, *args, **kwargs):
45932
bd22900e26ac exthelper: update the examples to be python3 complaint
Matt Harbison <matt_harbison@yahoo.com>
parents: 43238
diff changeset
   332
                ui.note(b'His head smashed in and his heart cut out')
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   333
                return orig(*args, **kwargs)
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   334
        """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42316
diff changeset
   335
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   336
        def dec(wrapper):
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   337
            self._functionwrappers.append((container, funcname, wrapper))
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   338
            return wrapper
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42316
diff changeset
   339
41044
fe606f2dcae9 extensions: import the exthelper class from evolve 980565468003 (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
diff changeset
   340
        return dec