hgkw/keyword.py
branchkwmap-templates
changeset 100 4f1129ddbdb8
parent 99 f881ecdcdec9
child 101 98a65d978098
equal deleted inserted replaced
99:f881ecdcdec9 100:4f1129ddbdb8
    41     checked in by = {author}
    41     checked in by = {author}
    42     ...
    42     ...
    43 '''
    43 '''
    44 
    44 
    45 from mercurial import cmdutil, templater, util
    45 from mercurial import cmdutil, templater, util
       
    46 from mercurial.node import *
    46 import os.path, re, sys, time
    47 import os.path, re, sys, time
    47 
    48 
    48 deftemplates = {
    49 deftemplates = {
    49         'Revision': '{node|short}',
    50         'Revision': '{node|short}',
    50         'Author': '{author|user}',
    51         'Author': '{author|user}',
   139         def read(self, node):
   140         def read(self, node):
   140             '''Substitutes keywords when reading filelog.'''
   141             '''Substitutes keywords when reading filelog.'''
   141             data = super(kwfilelog, self).read(node)
   142             data = super(kwfilelog, self).read(node)
   142             if self.iskwcandidate(data):
   143             if self.iskwcandidate(data):
   143                 c = context.filectx(self._repo, self._path,
   144                 c = context.filectx(self._repo, self._path,
   144                          fileid=node, filelog=self)
   145                                     fileid=node, filelog=self)
   145                 return self.kwt.re_kw.sub(lambda m:
   146                 return self.kwt.re_kw.sub(lambda m:
   146                         self.kwt.expand(m, self._path, node=c.node()), data)
   147                         self.kwt.expand(m, self._path, node=c.node()), data)
   147             return data
   148             return data
   148 
   149 
   149         def add(self, text, meta, tr, link, p1=None, p2=None):
   150         def add(self, text, meta, tr, link, p1=None, p2=None):
   194     modified, added = repo.status(files=files, match=match)[:2]
   195     modified, added = repo.status(files=files, match=match)[:2]
   195     candidates = kwfmatches(ui, repo, modified+added)
   196     candidates = kwfmatches(ui, repo, modified+added)
   196     if not candidates:
   197     if not candidates:
   197         return
   198         return
   198 
   199 
   199     kwt = kwtemplater(ui, repo, node=repo.changelog.tip())
   200     kwt = kwtemplater(ui, repo, node=bin(args['node']))
   200     for f in candidates:
   201     for f in candidates:
   201         data = repo.wfile(f).read()
   202         data = repo.wfile(f).read()
   202         if not util.binary(data):
   203         if not util.binary(data):
   203             data, kwct = kwt.re_kw.subn(lambda m: kwt.expand(m, f), data)
   204             data, kwct = kwt.re_kw.subn(lambda m: kwt.expand(m, f), data)
   204             if kwct:
   205             if kwct: