hgkw/keyword.py
branchkwmap-templates
changeset 184 30b3e6a09a9d
parent 183 80fa00250c6d
child 185 bc5cd6cf69bc
equal deleted inserted replaced
183:80fa00250c6d 184:30b3e6a09a9d
   220     msg = '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     ui.note(_('creating temporary repo at %s\n') % tmpdir)
   223     ui.note(_('creating temporary repo at %s\n') % tmpdir)
   224     _repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   224     _repo = localrepo.localrepository(ui, path=tmpdir, create=True)
   225     _repo.ui.setconfig('keyword', fn, '')
   225     # for backwards compatibility
       
   226     ui = _repo.ui
       
   227     ui.setconfig('keyword', fn, '')
   226     if opts['default']:
   228     if opts['default']:
   227         kwstatus = 'default'
   229         kwstatus = 'default'
   228         kwmaps = deftemplates
   230         kwmaps = deftemplates
   229     else:
   231     else:
   230         kwstatus = 'current'
   232         kwstatus = 'current'
   231         kwmaps = dict(ui.configitems('keywordmaps')) or deftemplates
   233         kwmaps = dict(ui.configitems('keywordmaps')) or deftemplates
   232     if ui.configitems('keywordmaps'):
   234     if ui.configitems('keywordmaps'):
   233         for k, v in kwmaps.items():
   235         for k, v in kwmaps.items():
   234             _repo.ui.setconfig('keywordmaps', k, v)
   236             ui.setconfig('keywordmaps', k, v)
   235     reposetup(_repo.ui, _repo)
   237     reposetup(ui, _repo)
   236     ui.status(_('config with %s keyword template maps:\n') % kwstatus)
   238     ui.status(_('config with %s keyword template maps:\n') % kwstatus)
   237     ui.write('[keyword]\n%s =\n[keywordmaps]\n' % fn)
   239     ui.write('[keyword]\n%s =\n[keywordmaps]\n' % fn)
   238     for k, v in kwmaps.items():
   240     for k, v in kwmaps.items():
   239         ui.write('%s = %s\n' % (k, v))
   241         ui.write('%s = %s\n' % (k, v))
   240     path = _repo.wjoin(fn)
   242     path = _repo.wjoin(fn)
   259     Wraps commit to overwrite configured files with updated
   261     Wraps commit to overwrite configured files with updated
   260     keyword substitutions.
   262     keyword substitutions.
   261     This is done for local repos only, and only if there are
   263     This is done for local repos only, and only if there are
   262     files configured at all for keyword substitution.'''
   264     files configured at all for keyword substitution.'''
   263 
   265 
   264     if not repo.local() or getcmd(repo.ui) in nokwcommands:
   266     # for backwards compatibility
       
   267     ui = repo.ui
       
   268 
       
   269     if not repo.local() or getcmd(ui) in nokwcommands:
   265         return
   270         return
   266 
   271 
   267     kwfmatcher = keywordmatcher(ui, repo)
   272     kwfmatcher = keywordmatcher(ui, repo)
   268     if kwfmatcher is None:
   273     if kwfmatcher is None:
   269         return
   274         return
   270 
       
   271     # for backwards compatibility
       
   272     ui = repo.ui
       
   273 
   275 
   274     class kwrepo(repo.__class__):
   276     class kwrepo(repo.__class__):
   275         def file(self, f):
   277         def file(self, f):
   276             if f[0] == '/':
   278             if f[0] == '/':
   277                 f = f[1:]
   279                 f = f[1:]