kwdemo fixes and tweaks
Write map arguments in repo hgrc, to simulate parsing
and parsing errors.
Add branch display; change demo verbosity for branch command.
Display current [keyword] files additionally to demo.txt, as they
might influence the result.
Formatting: status indented by tab.
--- 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)
--- a/tests/test-keyword Sun Jul 22 14:56:13 2007 +0200
+++ b/tests/test-keyword Mon Jul 23 10:36:00 2007 +0200
@@ -20,6 +20,8 @@
-e '/[$]Revision/ s/: [a-z0-9][a-z0-9]* /: xxxxxxxxxxxx /' \
-e 's! 20[0-9][0-9]/[01][0-9]/[0-3][0-9] [0-2][0-9]:[0-6][0-9]:[0-6][0-9]! 2000/00/00 00:00:00!'
+hg --quiet kwdemo "Branch = {branches}"
+
hg init Test
cd Test
--- a/tests/test-keyword.out Sun Jul 22 14:56:13 2007 +0200
+++ b/tests/test-keyword.out Mon Jul 23 10:36:00 2007 +0200
@@ -36,7 +36,9 @@
[extensions]
hgext.keyword =
[keyword]
-demo.txt =
+* =
+b = ignore
+demo.txt =
[keywordmaps]
RCSFile = {file|basename},v
Author = {author|user}
@@ -52,6 +54,15 @@
$Date: 2000/00/00 00:00:00 $
$Id: demo.txt,v xxxxxxxxxxxx 2000/00/00 00:00:00 test $
$Revision: xxxxxxxxxxxx $
+[extensions]
+hgext.keyword =
+[keyword]
+* =
+b = ignore
+demo.txt =
+[keywordmaps]
+Branch = {branches}
+$Branch: demobranch $
% kwshrink should abort in empty/invalid repo
abort: no revision checked out!
% cat
@@ -101,7 +112,9 @@
[extensions]
hgext.keyword =
[keyword]
-demo.txt =
+* =
+b = ignore
+demo.txt =
[keywordmaps]
Xinfo = {author}: {desc}
$Xinfo: test: hg keyword config and expansion example $