Patchwork [3,of,3] hgext: use templatekeyword to mark a function as template keyword

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 12, 2016, 8:20 p.m.
Message ID <c662c6d9c9ef18e71de8.1457814047@feefifofum>
Download mbox | patch
Permalink /patch/13832/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Katsunori FUJIWARA - March 12, 2016, 8:20 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1457813826 -32400
#      Sun Mar 13 05:17:06 2016 +0900
# Node ID c662c6d9c9ef18e71de8fe2421f4c8327a5d2bbe
# Parent  c47aef028594226f7070ebdd65413be5d4e135e6
hgext: use templatekeyword to mark a function as template keyword

This patch replaces registration of template keyword function in
bundled extensions by registrar.templatekeyword decorator all at once.

Patch

diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py
--- a/hgext/convert/__init__.py
+++ b/hgext/convert/__init__.py
@@ -11,7 +11,7 @@  from __future__ import absolute_import
 
 from mercurial import (
     cmdutil,
-    templatekw,
+    registrar,
 )
 from mercurial.i18n import _
 
@@ -437,22 +437,22 @@  def kwconverted(ctx, name):
             return subversion.revsplit(rev)[0]
     return rev
 
+templatekeyword = registrar.templatekeyword()
+
+@templatekeyword('svnrev')
 def kwsvnrev(repo, ctx, **args):
-    """:svnrev: String. Converted subversion revision number."""
+    """String. Converted subversion revision number."""
     return kwconverted(ctx, 'svnrev')
 
+@templatekeyword('svnpath')
 def kwsvnpath(repo, ctx, **args):
-    """:svnpath: String. Converted subversion revision project path."""
+    """String. Converted subversion revision project path."""
     return kwconverted(ctx, 'svnpath')
 
+@templatekeyword('svnuuid')
 def kwsvnuuid(repo, ctx, **args):
-    """:svnuuid: String. Converted subversion revision repository identifier."""
+    """String. Converted subversion revision repository identifier."""
     return kwconverted(ctx, 'svnuuid')
 
-def extsetup(ui):
-    templatekw.keywords['svnrev'] = kwsvnrev
-    templatekw.keywords['svnpath'] = kwsvnpath
-    templatekw.keywords['svnuuid'] = kwsvnuuid
-
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = [kwsvnrev, kwsvnpath, kwsvnuuid]
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -32,7 +32,6 @@  from mercurial import (
     revlog,
     revset,
     scmutil,
-    templatekw,
     util,
 )
 
@@ -726,14 +725,16 @@  def revsettransplanted(repo, subset, x):
     return revset.baseset([r for r in s if
         repo[r].extra().get('transplant_source')])
 
+templatekeyword = registrar.templatekeyword()
+
+@templatekeyword('transplanted')
 def kwtransplanted(repo, ctx, **args):
-    """:transplanted: String. The node identifier of the transplanted
+    """String. The node identifier of the transplanted
     changeset if any."""
     n = ctx.extra().get('transplant_source')
     return n and nodemod.hex(n) or ''
 
 def extsetup(ui):
-    templatekw.keywords['transplanted'] = kwtransplanted
     cmdutil.unfinishedstates.append(
         ['transplant/journal', True, False, _('transplant in progress'),
          _("use 'hg transplant --continue' or 'hg update' to abort")])