hgkw/keyword.py
branch0.9.2compat
changeset 303 46ccec2f325f
parent 299 50bb27cfd926
child 311 6160401f94f2
equal deleted inserted replaced
299:50bb27cfd926 303:46ccec2f325f
   166         self.ui = ui
   166         self.ui = ui
   167         self.repo = repo
   167         self.repo = repo
   168         self.t = expand or None
   168         self.t = expand or None
   169         self.path = path
   169         self.path = path
   170         self.node = node
   170         self.node = node
   171         self.debug = self.ui.debugflag
       
   172 
   171 
   173         kwmaps = self.ui.configitems('keywordmaps')
   172         kwmaps = self.ui.configitems('keywordmaps')
   174         if kwmaps: # override default templates
   173         if kwmaps: # override default templates
   175             kwmaps = [(k, templater.parsestring(v, quoted=False))
   174             kwmaps = [(k, templater.parsestring(v, quoted=False))
   176                       for (k, v) in kwmaps]
   175                       for (k, v) in kwmaps]
   208             for f in files:
   207             for f in files:
   209                 self.repo.dirstate.normal(f)
   208                 self.repo.dirstate.normal(f)
   210         except AttributeError:
   209         except AttributeError:
   211             self.repo.dirstate.update(files, 'n')
   210             self.repo.dirstate.update(files, 'n')
   212 
   211 
   213     def kwsub(self, mobj):
       
   214         '''Substitutes keyword using corresponding template.'''
       
   215         kw = mobj.group(1)
       
   216         self.t.use_template(self.templates[kw])
       
   217         self.ui.pushbuffer()
       
   218         self.t.show(changenode=self.node, root=self.repo.root, file=self.path)
       
   219         keywordsub = templater.firstline(self.ui.popbuffer())
       
   220         return '$%s: %s $' % (kw, keywordsub)
       
   221 
       
   222     def substitute(self, node, data, subfunc):
   212     def substitute(self, node, data, subfunc):
   223         '''Obtains node if missing.
   213         '''Obtains node if missing, and calls given substitution function.'''
   224         Ensures consistent templates regardless of ui.debugflag.
       
   225         Calls given substitution function.'''
       
   226         if not self.node:
   214         if not self.node:
   227             c = context.filectx(self.repo, self.path, fileid=node)
   215             c = context.filectx(self.repo, self.path, fileid=node)
   228             self.node = c.node()
   216             self.node = c.node()
   229         self.ui.debugflag = False
   217 
   230         result = subfunc(self.kwsub, data)
   218         def kwsub(mobj):
   231         self.ui.debugflag = self.debug
   219             '''Substitutes keyword using corresponding template.'''
   232         return result
   220             kw = mobj.group(1)
       
   221             self.t.use_template(self.templates[kw])
       
   222             self.ui.pushbuffer()
       
   223             self.t.show(changenode=self.node,
       
   224                         root=self.repo.root, file=self.path)
       
   225             return '$%s: %s $' % (kw, templater.firstline(self.ui.popbuffer()))
       
   226 
       
   227         return subfunc(kwsub, data)
   233 
   228 
   234     def expand(self, node, data):
   229     def expand(self, node, data):
   235         '''Returns data with keywords expanded.'''
   230         '''Returns data with keywords expanded.'''
   236         if util.binary(data):
   231         if util.binary(data):
   237             return data
   232             return data