hgkw/keyword.py
changeset 205 f2d2e36053f9
parent 204 2d089b691b31
child 206 8d16b70359da
--- a/hgkw/keyword.py	Fri Jul 20 09:44:38 2007 +0200
+++ b/hgkw/keyword.py	Fri Jul 20 14:07:17 2007 +0200
@@ -299,15 +299,13 @@
     msg = 'hg keyword config and expansion example'
     kwstatus = 'current'
     fn = 'demo.txt'
-    tmpdir = tempfile.mkdtemp('', 'kwdemo.')
-    ui.note(_('creating temporary repo at %s\n') % tmpdir)
-    _repo = localrepo.localrepository(ui, path=tmpdir, create=True)
-    # for backwards compatibility
-    ui = _repo.ui
     ui.setconfig('keyword', fn, '')
     if opts['default']:
         kwstatus = 'default'
         kwmaps = kwtemplater.deftemplates
+        if ui.configitems('keywordmaps'):
+            for k, v in kwmaps.items():
+                ui.setconfig('keywordmaps', k, v)
     else:
         if args or opts['rcfile']:
             kwstatus = 'custom'
@@ -318,25 +316,26 @@
             ui.readconfig(opts['rcfile'])
         kwmaps = (dict(ui.configitems('keywordmaps')) or
                   kwtemplater.deftemplates)
-    if ui.configitems('keywordmaps'):
-        for k, v in kwmaps.items():
-            ui.setconfig('keywordmaps', k, v)
-    reposetup(ui, _repo)
+    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)
     for k, v in kwmaps.items():
         ui.write('%s = %s\n' % (k, v))
-    path = _repo.wjoin(fn)
+    path = repo.wjoin(fn)
     keywords = '$' + '$\n$'.join(kwmaps.keys()) + '$\n'
-    _repo.wopener(fn, 'w').write(keywords)
-    _repo.add([fn])
+    repo.wopener(fn, 'w').write(keywords)
+    repo.add([fn])
     ui.note(_('\n%s keywords written to %s:\n') % (kwstatus, path))
     ui.note(keywords)
-    ui.note(_("\nhg --repository '%s' commit\n") % tmpdir)
-    _repo.commit(text=msg)
+    ui.note('\nhg -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))
-    ui.write(_repo.wread(fn))
+    ui.write(repo.wread(fn))
     ui.debug(_('\nremoving temporary repo %s\n') % tmpdir)
     shutil.rmtree(tmpdir)