hgkw/keyword.py
branchsolo-extension
changeset 51 1ecb6ec5d16b
parent 50 fe891f87a16c
child 52 7783eb22de30
equal deleted inserted replaced
50:fe891f87a16c 51:1ecb6ec5d16b
    79             self._repo = repo
    79             self._repo = repo
    80             self._path = path
    80             self._path = path
    81 
    81 
    82         def read(self, node):
    82         def read(self, node):
    83             data = super(kwfilelog, self).read(node)
    83             data = super(kwfilelog, self).read(node)
    84             if util.binary(data):
    84             if not self._path.startswith('.hg') and not util.binary(data):
    85                 return data
       
    86 
    85 
    87             c = context.filectx(self._repo, self._path, fileid=node,
    86                 c = context.filectx(self._repo, self._path, fileid=node,
    88                                  filelog=self)
    87                                      filelog=self)
    89             if self._path.startswith('.hg'):
    88                 for pat, opt in self._repo.ui.configitems('keyword'):
    90                 return data
    89                     if opt == 'expand':
       
    90                         mf = util.matcher(self._repo.root,
       
    91                                 '', [pat], [], [])[1]
       
    92                         if mf(self._path):
    91 
    93 
    92             for pat, opt in self._repo.ui.configitems('keyword'):
    94                             def kwexpander(matchobj):
    93                 if opt == 'expand':
    95                                 return kwexpand(matchobj,
    94                     mf = util.matcher(self._repo.root,
    96                                         self._repo, c.changectx(), self._path,
    95                             '', [pat], [], [])[1]
    97                                         c.date(), c.user())
    96                     if mf(self._path):
       
    97 
    98 
    98                         def kwexpander(matchobj):
    99                             re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
    99                             return kwexpand(matchobj,
   100                             return re_kw.sub(kwexpander, data)
   100                                     self._repo, c.changectx(), self._path,
   101             return data
   101                                     c.date(), c.user())
       
   102 
   102 
   103                         re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
   103         def add(self, text, meta, tr, link, p1=None, p2=None):
   104                         return re_kw.sub(kwexpander, data)
   104             if not util.binary(text):
   105             return data
   105                 re_kw = re.compile(r'\$(%s): [^$]+? \$' % hgkeywords)
       
   106                 text = re_kw.sub(r'$\1$', text)
       
   107             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
   106 
   108 
   107         def size(self, rev):
   109         def size(self, rev):
   108             '''Overrides filelog's size() to use kwfilelog.read().'''
   110             '''Overrides filelog's size() to use kwfilelog.read().'''
   109             node = self.node(rev)
   111             node = self.node(rev)
   110             if self.renamed(node):
   112             if self.renamed(node):