--- a/hgkw/keyword.py Sat Jan 20 22:18:57 2007 +0100
+++ b/hgkw/keyword.py Sun Jan 21 05:04:17 2007 +0100
@@ -1,65 +1,70 @@
-# keyword.py - keyword expansion for mercurial
+# keyword.py - keyword expansion for Mercurial
# $Id$
-
-'''keyword expansion hack against the grain of a DSCM
-
-This extension lets you expand RCS/CVS-like keywords in a Mercurial
-repository.
+#
+# Keyword expansion hack against the grain of a DSCM
+#
+# There are many good reasons why this is not needed in a distributed
+# SCM, still it may be useful in very small projects based on single
+# files (like LaTeX packages), that are mostly addressed to an audience
+# not running a version control system.
+#
+# For in-depth discussion refer to
+# <http://www.selenic.com/mercurial/wiki/index.cgi/KeywordPlan>.
+#
+# Keyword expansion is based on Mercurial's changeset template mappings.
+# The extension provides an additional UTC-date filter ({date|utcdate}).
+#
+# The user has the choice either to create his own keywords and their
+# expansions or to use the CVS-like default ones.
+#
+# Default $keywords$ and their $keyword: substition $ are:
+# Revision: changeset id
+# Author: username
+# Date: %Y/%m/%d %H:%M:%S [UTC]
+# RCSFile: basename,v
+# Source: /path/to/basename,v
+# Id: basename,v csetid %Y/%m/%d %H:%M:%S username
+# Header: /path/to/basename,v csetid %Y/%m/%d %H:%M:%S username
+#
+# Expansions spanning more than one line are truncated to their first line.
+# Incremental expansion (like CVS' $Log$) is not supported.
+#
+# Simple setup in hgrc:
+#
+# # enable extension
+# keyword = /full/path/to/keyword.py
+# # or, if script in hgext folder:
+# # hgext.keyword =
+#
+# # filename patterns for expansion are configured in this section
+# # files matching patterns with value 'ignore' are ignored
+# [keyword]
+# **.py =
+# x* = ignore
+# ...
+# # in case you prefer your own keyword maps over the cvs-like defaults:
+# [keywordmaps]
+# HGdate = {date|rfc822date}
+# lastlog = {desc} ## same as {desc|firstline} in this context
+# checked in by = {author}
+# ...
-There are many good reasons why this is not needed in a distributed
-SCM, still it may be useful in very small projects based on single
-files (like LaTeX packages), that are mostly addressed to an audience
-not running a version control system.
+'''keyword expansion in local repositories
-For in-depth discussion refer to
-<http://www.selenic.com/mercurial/wiki/index.cgi/KeywordPlan>.
+This extension expands RCS/CVS-like or self-customized keywords in
+the text files selected by your configuration.
Keywords are only expanded in local repositories and not logged by
Mercurial internally. The mechanism can be regarded as a convenience
for the current user and may be turned off anytime.
-
+
Substitution takes place on every commit and update of the working
repository.
-Keyword expansion is based on Mercurial's changeset template mappings.
-The extension provides an additional UTC-date filter.
-
-The user has the choice either to create his own keywords and their
-expansions or to use the CVS-like default ones.
-
-Default $keywords$ and their $keyword: substition $ are:
- Revision: changeset id
- Author: username
- Date: %Y/%m/%d %H:%M:%S [UTC]
- RCSFile: basename,v
- Source: /path/to/basename,v
- Id: basename,v csetid %Y/%m/%d %H:%M:%S username
- Header: /path/to/basename,v csetid %Y/%m/%d %H:%M:%S username
-
-Expansions spanning more than one line are truncated to their first line.
-Incremental expansion (like CVS' $Log$) is not supported.
-
-Simple setup in hgrc:
-
- # enable extension
- keyword = /full/path/to/keyword.py
- # or, if script in hgext folder:
- # hgext.keyword =
-
- # filename patterns for expansion are configured in this section
- # files matching patterns with value 'ignore' are ignored
- [keyword]
- **.py =
- x* = ignore
- ...
- # in case you prefer your own keyword maps over the cvs-like defaults:
- [keywordmaps]
- HGdate = {date|rfc822date}
- lastlog = {desc} ## same as {desc|firstline} in this context
- checked in by = {author}
- ...
+Configuration is done in the [keyword] and [keywordmaps] sections of
+hgrc files.
'''
-
+
from mercurial.i18n import gettext as _
# above line for backwards compatibility; can be changed to
# from mercurial.i18n import _
@@ -98,8 +103,8 @@
return os.path.splitext(os.path.basename(__file__))[0]
def kwfmatches(ui, repo, files):
- '''Selects candidates for keyword substitution
- configured in keyword section in hgrc.'''
+ '''Selects and weeds out candidates for keyword substitution
+ by patterns configured in [keyword] section in hgrc.'''
inc, exc = [], []
for pat, opt in ui.configitems('keyword'):
if opt != 'ignore':
@@ -111,7 +116,6 @@
kwfmatcher = util.matcher(repo.root, inc=inc, exc=['.hg*']+exc)[1]
return [f for f in files if kwfmatcher(f)]
-
class kwtemplater(object):
'''
Sets up keyword templates, corresponding keyword regex, and
@@ -128,7 +132,7 @@
def expand(self, mobj, path, node):
- '''Expands keyword with corresponding template.'''
+ '''Expands keyword using corresponding template.'''
kw = mobj.group(1)
template = templater.parsestring(self.templates[kw], quoted=False)
self.t.use_template(template)
@@ -140,12 +144,11 @@
def reposetup(ui, repo):
'''Sets up repo, and filelog especially, as kwrepo and kwfilelog
- for keyword substitution. This is done for local repos only.'''
+ for keyword substitution. This is done for local repos only.'''
if not repo.local():
return
-
class kwrepo(repo.__class__):
def file(self, f):
if f[0] == '/':