[PATCH 1 of 2] keyword: add 2 svn-like date filters

Christian Ebert blacktrash at gmx.net
Tue May 18 17:46:00 CDT 2010


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1274213798 -7200
# Node ID f0754232e28dcac0b3beb21e27039d0d6852f21e
# Parent  687c7d395f20867e1beac54c16269806a7a270e4
keyword: add 2 svn-like date filters

svnisodate yields the format the date in svn's Id keyword expands to.
svnutcdate yields the format svn's Date/LastChangedDate expands to.

http://svnbook.red-bean.com/en/1.5/svn.advanced.props.special.keywords.html

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -52,8 +52,11 @@
 control run :hg:`kwdemo`. See :hg:`help templates` for a list of
 available templates and filters.
 
-An additional date template filter {date|utcdate} is provided. It
-returns a date like "2006/09/18 15:13:13".
+Three additional date template filters are provided::
+
+    utcdate      "2006/09/18 15:13:13"
+    svnutcdate   "2006-09-18 15:13:13Z"
+    svnisodate   "2006-09-18 08:13:13 -700 (Mon, 18 Sep 2006)"
 
 The default template mappings (view with :hg:`kwdemo -d`) can be
 replaced with customized keywords and templates. Again, run
@@ -94,8 +97,12 @@
 # names of extensions using dorecord
 recordextensions = 'record'
 
-# provide cvs-like UTC date filter
+# date like in cvs' $Date
 utcdate = lambda x: util.datestr((x[0], 0), '%Y/%m/%d %H:%M:%S')
+# date like in svn's $Date
+svnisodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2 (%a, %d %b %Y)')
+# date like in svn's $Id
+svnutcdate = lambda x: util.datestr((x[0], 0), '%Y-%m-%d %H:%M:%SZ')
 
 # make keyword tools accessible
 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
@@ -135,6 +142,8 @@
         self.re_kw = re.compile(kwpat)
 
         templatefilters.filters['utcdate'] = utcdate
+        templatefilters.filters['svnisodate'] = svnisodate
+        templatefilters.filters['svnutcdate'] = svnutcdate
 
     def substitute(self, data, path, ctx, subfunc):
         '''Replaces keywords in data with expanded template.'''


More information about the Mercurial-devel mailing list