--- a/hgkw/keyword.py Sun Jul 22 14:56:13 2007 +0200
+++ b/hgkw/keyword.py Mon Jul 23 10:36:00 2007 +0200
@@ -306,52 +306,76 @@
'''print [keywordmaps] configuration and an expansion example
show current, custom, or default keyword template maps and their expansion
+
+ extend current configuration by specifying maps as arguments
+ and optionally by reading from an additional hgrc file
+
+ override current keyword template maps with "default" option
'''
+ def _demostatus(stat):
+ ui.status(_('\n\t%s\n') % stat)
+
+ def _showitems(section, items):
+ ui.write('[%s]\n' % section)
+ for k, v in items:
+ 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 repo at %s\n') % tmpdir)
+ repo = localrepo.localrepository(ui, path=tmpdir, create=True)
+ repo.ui = ui # backwards compatibility
ui.setconfig('keyword', fn, '')
+ if args or opts['rcfile']:
+ kwstatus = 'custom'
+ if opts['rcfile']:
+ ui.readconfig(opts['rcfile'])
if opts['default']:
kwstatus = 'default'
kwmaps = kwtemplater.deftemplates
if ui.configitems('keywordmaps'):
+ # override maps from optional rcfile
for k, v in kwmaps.items():
ui.setconfig('keywordmaps', k, v)
- else:
- if args or opts['rcfile']:
- kwstatus = 'custom'
- for tmap in args:
- k, v = tmap.split('=', 1)
- ui.setconfig('keywordmaps', k.strip(), v.strip())
- if opts['rcfile']:
- ui.readconfig(opts['rcfile'])
+ 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['default']:
kwmaps = (dict(ui.configitems('keywordmaps')) or
kwtemplater.deftemplates)
+ reposetup(ui, repo)
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 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)
+ _demostatus('config using %s keyword template maps' % kwstatus)
+ ui.write('[extensions]\n%s\n' % extension)
+ _showitems('keyword', ui.configitems('keyword'))
+ _showitems('keywordmaps', kwmaps.items())
keywords = '$' + '$\n$'.join(kwmaps.keys()) + '$\n'
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(keywords)
- ui.note('\nhg -R "%s" ci -m "%s"\n' % (tmpdir, msg))
+ ui.note('\nhg -R "%s" branch "%s"\n' % (tmpdir, branchname))
+ # silence branch command if not verbose
+ quiet = ui.quiet
+ verbose = ui.verbose
+ ui.quiet = not verbose
+ commands.branch(ui, repo, branchname)
+ ui.quiet = quiet
+ ui.note('hg -R "%s" ci -m "%s"\n' % (tmpdir, msg))
repo.commit(text=msg)
pathinfo = ('', ' in %s' % path)[ui.verbose]
- ui.status(_('\n%s keywords expanded%s:\n') % (kwstatus, pathinfo))
+ _demostatus('%s keywords expanded%s' % (kwstatus, pathinfo))
ui.write(repo.wread(fn))
ui.debug(_('\nremoving temporary repo %s\n') % tmpdir)
shutil.rmtree(tmpdir)