87 from mercurial.hgweb import webcommands |
87 from mercurial.hgweb import webcommands |
88 from mercurial.i18n import _ |
88 from mercurial.i18n import _ |
89 import os, re, shutil, tempfile |
89 import os, re, shutil, tempfile |
90 |
90 |
91 commands.optionalrepo += ' kwdemo' |
91 commands.optionalrepo += ' kwdemo' |
|
92 |
|
93 cmdtable = {} |
|
94 command = cmdutil.command(cmdtable) |
92 |
95 |
93 # hg commands that do not act on keywords |
96 # hg commands that do not act on keywords |
94 nokwcommands = ('add addremove annotate bundle export grep incoming init log' |
97 nokwcommands = ('add addremove annotate bundle export grep incoming init log' |
95 ' outgoing push tip verify convert email glog') |
98 ' outgoing push tip verify convert email glog') |
96 |
99 |
343 raise util.Abort(_('outstanding uncommitted changes')) |
346 raise util.Abort(_('outstanding uncommitted changes')) |
344 kwt.overwrite(wctx, clean, True, expand) |
347 kwt.overwrite(wctx, clean, True, expand) |
345 finally: |
348 finally: |
346 wlock.release() |
349 wlock.release() |
347 |
350 |
|
351 @command('kwdemo', |
|
352 [('d', 'default', None, _('show default keyword template maps')), |
|
353 ('f', 'rcfile', '', |
|
354 _('read maps from rcfile'), _('FILE'))], |
|
355 _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')) |
348 def demo(ui, repo, *args, **opts): |
356 def demo(ui, repo, *args, **opts): |
349 '''print [keywordmaps] configuration and an expansion example |
357 '''print [keywordmaps] configuration and an expansion example |
350 |
358 |
351 Show current, custom, or default keyword template maps and their |
359 Show current, custom, or default keyword template maps and their |
352 expansions. |
360 expansions. |
426 repo.commit(text=msg) |
434 repo.commit(text=msg) |
427 ui.status(_('\n\tkeywords expanded\n')) |
435 ui.status(_('\n\tkeywords expanded\n')) |
428 ui.write(repo.wread(fn)) |
436 ui.write(repo.wread(fn)) |
429 shutil.rmtree(tmpdir, ignore_errors=True) |
437 shutil.rmtree(tmpdir, ignore_errors=True) |
430 |
438 |
|
439 @command('kwexpand', commands.walkopts, _('hg kwexpand [OPTION]... [FILE]...')) |
431 def expand(ui, repo, *pats, **opts): |
440 def expand(ui, repo, *pats, **opts): |
432 '''expand keywords in the working directory |
441 '''expand keywords in the working directory |
433 |
442 |
434 Run after (re)enabling keyword expansion. |
443 Run after (re)enabling keyword expansion. |
435 |
444 |
436 kwexpand refuses to run if given files contain local changes. |
445 kwexpand refuses to run if given files contain local changes. |
437 ''' |
446 ''' |
438 # 3rd argument sets expansion to True |
447 # 3rd argument sets expansion to True |
439 _kwfwrite(ui, repo, True, *pats, **opts) |
448 _kwfwrite(ui, repo, True, *pats, **opts) |
440 |
449 |
|
450 @command('kwfiles', |
|
451 [('A', 'all', None, _('show keyword status flags of all files')), |
|
452 ('i', 'ignore', None, _('show files excluded from expansion')), |
|
453 ('u', 'unknown', None, _('only show unknown (not tracked) files')), |
|
454 ] + commands.walkopts, |
|
455 _('hg kwfiles [OPTION]... [FILE]...')) |
441 def files(ui, repo, *pats, **opts): |
456 def files(ui, repo, *pats, **opts): |
442 '''show files configured for keyword expansion |
457 '''show files configured for keyword expansion |
443 |
458 |
444 List which files in the working directory are matched by the |
459 List which files in the working directory are matched by the |
445 [keyword] configuration patterns. |
460 [keyword] configuration patterns. |
482 for char, filenames, kwstate in kwstates: |
497 for char, filenames, kwstate in kwstates: |
483 fmt = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n' |
498 fmt = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n' |
484 for f in filenames: |
499 for f in filenames: |
485 ui.write(fmt % repo.pathto(f, cwd), label='kwfiles.' + kwstate) |
500 ui.write(fmt % repo.pathto(f, cwd), label='kwfiles.' + kwstate) |
486 |
501 |
|
502 @command('kwshrink', commands.walkopts, _('hg kwshrink [OPTION]... [FILE]...')) |
487 def shrink(ui, repo, *pats, **opts): |
503 def shrink(ui, repo, *pats, **opts): |
488 '''revert expanded keywords in the working directory |
504 '''revert expanded keywords in the working directory |
489 |
505 |
490 Must be run before changing/disabling active keywords. |
506 Must be run before changing/disabling active keywords. |
491 |
507 |
671 extensions.wrapfunction(record, 'dorecord', kw_dorecord) |
687 extensions.wrapfunction(record, 'dorecord', kw_dorecord) |
672 except KeyError: |
688 except KeyError: |
673 pass |
689 pass |
674 |
690 |
675 repo.__class__ = kwrepo |
691 repo.__class__ = kwrepo |
676 |
|
677 cmdtable = { |
|
678 'kwdemo': |
|
679 (demo, |
|
680 [('d', 'default', None, _('show default keyword template maps')), |
|
681 ('f', 'rcfile', '', |
|
682 _('read maps from rcfile'), _('FILE'))], |
|
683 _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')), |
|
684 'kwexpand': (expand, commands.walkopts, |
|
685 _('hg kwexpand [OPTION]... [FILE]...')), |
|
686 'kwfiles': |
|
687 (files, |
|
688 [('A', 'all', None, _('show keyword status flags of all files')), |
|
689 ('i', 'ignore', None, _('show files excluded from expansion')), |
|
690 ('u', 'unknown', None, _('only show unknown (not tracked) files')), |
|
691 ] + commands.walkopts, |
|
692 _('hg kwfiles [OPTION]... [FILE]...')), |
|
693 'kwshrink': (shrink, commands.walkopts, |
|
694 _('hg kwshrink [OPTION]... [FILE]...')), |
|
695 } |
|