hgkw/keyword.py
branchstable
changeset 716 409e8ba90661
parent 715 0614ba0295f6
child 730 bd1722740798
equal deleted inserted replaced
712:d01d3a15995a 716:409e8ba90661
   138 
   138 
   139     def substitute(self, data, path, ctx, subfunc):
   139     def substitute(self, data, path, ctx, subfunc):
   140         '''Replaces keywords in data with expanded template.'''
   140         '''Replaces keywords in data with expanded template.'''
   141         def kwsub(mobj):
   141         def kwsub(mobj):
   142             kw = mobj.group(1)
   142             kw = mobj.group(1)
   143             self.ct = cmdutil.changeset_templater(self.ui, self.repo,
   143             ct = cmdutil.changeset_templater(self.ui, self.repo,
   144                                                   False, None, '', False)
   144                                              False, None, '', False)
   145             self.ct.use_template(self.templates[kw])
   145             ct.use_template(self.templates[kw])
   146             self.ui.pushbuffer()
   146             self.ui.pushbuffer()
   147             self.ct.show(ctx, root=self.repo.root, file=path)
   147             ct.show(ctx, root=self.repo.root, file=path)
   148             ekw = templatefilters.firstline(self.ui.popbuffer())
   148             ekw = templatefilters.firstline(self.ui.popbuffer())
   149             return '$%s: %s $' % (kw, ekw)
   149             return '$%s: %s $' % (kw, ekw)
   150         return subfunc(kwsub, data)
   150         return subfunc(kwsub, data)
   151 
   151 
   152     def expand(self, path, node, data):
   152     def expand(self, path, node, data):
   320         ui.status(_('\n\tconfiguration using current keyword template maps\n'))
   320         ui.status(_('\n\tconfiguration using current keyword template maps\n'))
   321         kwmaps = dict(uikwmaps) or kwtemplater.templates
   321         kwmaps = dict(uikwmaps) or kwtemplater.templates
   322 
   322 
   323     uisetup(ui)
   323     uisetup(ui)
   324     reposetup(ui, repo)
   324     reposetup(ui, repo)
   325     for k, v in ui.configitems('extensions'):
   325     ui.write('[extensions]\nkeyword =\n')
   326         if k.endswith('keyword'):
       
   327             extension = '%s = %s' % (k, v)
       
   328             break
       
   329     ui.write('[extensions]\n%s\n' % extension)
       
   330     demoitems('keyword', ui.configitems('keyword'))
   326     demoitems('keyword', ui.configitems('keyword'))
   331     demoitems('keywordmaps', kwmaps.iteritems())
   327     demoitems('keywordmaps', kwmaps.iteritems())
   332     keywords = '$' + '$\n$'.join(sorted(kwmaps.keys())) + '$\n'
   328     keywords = '$' + '$\n$'.join(sorted(kwmaps.keys())) + '$\n'
   333     repo.wopener(fn, 'w').write(keywords)
   329     repo.wopener(fn, 'w').write(keywords)
   334     repo.add([fn])
   330     repo.add([fn])
   467             finally:
   463             finally:
   468                 del self.commitctx
   464                 del self.commitctx
   469 
   465 
   470         def kwcommitctx(self, ctx, error=False):
   466         def kwcommitctx(self, ctx, error=False):
   471             n = super(kwrepo, self).commitctx(ctx, error)
   467             n = super(kwrepo, self).commitctx(ctx, error)
       
   468             # no lock needed, only called from repo.commit() which already locks
   472             kwt.overwrite(n, True, None)
   469             kwt.overwrite(n, True, None)
   473             return n
   470             return n
   474 
   471 
   475     # monkeypatches
   472     # monkeypatches
   476     def kwpatchfile_init(orig, self, ui, fname, opener,
   473     def kwpatchfile_init(orig, self, ui, fname, opener,