[PATCH] templatekw: automatically maintain documentation

Yuya Nishihara yuya at tcha.org
Fri Sep 25 10:04:03 CDT 2015


On Thu, 24 Sep 2015 13:18:58 -0500, timeless at mozdev.org wrote:
> # HG changeset patch
> # User timeless at mozdev.org
> # Date 1443117498 14400
> #      Thu Sep 24 13:58:18 2015 -0400
> # Node ID 6e37b8ec2b01d944ea1c116712d18f9471be085b
> # Parent  db4c192cb9b3744c42b85af45ea6c8015d271bcc
> templatekw: automatically maintain documentation
> 
> without this, extension keywords do not appear in `hg help templates`
> 
> diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
> --- a/mercurial/templatekw.py
> +++ b/mercurial/templatekw.py
> @@ -448,6 +448,30 @@
>      """:tags: List of strings. Any tags associated with the changeset."""
>      return shownames('tags', **args)
>  
> +def _showparents(**args):
> +    """:parents: List of strings. The parents of the changeset in "rev:node"
> +    format. If the changeset has only one "natural" parent (the predecessor
> +    revision) nothing is shown."""
> +    pass
> +
> +dockeywords = {
> +    'parents': _showparents,
> +}
> +
> +class keywordsdict(dict):
> +    def __init__(self, *args, **kwargs):
> +        dict.__init__(self, *args, **kwargs)
> +        self.update(*args, **kwargs)
> +
> +    def __setitem__(self, key, val):
> +        dict.__setitem__(self, key, val)
> +        self.update()
> +
> +    def update(self, *args, **kwargs):
> +        super(keywordsdict, self).update(*args, **kwargs)
> +        dockeywords.update(self)
> +        del dockeywords['branches']
> +
>  # keywords are callables like:
>  # fn(repo, ctx, templ, cache, revcache, **args)
>  # with:
> @@ -456,7 +480,7 @@
>  # templ - the templater instance
>  # cache - a cache dictionary for the whole templater run
>  # revcache - a cache dictionary for the current revision
> -keywords = {
> +keywords = keywordsdict({
>      'activebookmark': showactivebookmark,
>      'author': showauthor,
>      'bisect': showbisect,
> @@ -490,19 +514,7 @@
>      'rev': showrev,
>      'subrepos': showsubrepos,
>      'tags': showtags,
> -}
> -
> -def _showparents(**args):
> -    """:parents: List of strings. The parents of the changeset in "rev:node"
> -    format. If the changeset has only one "natural" parent (the predecessor
> -    revision) nothing is shown."""
> -    pass
> -
> -dockeywords = {
> -    'parents': _showparents,
> -}
> -dockeywords.update(keywords)
> -del dockeywords['branches']

Can you hold this patch for now?

I think it's possible to move showparents() to templatekw, and the docstring
of showbranches can be commented out. Then, we won't need the dockeywords hack.


More information about the Mercurial-devel mailing list