[PATCH 3 of 5] keyword: use templatefilter to mark a function as template filter

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Mar 29 13:15:41 EDT 2016


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1459271444 -32400
#      Wed Mar 30 02:10:44 2016 +0900
# Node ID 6a44183e3ca6ce60339f38e491cb0d2d6c30b460
# Parent  fe4d5a78a34c811c919520adf06aff31719b21f7
keyword: use templatefilter to mark a function as template filter

This patch also adds test for filter 'svnisodate' and 'svnutcdate' for
safety, because there is no test using them, yet.

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -104,6 +104,7 @@ from mercurial import (
     match,
     patch,
     pathutil,
+    registrar,
     scmutil,
     templatefilters,
     util,
@@ -137,28 +138,29 @@ colortable = {
     'kwfiles.ignoredunknown': 'none'
 }
 
+templatefilter = registrar.templatefilter()
+
 # date like in cvs' $Date
+ at templatefilter('utcdate')
 def utcdate(text):
-    ''':utcdate: Date. Returns a UTC-date in this format: "2009/08/18 11:00:13".
+    '''Date. Returns a UTC-date in this format: "2009/08/18 11:00:13".
     '''
     return util.datestr((util.parsedate(text)[0], 0), '%Y/%m/%d %H:%M:%S')
 # date like in svn's $Date
+ at templatefilter('svnisodate')
 def svnisodate(text):
-    ''':svnisodate: Date. Returns a date in this format: "2009-08-18 13:00:13
+    '''Date. Returns a date in this format: "2009-08-18 13:00:13
     +0200 (Tue, 18 Aug 2009)".
     '''
     return util.datestr(text, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
 # date like in svn's $Id
+ at templatefilter('svnutcdate')
 def svnutcdate(text):
-    ''':svnutcdate: Date. Returns a UTC-date in this format: "2009-08-18
+    '''Date. Returns a UTC-date in this format: "2009-08-18
     11:00:13Z".
     '''
     return util.datestr((util.parsedate(text)[0], 0), '%Y-%m-%d %H:%M:%SZ')
 
-templatefilters.filters.update({'utcdate': utcdate,
-                                'svnisodate': svnisodate,
-                                'svnutcdate': svnutcdate})
-
 # make keyword tools accessible
 kwtools = {'templater': None, 'hgcmd': ''}
 
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -51,6 +51,31 @@ as it would succeed without uisetup othe
   Branch = {branches}
   $Branch: demobranch $
 
+(test template filter svnisodate and svnutcdate)
+
+  $ hg --quiet kwdemo --config keywordset.svn=True
+  [extensions]
+  keyword =
+  [keyword]
+  demo.txt = 
+  [keywordset]
+  svn = True
+  [keywordmaps]
+  Author = {author|user}
+  Date = {date|svnisodate}
+  Id = {file|basename},v {node|short} {date|svnutcdate} {author|user}
+  LastChangedBy = {author|user}
+  LastChangedDate = {date|svnisodate}
+  LastChangedRevision = {node|short}
+  Revision = {node|short}
+  $Author: test $
+  $Date: ????-??-?? ??:??:?? ????? (???, ?? ??? ????) $ (glob)
+  $Id: demo.txt,v ???????????? ????-??-?? ??:??:??Z test $ (glob)
+  $LastChangedBy: test $
+  $LastChangedDate: ????-??-?? ??:??:?? ????? (???, ?? ??? ????) $ (glob)
+  $LastChangedRevision: ???????????? $ (glob)
+  $Revision: ???????????? $ (glob)
+
   $ cat <<EOF >> $HGRCPATH
   > [keyword]
   > ** =


More information about the Mercurial-devel mailing list