# HG changeset patch # User FUJIWARA Katsunori # Date 2016-03-29 17:10:44 # Node ID 9a6fa1d93bc89e77c8120f258468e282c45e4d9b # Parent 11f623b5668f99fa4079fe4e172e7a229df28358 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 +@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 +@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 +@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 <> $HGRCPATH > [keyword] > ** =