Mercurial > hg
changeset 11214:b05ec0cc063e
keyword: offer svn-like default keywordmaps
svn-like default keywords can be set in a new configuration section
called [keywordset] -- thanks to timeless for the name.
Move setup of default keywordmaps into dedicated function used by
kwtemplater.__init__ and demo.
HeadURL/URL is not supported (by default).
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Wed, 19 May 2010 00:45:50 +0200 |
parents | 3d61813a300e |
children | ebc90fd4ebc0 |
files | hgext/keyword.py |
diffstat | 1 files changed, 29 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/keyword.py Tue May 18 22:16:38 2010 +0200 +++ b/hgext/keyword.py Wed May 19 00:45:50 2010 +0200 @@ -35,8 +35,8 @@ change history. The mechanism can be regarded as a convenience for the current user or for archive distribution. -Configuration is done in the [keyword] and [keywordmaps] sections of -hgrc files. +Configuration is done in the [keyword], [keywordset] and [keywordmaps] +sections of hgrc files. Example:: @@ -45,6 +45,10 @@ **.py = x* = ignore + [keywordset] + # 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. @@ -108,14 +112,13 @@ 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 keywordset configuration.''' templates = { 'Revision': '{node|short}', 'Author': '{author|user}', + } + kwsets = ({ 'Date': '{date|utcdate}', 'RCSfile': '{file|basename},v', 'RCSFile': '{file|basename},v', # kept for backwards compatibility @@ -123,7 +126,21 @@ 'Source': '{root}/{file},v', 'Id': '{file|basename},v {node|short} {date|utcdate} {author|user}', 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', - } + }, { + 'Date': '{date|svnisodate}', + 'Id': '{file|basename},v {node|short} {date|svnutcdate} {author|user}', + 'LastChangedRevision': '{node|short}', + 'LastChangedBy': '{author|user}', + 'LastChangedDate': '{date|svnisodate}', + }) + templates.update(kwsets[ui.configbool('keywordset', 'svn')]) + 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 @@ -137,6 +154,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) @@ -322,14 +341,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)