Patchwork templatekw: automatically maintain documentation

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 24, 2015, 6:18 p.m.
Message ID <6e37b8ec2b01d944ea1c.1443118738@waste.org>
Download mbox | patch
Permalink /patch/10612/
State Changes Requested
Headers show

Comments

timeless@mozdev.org - Sept. 24, 2015, 6:18 p.m.
# HG changeset patch
# User timeless@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`
Yuya Nishihara - Sept. 25, 2015, 3:04 p.m.
On Thu, 24 Sep 2015 13:18:58 -0500, timeless@mozdev.org wrote:
> # HG changeset patch
> # User timeless@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.

Patch

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']
+})
 
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = dockeywords.values()
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -278,6 +278,8 @@ 
        transplant    command to transplant changesets from another branch
        win32mbcs     allow the use of MBCS paths with problematic encodings
        zeroconf      discover and advertise repositories on the local network
+  $ hg help --config extensions.transplant= templating|grep transplant > /dev/null
+
 Test short command list with verbose option
 
   $ hg -v help shortlist