[PATCH 2 of 2] keyword: offer svn-like default keywordmaps

Christian Ebert blacktrash at gmx.net
Wed Feb 10 03:14:06 CST 2010


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1265793232 -3600
# Node ID 325009afe6ff59b076e53c85740edc6028a3291b
# Parent  10c4d26ba800a07a37171f76c74ba3ad0acaf67d
keyword: offer svn-like default keywordmaps

svn-like default keywords can be set in the a new config section
keywordstyle.

Move setup of default keywordmaps into dedicated function used by
kwtemplater.__init__ and demo.

HeadURL/URL is not supported (by default).

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -45,6 +45,10 @@
     **.py =
     x*    = ignore
 
+    [keywordstyle]
+    # prefer svn- over cvs-like default keywordmaps
+    svn = True
+
 NOTE: the more specific you are in your filename patterns the less you
 lose speed in huge repositories.
 
@@ -110,14 +114,14 @@
 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
 
 
-class kwtemplater(object):
-    '''
-    Sets up keyword templates, corresponding keyword regex, and
-    provides keyword substitution functions.
-    '''
+def _defaultkwmaps(ui):
+    '''Returns default keywordmaps according to keywordstyle configuration.'''
     templates = {
         'Revision': '{node|short}',
         'Author': '{author|user}',
+    }
+
+    cvs = {
         'Date': '{date|utcdate}',
         'RCSfile': '{file|basename},v',
         'RCSFile': '{file|basename},v', # kept for backwards compatibility
@@ -127,6 +131,23 @@
         'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}',
     }
 
+    svn = {
+        'Date': '{date|svnisodate}',
+        'Id': '{file|basename},v {node|short} {date|svnutcdate} {author|user}',
+        'LastChangedRevision': '{node|short}',
+        'LastChangedBy': '{author|user}',
+        'LastChangedDate': '{date|svnisodate}',
+    }
+
+    templates.update(ui.configbool('keywordstyle', 'svn') and svn or cvs)
+    return templates
+
+class kwtemplater(object):
+    '''
+    Sets up keyword templates, corresponding keyword regex, and
+    provides keyword substitution functions.
+    '''
+
     def __init__(self, ui, repo):
         self.ui = ui
         self.repo = repo
@@ -138,6 +159,8 @@
         if kwmaps: # override default templates
             self.templates = dict((k, templater.parsestring(v, False))
                                   for k, v in kwmaps)
+        else:
+            self.templates = _defaultkwmaps(self.ui)
         escaped = map(re.escape, self.templates.keys())
         kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
         self.re_kw = re.compile(kwpat)
@@ -330,14 +353,14 @@
         kwmaps = dict(ui.configitems('keywordmaps'))
     elif opts.get('default'):
         ui.status(_('\n\tconfiguration using default keyword template maps\n'))
-        kwmaps = kwtemplater.templates
+        kwmaps = _defaultkwmaps(ui)
         if uikwmaps:
             ui.status(_('\tdisabling current template maps\n'))
             for k, v in kwmaps.iteritems():
                 ui.setconfig('keywordmaps', k, v)
     else:
         ui.status(_('\n\tconfiguration using current keyword template maps\n'))
-        kwmaps = dict(uikwmaps) or kwtemplater.templates
+        kwmaps = dict(uikwmaps) or _defaultkwmaps(ui)
 
     uisetup(ui)
     reposetup(ui, repo)


More information about the Mercurial-devel mailing list