(stable) merge stable
authorChristian Ebert <blacktrash@gmx.net>
Wed, 05 Aug 2009 16:57:21 +0200
branchstable
changeset 637 103120cace93
parent 632 1357d4a4ad3e (current diff)
parent 636 d0c35f5fa25f (diff)
child 641 bf971e786e93
(stable) merge
--- a/hgkw/keyword.py	Mon Aug 03 11:53:13 2009 +0200
+++ b/hgkw/keyword.py	Wed Aug 05 16:57:21 2009 +0200
@@ -49,9 +49,11 @@
 lose speed in huge repositories.
 
 For [keywordmaps] template mapping and expansion demonstration and
-control run "hg kwdemo".
+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.
+An additional date template filter {date|utcdate} is provided. It
+returns a date like "2006/09/18 15:13:13".
 
 The default template mappings (view with "hg kwdemo -d") can be
 replaced with customized keywords and templates. Again, run "hg
@@ -80,7 +82,7 @@
 from mercurial.lock import release
 from mercurial.node import nullid
 from mercurial.i18n import _
-import re, shutil, tempfile, time
+import re, shutil, tempfile
 
 commands.optionalrepo += ' kwdemo'
 
@@ -93,9 +95,8 @@
 # not when reading filelog, and unexpand when reading from working dir
 restricted = 'merge record resolve qfold qimport qnew qpush qrefresh qrecord'
 
-def utcdate(date):
-    '''Returns hgdate in cvs-like UTC format.'''
-    return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
+# provide cvs-like UTC date filter
+utcdate = lambda x: util.datestr(x, '%Y/%m/%d %H:%M:%S')
 
 # make keyword tools accessible
 kwtools = {'templater': None, 'hgcmd': '', 'inc': [], 'exc': ['.hg*']}
@@ -276,10 +277,12 @@
     Show current, custom, or default keyword template maps and their
     expansions.
 
-    Extend current configuration by specifying maps as arguments and
-    optionally by reading from an additional hgrc file.
+    Extend the current configuration by specifying maps as arguments
+    and using -f/--rcfile to source an external hgrc file.
 
-    Override current keyword template maps with "default" option.
+    Use -d/--default to disable current configuration.
+
+    See "hg help templates" for information on templates and filters.
     '''
     def demoitems(section, items):
         ui.write('[%s]\n' % section)
@@ -287,40 +290,47 @@
             ui.write('%s = %s\n' % (k, v))
 
     msg = 'hg keyword config and expansion example'
-    kwstatus = 'current'
     fn = 'demo.txt'
     branchname = 'demobranch'
     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
     ui.note(_('creating temporary repository at %s\n') % tmpdir)
     repo = localrepo.localrepository(ui, tmpdir, True)
     ui.setconfig('keyword', fn, '')
+
+    uikwmaps = ui.configitems('keywordmaps')
     if args or opts.get('rcfile'):
-        kwstatus = 'custom'
-    if opts.get('rcfile'):
-        ui.readconfig(opts.get('rcfile'))
-    if opts.get('default'):
-        kwstatus = 'default'
+        ui.status(_('\n\tconfiguration using custom keyword template maps\n'))
+        if uikwmaps:
+            ui.status(_('\textending current template maps\n'))
+        if opts.get('default') or not uikwmaps:
+            ui.status(_('\toverriding default template maps\n'))
+        if opts.get('rcfile'):
+            ui.readconfig(opts.get('rcfile'))
+        if args:
+            # simulate hgrc parsing
+            rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args]
+            fp = repo.opener('hgrc', 'w')
+            fp.writelines(rcmaps)
+            fp.close()
+            ui.readconfig(repo.join('hgrc'))
+        kwmaps = dict(ui.configitems('keywordmaps'))
+    elif opts.get('default'):
+        ui.status(_('\n\tconfiguration using default keyword template maps\n'))
         kwmaps = kwtemplater.templates
-        if ui.configitems('keywordmaps'):
-            # override maps from optional rcfile
+        if uikwmaps:
+            ui.status(_('\tdisabling current template maps\n'))
             for k, v in kwmaps.iteritems():
                 ui.setconfig('keywordmaps', k, v)
-    elif args:
-        # simulate hgrc parsing
-        rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args]
-        fp = repo.opener('hgrc', 'w')
-        fp.writelines(rcmaps)
-        fp.close()
-        ui.readconfig(repo.join('hgrc'))
-    if not opts.get('default'):
-        kwmaps = dict(ui.configitems('keywordmaps')) or kwtemplater.templates
+    else:
+        ui.status(_('\n\tconfiguration using current keyword template maps\n'))
+        kwmaps = dict(uikwmaps) or kwtemplater.templates
+
     uisetup(ui)
     reposetup(ui, repo)
     for k, v in ui.configitems('extensions'):
         if k.endswith('keyword'):
             extension = '%s = %s' % (k, v)
             break
-    ui.status(_('\n\tconfig using %s keyword template maps\n') % kwstatus)
     ui.write('[extensions]\n%s\n' % extension)
     demoitems('keyword', ui.configitems('keyword'))
     demoitems('keywordmaps', kwmaps.iteritems())
@@ -328,7 +338,7 @@
     repo.wopener(fn, 'w').write(keywords)
     repo.add([fn])
     path = repo.wjoin(fn)
-    ui.note(_('\n%s keywords written to %s:\n') % (kwstatus, path))
+    ui.note(_('\nkeywords written to %s:\n') % path)
     ui.note(keywords)
     ui.note('\nhg -R "%s" branch "%s"\n' % (tmpdir, branchname))
     # silence branch command if not verbose
@@ -342,8 +352,7 @@
     ui.note(_('unhooked all commit hooks\n'))
     ui.note('hg -R "%s" ci -m "%s"\n' % (tmpdir, msg))
     repo.commit(text=msg)
-    fmt = ui.verbose and ' in %s' % path or ''
-    ui.status(_('\n\t%s keywords expanded%s\n') % (kwstatus, fmt))
+    ui.status(_('\n\tkeywords expanded\n'))
     ui.write(repo.wread(fn))
     ui.debug(_('\nremoving temporary repository %s\n') % tmpdir)
     shutil.rmtree(tmpdir, ignore_errors=True)
--- a/tests/test-keyword	Mon Aug 03 11:53:13 2009 +0200
+++ b/tests/test-keyword	Wed Aug 05 16:57:21 2009 +0200
@@ -13,9 +13,6 @@
 commit.test=cp a hooktest
 EOF
 
-echo % help
-hg help keyword
-
 echo % hg kwdemo
 hg --quiet kwdemo --default \
 | sed -e 's![^ ][^ ]*demo.txt,v!/TMP/demo.txt,v!' \
--- a/tests/test-keyword.out	Mon Aug 03 11:53:13 2009 +0200
+++ b/tests/test-keyword.out	Wed Aug 05 16:57:21 2009 +0200
@@ -1,64 +1,3 @@
-% help
-keyword extension - expand keywords in tracked files
-
-This extension expands RCS/CVS-like or self-customized $Keywords$ 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:
-
-  [keyword]
-  # expand keywords in every python file except those matching "x*"
-  **.py =
-  x*    = ignore
-
-NOTE: the more specific you are in your filename patterns the less you lose
-speed in huge repositories.
-
-For [keywordmaps] template mapping and expansion demonstration and control run
-"hg kwdemo".
-
-An additional date template filter {date|utcdate} is provided.
-
-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.
-
-Before changing/disabling active keywords, run "hg kwshrink" to avoid the risk
-of inadvertently storing expanded keywords in the change history.
-
-To force expansion after enabling it, or a configuration change, run "hg
-kwexpand".
-
-Also, when committing with the record extension or using mq's qrecord, be
-aware that keywords cannot be updated. Again, run "hg kwexpand" on the files
-in question to update keyword expansions after all changes have been checked
-in.
-
-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.
-
-list of commands:
-
- kwdemo     print [keywordmaps] configuration and an expansion example
- kwexpand   expand keywords in the working directory
- kwfiles    show files configured for keyword expansion
- kwshrink   revert expanded keywords in the working directory
-
-enabled extensions:
-
- keyword   expand keywords in tracked files
- mq        manage a stack of patches
- notify    hooks for sending email notifications at commit/push time
-
-use "hg -v help keyword" to show aliases and global options
 % hg kwdemo
 [extensions]
 hgext.keyword =