Show extension in kwdemo; flag helpers; rephrase doc
authorChristian Ebert <blacktrash@gmx.net>
Sat, 21 Jul 2007 21:44:33 +0200
changeset 208 5afdcec8a01f
parent 207 affc18a621f5
child 209 430837dbe7f4
Show extension in kwdemo; flag helpers; rephrase doc Update test and test output.
hgkw/keyword.py
tests/test-keyword
tests/test-keyword.out
--- a/hgkw/keyword.py	Sat Jul 21 09:41:13 2007 +0200
+++ b/hgkw/keyword.py	Sat Jul 21 21:44:33 2007 +0200
@@ -1,4 +1,4 @@
-# keyword.py - keyword expansion for Mercurial
+# keyword.py - $Keyword$ expansion for Mercurial
 #
 # Copyright 2007 Christian Ebert <blacktrash@gmx.net>
 #
@@ -18,59 +18,58 @@
 # <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}).
-#
-# Expansions spanning more than one line are truncated to their first line.
-# Incremental expansion (like CVS' $Log$) is not supported.
 #
 # Binary files are not touched.
 #
 # Setup in hgrc:
 #
-#     # enable extension
-#     keyword = /full/path/to/keyword.py
-#     # or, if script in hgext folder:
-#     # hgext.keyword =
+#   [extensions]
+#   # enable extension
+#   keyword = /full/path/to/hgkw/keyword.py
+#   # or, if script in canonical hgext folder:
+#   # hgext.keyword =
+#
+# Files to act upon/ignore are specified in the [keyword] section.
+# Customized keyword template mappings in the [keywordmaps] section.
+#
+# Run "hg help keyword" and "hg kwdemo" to get info on configuration.
 
 '''keyword expansion in local repositories
 
 This extension expands RCS/CVS-like or self-customized $Keywords$
-in the text files selected by your configuration.
+in tracked 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 or archive distribution.
+Keywords are only expanded in local repositories and not stored in
+the 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] and [keywordmaps] sections
+of hgrc files.
 
 Example:
-    [extensions]
-    hgext.keyword =
 
     [keyword]
     # expand keywords in every python file except those matching "x*"
     **.py =
-    x* = ignore
+    x*    = ignore
 
-Note: the more specific you are in your [keyword] filename patterns
+Note: the more specific you are in your filename patterns
       the less you lose speed in huge repos.
 
-For a [keywordmaps] template mapping and expansion demonstration
-run "hg kwdemo".
+For [keywordmaps] template mapping and expansion demonstration and
+control run "hg kwdemo".
 
 An additional date template filter {date|utcdate} is provided.
 
-You can replace the default template mappings with customized keywords
-and templates of your choice.
+The default template mappings (view with "hg kwdemo -d") can be replaced
+with customized keywords and templates.
 Again, run "hg kwdemo" to control the results of your config changes.
 
-When you change keyword configuration, especially the active keywords,
-and do not want to store expanded keywords in change history, run
-"hg kwshrink", and then change configuration.
+Before changing/disabling active keywords, run "hg kwshrink" to avoid
+the risk of inadvertedly storing expanded keywords in the change history.
 
-Expansions spanning more than one line and incremental exapansions
-(like CVS' $Log$) are not supported. A keyword template map
+Expansions spanning more than one line and incremental expansions,
+like CVS' $Log$, are not supported. A keyword template map
 "Log = {desc}" expands to the first line of the changeset description.
 
 Caveat: "hg import" fails if the patch context contains an active
@@ -139,13 +138,13 @@
                 self.t = cmdutil.changeset_templater(self.ui, self.repo,
                                                      False, None, '', False)
 
-    def ctxnode(self, node):
+    def _ctxnode(self, node):
         '''Obtains missing node from file context.'''
         if not self.node:
             c = context.filectx(self.repo, self.path, fileid=node)
             self.node = c.node()
 
-    def kwsub(self, mobj):
+    def _kwsub(self, mobj):
         '''Substitutes keyword using corresponding template.'''
         kw = mobj.group(1)
         self.t.use_template(self.templates[kw])
@@ -158,8 +157,8 @@
         '''Returns data with keywords expanded.'''
         if util.binary(data):
             return data
-        self.ctxnode(node)
-        return self.re_kw.sub(self.kwsub, data)
+        self._ctxnode(node)
+        return self.re_kw.sub(self._kwsub, data)
 
     def process(self, node, data):
         '''Returns a tuple: data, count.
@@ -168,8 +167,8 @@
         if util.binary(data):
             return data, None
         if self.t:
-            self.ctxnode(node)
-            return self.re_kw.subn(self.kwsub, data)
+            self._ctxnode(node)
+            return self.re_kw.subn(self._kwsub, data)
         return data, self.re_kw.search(data)
 
     def shrink(self, text):
@@ -280,10 +279,8 @@
 def shrink(ui, repo, *args):
     '''revert expanded keywords in working directory
 
-    run before:
-               disabling keyword expansion
-               changing keyword expansion configuration
-    or if you experience problems with "hg import"
+    run before changing/disabling active keywords
+    or if you experience problems with "hg import" or "hg merge"
     '''
     expand = False
     _overwrite(ui, repo, args, expand)
@@ -321,13 +318,19 @@
             ui.readconfig(opts['rcfile'])
         kwmaps = (dict(ui.configitems('keywordmaps')) or
                   kwtemplater.deftemplates)
+    for k, v in ui.configitems('extensions'):
+        if k.endswith('keyword'):
+            extension = '%s = %s' % (k, v)
+            break
     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
     ui.note(_('creating temporary repo at %s\n') % tmpdir)
     repo = localrepo.localrepository(ui, path=tmpdir, create=True)
     repo.ui = ui # backwards compatibility
     reposetup(ui, repo)
-    ui.status(_('config with %s keyword template maps:\n') % kwstatus)
-    ui.write('[keyword]\n%s =\n[keywordmaps]\n' % fn)
+    ui.status(_('config using %s keyword template maps:\n') % kwstatus)
+    ui.write('[extensions]\n%s\n'
+             '[keyword]\n%s =\n'
+             '[keywordmaps]\n' % (extension, fn))
     for k, v in kwmaps.items():
         ui.write('%s = %s\n' % (k, v))
     path = repo.wjoin(fn)
--- a/tests/test-keyword	Sat Jul 21 09:41:13 2007 +0200
+++ b/tests/test-keyword	Sat Jul 21 21:44:33 2007 +0200
@@ -10,7 +10,7 @@
 
 echo % help
 hg help keyword \
-| sed -e '/^list of commands:/d' -e '/hg -v help keyword/d' -e '/^$/d'
+| sed -e '/^list of commands/d' -e '/hg -v help keyword/d' -e '/^$/d'
 
 echo % hg kwdemo
 hg --quiet kwdemo --default \
--- a/tests/test-keyword.out	Sat Jul 21 09:41:13 2007 +0200
+++ b/tests/test-keyword.out	Sat Jul 21 21:44:33 2007 +0200
@@ -1,42 +1,40 @@
 % help
 keyword extension - keyword expansion in local repositories
 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 or archive distribution.
-Configuration is done in the [keyword] and [keywordmaps] sections of
-hgrc files.
+in tracked text files selected by your configuration.
+Keywords are only expanded in local repositories and not stored in
+the 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.
 Example:
-    [extensions]
-    hgext.keyword =
     [keyword]
     # expand keywords in every python file except those matching "x*"
     **.py =
-    x* = ignore
-Note: the more specific you are in your [keyword] filename patterns
+    x*    = ignore
+Note: the more specific you are in your filename patterns
       the less you lose speed in huge repos.
-For a [keywordmaps] template mapping and expansion demonstration
-run "hg kwdemo".
+For [keywordmaps] template mapping and expansion demonstration and
+control run "hg kwdemo".
 An additional date template filter {date|utcdate} is provided.
-You can replace the default template mappings with customized keywords
-and templates of your choice.
+The default template mappings (view with "hg kwdemo -d") can be replaced
+with customized keywords and templates.
 Again, run "hg kwdemo" to control the results of your config changes.
-When you change keyword configuration, especially the active keywords,
-and do not want to store expanded keywords in change history, run
-"hg kwshrink", and then change configuration.
-Expansions spanning more than one line and incremental exapansions
-(like CVS' $Log$) are not supported. A keyword template map
+Before changing/disabling active keywords, run "hg kwshrink" to avoid
+the risk of inadvertedly storing expanded keywords in the change history.
+Expansions spanning more than one line and incremental expansions,
+like CVS' $Log$, are not supported. A keyword template map
 "Log = {desc}" expands to the first line of the changeset description.
 Caveat: "hg import" fails if the patch context contains an active
         keyword. In that case run "hg kwshrink", reimport, and then
         "hg kwexpand".
         Or, better, use bundle/unbundle to share changes.
-list of commands (use "hg help -v keyword" to show aliases and global options):
  kwdemo     print [keywordmaps] configuration and an expansion example
  kwexpand   expand keywords in working directory
  kwshrink   revert expanded keywords in working directory
 % hg kwdemo
+[extensions]
+hgext.keyword = 
 [keyword]
 demo.txt =
 [keywordmaps]
@@ -100,6 +98,8 @@
 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
 % custom keyword expansion
 % try with kwdemo
+[extensions]
+hgext.keyword = 
 [keyword]
 demo.txt =
 [keywordmaps]