[PATCH 1 of 6 V2] extensions: import the exthelper class from evolve 980565468003 (API)

Yuya Nishihara yuya at tcha.org
Sun Dec 23 08:27:42 EST 2018


On Sun, 23 Dec 2018 01:15:46 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison at yahoo.com>
> # Date 1545530784 18000
> #      Sat Dec 22 21:06:24 2018 -0500
> # Node ID ffab2010329f111c2237ebbb64be650a1b0301d8
> # Parent  e9c606fef203621755d75b0434574a8a60ffd0ff
> extensions: import the exthelper class from evolve 980565468003 (API)

Queued with several pyflakes fixes, thanks.

> +    def wrapcommand(self, command, extension=None, opts=None):
> +        """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::
> +
> +            @eh.wrapcommand('summary')
> +            def wrapsummary(orig, ui, repo, *args, **kwargs):
> +                ui.note('Barry!')
> +                return orig(ui, repo, *args, **kwargs)
> +
> +        The `opts` argument allows specifying additional arguments for the
> +        command.
> +
> +        """
> +        def dec(wrapper):
> +            if opts is None:
> +                opts = []

It shadows the outer 'opts' variable. Moved out of the dec function.

> +    def addattr(self, container, funcname):
> +        """Decorated function is to be added to the container
> +
> +        This function takes two arguments, the container and the name of the
> +        function to wrap. The wrapping is performed during `uisetup`.
> +
> +        example::
> +
> +            @eh.function(context.changectx, 'babar')
> +            def babar(ctx):
> +                return 'babar' in ctx.description

This example doesn't look nice since we discourage rewriting classes.

https://www.mercurial-scm.org/wiki/WritingExtensions#Wrapping_methods_on_the_ui_and_repo_classes


More information about the Mercurial-devel mailing list