diff -r 1357d4a4ad3e -r 103120cace93 hgkw/keyword.py --- 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)