215 |
215 |
216 |
216 |
217 def demo(ui, repo, **opts): |
217 def demo(ui, repo, **opts): |
218 '''print [keywordmaps] configuration and an expansion example |
218 '''print [keywordmaps] configuration and an expansion example |
219 ''' |
219 ''' |
220 log = 'hg keyword config and expansion example' |
220 msg = 'hg keyword config and expansion example' |
221 fn = 'demo.txt' |
221 fn = 'demo.txt' |
222 tmpdir = tempfile.mkdtemp('', 'kwdemo.') |
222 tmpdir = tempfile.mkdtemp('', 'kwdemo.') |
223 if ui.verbose: |
223 ui.note(_('creating temporary repo at %s\n') % tmpdir) |
224 ui.status(_('creating temporary repo at %s\n') % tmpdir) |
|
225 _repo = localrepo.localrepository(ui, path=tmpdir, create=True) |
224 _repo = localrepo.localrepository(ui, path=tmpdir, create=True) |
226 _repo.ui.setconfig('keyword', fn, '') |
225 _repo.ui.setconfig('keyword', fn, '') |
227 if opts['default']: |
226 if opts['default']: |
228 kwstatus = 'default' |
227 kwstatus = 'default' |
229 kwmaps = deftemplates |
228 kwmaps = deftemplates |
232 kwmaps = dict(ui.configitems('keywordmaps')) or deftemplates |
231 kwmaps = dict(ui.configitems('keywordmaps')) or deftemplates |
233 if ui.configitems('keywordmaps'): |
232 if ui.configitems('keywordmaps'): |
234 for k, v in kwmaps.items(): |
233 for k, v in kwmaps.items(): |
235 _repo.ui.setconfig('keywordmaps', k, v) |
234 _repo.ui.setconfig('keywordmaps', k, v) |
236 reposetup(_repo.ui, _repo) |
235 reposetup(_repo.ui, _repo) |
237 ui.status(_('config with %s keyword maps:\n') % kwstatus) |
236 ui.status(_('config with %s keyword template maps:\n') % kwstatus) |
238 ui.write('[keyword]\n%s =\n[keywordmaps]\n' % fn) |
237 ui.write('[keyword]\n%s =\n[keywordmaps]\n' % fn) |
239 for k, v in kwmaps.items(): |
238 for k, v in kwmaps.items(): |
240 ui.write('%s = %s\n' % (k, v)) |
239 ui.write('%s = %s\n' % (k, v)) |
241 path = _repo.wjoin(fn) |
240 path = _repo.wjoin(fn) |
242 keywords = '$' + '$\n$'.join(kwmaps.keys()) + '$\n' |
241 keywords = '$' + '$\n$'.join(kwmaps.keys()) + '$\n' |
243 _repo.wfile(fn, 'w').write(keywords) |
242 _repo.wopener(fn, 'w').write(keywords) |
244 _repo.add([fn]) |
243 _repo.add([fn]) |
245 if ui.verbose: |
244 ui.note(_('\n%s keywords written to %s:\n') % (kwstatus, path)) |
246 ui.status(_('\n%s keywords written to %s:\n') % (kwstatus, path)) |
245 ui.note(keywords) |
247 ui.write(keywords) |
246 ui.note(_("\nhg --repository '%s' commit\n") % tmpdir) |
248 ui.status(_("\nhg --repository '%s' commit\n") % tmpdir) |
247 _repo.commit(text=msg) |
249 _repo.commit(text=log) |
248 pathinfo = ('', ' in %s' % path)[ui.verbose] |
250 if ui.verbose: |
249 ui.status(_('\n%s keywords expanded%s:\n') % (kwstatus, pathinfo)) |
251 ui.status(_('\n%s keywords expanded in %s:\n') % (kwstatus, path)) |
|
252 else: |
|
253 ui.status(_('\n%s keywords expanded:\n') % kwstatus) |
|
254 ui.write(_repo.wread(fn)) |
250 ui.write(_repo.wread(fn)) |
255 ui.debug(_('\nremoving temporary repo\n')) |
251 ui.debug(_('\nremoving temporary repo %s\n') % tmpdir) |
256 shutil.rmtree(tmpdir) |
252 shutil.rmtree(tmpdir) |
257 |
253 |
258 |
254 |
259 def reposetup(ui, repo): |
255 def reposetup(ui, repo): |
260 '''Sets up repo as kwrepo for keyword substitution. |
256 '''Sets up repo as kwrepo for keyword substitution. |