hgkw/keyword.py
branchstable
changeset 876 20db7f6aba9a
parent 875 e01f1b4a62e9
child 890 ddd525b7dd4a
equal deleted inserted replaced
872:67aaf09289bb 876:20db7f6aba9a
    68 
    68 
    69 The default template mappings (view with :hg:`kwdemo -d`) can be
    69 The default template mappings (view with :hg:`kwdemo -d`) can be
    70 replaced with customized keywords and templates. Again, run
    70 replaced with customized keywords and templates. Again, run
    71 :hg:`kwdemo` to control the results of your configuration changes.
    71 :hg:`kwdemo` to control the results of your configuration changes.
    72 
    72 
    73 Before changing/disabling active keywords, run :hg:`kwshrink` to avoid
    73 Before changing/disabling active keywords, you must run :hg:`kwshrink`
    74 the risk of inadvertently storing expanded keywords in the change
    74 to avoid storing expanded keywords in the change history.
    75 history.
       
    76 
    75 
    77 To force expansion after enabling it, or a configuration change, run
    76 To force expansion after enabling it, or a configuration change, run
    78 :hg:`kwexpand`.
    77 :hg:`kwexpand`.
    79 
    78 
    80 Expansions spanning more than one line and incremental expansions,
    79 Expansions spanning more than one line and incremental expansions,
   354     fn = 'demo.txt'
   353     fn = 'demo.txt'
   355     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   354     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
   356     ui.note(_('creating temporary repository at %s\n') % tmpdir)
   355     ui.note(_('creating temporary repository at %s\n') % tmpdir)
   357     repo = localrepo.localrepository(ui, tmpdir, True)
   356     repo = localrepo.localrepository(ui, tmpdir, True)
   358     ui.setconfig('keyword', fn, '')
   357     ui.setconfig('keyword', fn, '')
       
   358     svn = ui.configbool('keywordset', 'svn')
       
   359     # explicitly set keywordset for demo output
       
   360     ui.setconfig('keywordset', 'svn', svn)
   359 
   361 
   360     uikwmaps = ui.configitems('keywordmaps')
   362     uikwmaps = ui.configitems('keywordmaps')
   361     if args or opts.get('rcfile'):
   363     if args or opts.get('rcfile'):
   362         ui.status(_('\n\tconfiguration using custom keyword template maps\n'))
   364         ui.status(_('\n\tconfiguration using custom keyword template maps\n'))
   363         if uikwmaps:
   365         if uikwmaps:
   364             ui.status(_('\textending current template maps\n'))
   366             ui.status(_('\textending current template maps\n'))
   365         if opts.get('default') or not uikwmaps:
   367         if opts.get('default') or not uikwmaps:
   366             ui.status(_('\toverriding default template maps\n'))
   368             if svn:
       
   369                 ui.status(_('\toverriding default svn keywordset\n'))
       
   370             else:
       
   371                 ui.status(_('\toverriding default cvs keywordset\n'))
   367         if opts.get('rcfile'):
   372         if opts.get('rcfile'):
   368             ui.readconfig(opts.get('rcfile'))
   373             ui.readconfig(opts.get('rcfile'))
   369         if args:
   374         if args:
   370             # simulate hgrc parsing
   375             # simulate hgrc parsing
   371             rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args]
   376             rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args]
   373             fp.writelines(rcmaps)
   378             fp.writelines(rcmaps)
   374             fp.close()
   379             fp.close()
   375             ui.readconfig(repo.join('hgrc'))
   380             ui.readconfig(repo.join('hgrc'))
   376         kwmaps = dict(ui.configitems('keywordmaps'))
   381         kwmaps = dict(ui.configitems('keywordmaps'))
   377     elif opts.get('default'):
   382     elif opts.get('default'):
   378         ui.status(_('\n\tconfiguration using default keyword template maps\n'))
   383         if svn:
       
   384             ui.status(_('\n\tconfiguration using default svn keywordset\n'))
       
   385         else:
       
   386             ui.status(_('\n\tconfiguration using default cvs keywordset\n'))
   379         kwmaps = _defaultkwmaps(ui)
   387         kwmaps = _defaultkwmaps(ui)
   380         if uikwmaps:
   388         if uikwmaps:
   381             ui.status(_('\tdisabling current template maps\n'))
   389             ui.status(_('\tdisabling current template maps\n'))
   382             for k, v in kwmaps.iteritems():
   390             for k, v in kwmaps.iteritems():
   383                 ui.setconfig('keywordmaps', k, v)
   391                 ui.setconfig('keywordmaps', k, v)
   387 
   395 
   388     uisetup(ui)
   396     uisetup(ui)
   389     reposetup(ui, repo)
   397     reposetup(ui, repo)
   390     ui.write('[extensions]\nkeyword =\n')
   398     ui.write('[extensions]\nkeyword =\n')
   391     demoitems('keyword', ui.configitems('keyword'))
   399     demoitems('keyword', ui.configitems('keyword'))
       
   400     demoitems('keywordset', ui.configitems('keywordset'))
   392     demoitems('keywordmaps', kwmaps.iteritems())
   401     demoitems('keywordmaps', kwmaps.iteritems())
   393     keywords = '$' + '$\n$'.join(sorted(kwmaps.keys())) + '$\n'
   402     keywords = '$' + '$\n$'.join(sorted(kwmaps.keys())) + '$\n'
   394     repo.wopener(fn, 'w').write(keywords)
   403     repo.wopener(fn, 'w').write(keywords)
   395     repo[None].add([fn])
   404     repo[None].add([fn])
   396     ui.note(_('\nkeywords written to %s:\n') % fn)
   405     ui.note(_('\nkeywords written to %s:\n') % fn)
   463             ui.write(fmt % repo.pathto(f, cwd), label='kwfiles.' + kwstate)
   472             ui.write(fmt % repo.pathto(f, cwd), label='kwfiles.' + kwstate)
   464 
   473 
   465 def shrink(ui, repo, *pats, **opts):
   474 def shrink(ui, repo, *pats, **opts):
   466     '''revert expanded keywords in the working directory
   475     '''revert expanded keywords in the working directory
   467 
   476 
   468     Run before changing/disabling active keywords or if you experience
   477     Must be run before changing/disabling active keywords.
   469     problems with :hg:`import` or :hg:`merge`.
       
   470 
   478 
   471     kwshrink refuses to run if given files contain local changes.
   479     kwshrink refuses to run if given files contain local changes.
   472     '''
   480     '''
   473     # 3rd argument sets expansion to False
   481     # 3rd argument sets expansion to False
   474     _kwfwrite(ui, repo, False, *pats, **opts)
   482     _kwfwrite(ui, repo, False, *pats, **opts)
   626                 kwt.restrict = True
   634                 kwt.restrict = True
   627             return ret
   635             return ret
   628         finally:
   636         finally:
   629             wlock.release()
   637             wlock.release()
   630 
   638 
   631     repo.__class__ = kwrepo
       
   632 
       
   633     def kwfilectx_cmp(orig, self, fctx):
   639     def kwfilectx_cmp(orig, self, fctx):
   634         # keyword affects data size, comparing wdir and filelog size does
   640         # keyword affects data size, comparing wdir and filelog size does
   635         # not make sense
   641         # not make sense
   636         if (fctx._filerev is None and
   642         if (fctx._filerev is None and
   637             (self._repo._encodefilterpats or
   643             (self._repo._encodefilterpats or
   650         try:
   656         try:
   651             record = extensions.find(name)
   657             record = extensions.find(name)
   652             extensions.wrapfunction(record, 'dorecord', kw_dorecord)
   658             extensions.wrapfunction(record, 'dorecord', kw_dorecord)
   653         except KeyError:
   659         except KeyError:
   654             pass
   660             pass
       
   661 
       
   662     repo.__class__ = kwrepo
   655 
   663 
   656 cmdtable = {
   664 cmdtable = {
   657     'kwdemo':
   665     'kwdemo':
   658         (demo,
   666         (demo,
   659          [('d', 'default', None, _('show default keyword template maps')),
   667          [('d', 'default', None, _('show default keyword template maps')),