[PATCH 4 of 5] revset: replace revset.extpredicate by registrar.revsetpredicate

Yuya Nishihara yuya at tcha.org
Thu Jan 7 09:19:25 CST 2016


On Tue, 05 Jan 2016 20:48:37 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1451994204 -32400
> #      Tue Jan 05 20:43:24 2016 +0900
> # Node ID 604903e68756b80dd147f37cc642c019b8d5e50b
> # Parent  c6554052f10db3a9312b17c658bf8c579198a5d2
> revset: replace revset.extpredicate by registrar.revsetpredicate

> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -33,6 +33,7 @@ from . import (
>      fancyopts,
>      hg,
>      hook,
> +    revset,
>      ui as uimod,
>      util,
>  )
> @@ -765,6 +766,7 @@ def _loadcmdtable(ui, name, cmdtable):
>  #   obj) arguments
>  extraloaders = [
>      ('cmdtable', None, None), # this is just a place holder for 'cmdtable'
> +    ('revsetpredicate', revset, 'loadpredicate'),
>  ]
>  
>  def _dispatch(req):
> diff --git a/mercurial/registrar.py b/mercurial/registrar.py
> --- a/mercurial/registrar.py
> +++ b/mercurial/registrar.py
> @@ -229,6 +229,12 @@ class revsetpredicate(funcregistrarbase)
>  
>      'revsetpredicate' instance in example above can be used to
>      decorate multiple functions.
> +
> +    Decorated functions are registered automatically at loading
> +    extension, if an instance named as 'revsetpredicate' is used for
> +    decorating in extension.
> +
> +    Otherwise, explicit 'revset.loadpredicate()' is needed.
>      """

I think these changes will better fit to the patch 3. The patch 3 implements
core function, and the patch 4 uses it.

>    $ cat <<EOF > $TESTTMP/custompredicate.py
> -  > from mercurial import revset
> +  > from mercurial import registrar, revset
>    > 
> -  > revsetpredicate = revset.extpredicate()
> +  > revsetpredicate = registrar.revsetpredicate()
>    > 
>    > @revsetpredicate('custom1()')
>    > def custom1(repo, subset, x):
>    >     return revset.baseset([1])
> -  > @revsetpredicate('custom2()')
> -  > def custom2(repo, subset, x):
> -  >     return revset.baseset([2])
>    > 
> -  > def uisetup(ui):
> -  >     if ui.configbool('custompredicate', 'enabled'):
> -  >         revsetpredicate.setup()
> +  > syntax error for intentional failure of loading this module

Uh, the code won't be run at all on parsing failure. You can use
"raise Exception" instead.


More information about the Mercurial-devel mailing list