comparison hgext/keyword.py @ 10713:b9c3f8e88e4f

keyword: make kwdemo less verbose 1) Set the branchname always silently with dirstate.setbranch(). We create a branch so that testing the {branches} template does not come up empty. But kwdemo is hardly the place to inform the user by inference why {branches} is empty on the default branch. "demobranch" is ascii and cannot be changed, so using the internal command instead of commands.branch() is safe. 2) Do not show full path to temporary directory (distracting long lines on Mac OS X). 3) No special debug output. Output only related to keyword, no internals like unsetting of commit hooks etc.
author Christian Ebert <blacktrash@gmx.net>
date Tue, 16 Mar 2010 22:28:58 +0100
parents fbe138da6b38
children 9c0a1887bd4b
comparison
equal deleted inserted replaced
10712:fbe138da6b38 10713:b9c3f8e88e4f
285 ui.write('[%s]\n' % section) 285 ui.write('[%s]\n' % section)
286 for k, v in sorted(items): 286 for k, v in sorted(items):
287 ui.write('%s = %s\n' % (k, v)) 287 ui.write('%s = %s\n' % (k, v))
288 288
289 fn = 'demo.txt' 289 fn = 'demo.txt'
290 branchname = 'demobranch'
291 tmpdir = tempfile.mkdtemp('', 'kwdemo.') 290 tmpdir = tempfile.mkdtemp('', 'kwdemo.')
292 ui.note(_('creating temporary repository at %s\n') % tmpdir) 291 ui.note(_('creating temporary repository at %s\n') % tmpdir)
293 repo = localrepo.localrepository(ui, tmpdir, True) 292 repo = localrepo.localrepository(ui, tmpdir, True)
294 ui.setconfig('keyword', fn, '') 293 ui.setconfig('keyword', fn, '')
295 294
331 demoitems('keyword', ui.configitems('keyword')) 330 demoitems('keyword', ui.configitems('keyword'))
332 demoitems('keywordmaps', kwmaps.iteritems()) 331 demoitems('keywordmaps', kwmaps.iteritems())
333 keywords = '$' + '$\n$'.join(sorted(kwmaps.keys())) + '$\n' 332 keywords = '$' + '$\n$'.join(sorted(kwmaps.keys())) + '$\n'
334 repo.wopener(fn, 'w').write(keywords) 333 repo.wopener(fn, 'w').write(keywords)
335 repo.add([fn]) 334 repo.add([fn])
336 path = repo.wjoin(fn) 335 ui.note(_('\nkeywords written to %s:\n') % fn)
337 ui.note(_('\nkeywords written to %s:\n') % path)
338 ui.note(keywords) 336 ui.note(keywords)
339 ui.note('\nhg -R "%s" branch "%s"\n' % (tmpdir, branchname)) 337 repo.dirstate.setbranch('demobranch')
340 # silence branch command if not verbose
341 quiet = ui.quiet
342 ui.quiet = not ui.verbose
343 commands.branch(ui, repo, branchname)
344 ui.quiet = quiet
345 for name, cmd in ui.configitems('hooks'): 338 for name, cmd in ui.configitems('hooks'):
346 if name.split('.', 1)[0].find('commit') > -1: 339 if name.split('.', 1)[0].find('commit') > -1:
347 repo.ui.setconfig('hooks', name, '') 340 repo.ui.setconfig('hooks', name, '')
348 ui.note(_('unhooked all commit hooks\n'))
349 msg = _('hg keyword configuration and expansion example') 341 msg = _('hg keyword configuration and expansion example')
350 ui.note("hg -R '%s' ci -m '%s'\n" % (tmpdir, msg)) 342 ui.note("hg ci -m '%s'\n" % msg)
351 repo.commit(text=msg) 343 repo.commit(text=msg)
352 ui.status(_('\n\tkeywords expanded\n')) 344 ui.status(_('\n\tkeywords expanded\n'))
353 ui.write(repo.wread(fn)) 345 ui.write(repo.wread(fn))
354 ui.debug('\nremoving temporary repository %s\n' % tmpdir)
355 shutil.rmtree(tmpdir, ignore_errors=True) 346 shutil.rmtree(tmpdir, ignore_errors=True)
356 347
357 def expand(ui, repo, *pats, **opts): 348 def expand(ui, repo, *pats, **opts):
358 '''expand keywords in the working directory 349 '''expand keywords in the working directory
359 350