hgkw/keyword.py
branchextension
changeset 44 dc6e7d0e607f
parent 42 ba000e29ecf3
child 46 67e9fb23a32b
child 47 0617e7d497f6
equal deleted inserted replaced
43:fe5d9b9e78fc 44:dc6e7d0e607f
    20             self._repo = repo
    20             self._repo = repo
    21             self._path = path
    21             self._path = path
    22 
    22 
    23         def read(self, node):
    23         def read(self, node):
    24             data = super(kwfilelog, self).read(node)
    24             data = super(kwfilelog, self).read(node)
    25             if not util.binary(data):
    25             if util.binary(data):
    26                 c = context.filectx(self._repo, self._path, fileid=node,
    26                 return data
    27                                      filelog=self)
       
    28                 f = c.path()
       
    29                 for pat, opt in self._repo.ui.configitems('keyword'):
       
    30                     if opt == 'expand':
       
    31                         mf = util.matcher(self._repo.root,
       
    32                                 '', [pat], [], [])[1]
       
    33                         if mf(f):
       
    34                             re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
       
    35 
    27 
    36                             def kwexpand(matchobj):
    28             c = context.filectx(self._repo, self._path, fileid=node,
    37                                 RCSFile = os.path.basename(f)+',v'
    29                                  filelog=self)
    38                                 Source = os.path.join(self._repo.root, f)+',v'
    30             f = c.path()
    39                                 Revision = c.changectx()
    31             if f.startswith('.hg'):
    40                                 Date = util.datestr(date=c.date())
    32                 return data
    41                                 Author = c.user()
       
    42                                 revdateauth = '%s %s %s' % (
       
    43                                         Revision,
       
    44                                         util.datestr(date=c.date(),
       
    45                                             format=util.defaultdateformats[0]),
       
    46                                         util.shortuser(Author))
       
    47                                 Header = '%s %s' % (Source, revdateauth)
       
    48                                 Id = '%s %s' % (RCSFile, revdateauth)
       
    49                                 return '$%s: %s $' % (
       
    50                                         matchobj.group(1), eval(matchobj.group(1)))
       
    51 
    33 
    52                             return re_kw.sub(kwexpand, data)
    34             for pat, opt in self._repo.ui.configitems('keyword'):
       
    35                 if opt == 'expand':
       
    36                     mf = util.matcher(self._repo.root,
       
    37                             '', [pat], [], [])[1]
       
    38                     if mf(f):
       
    39                         re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
       
    40 
       
    41                         def kwexpand(matchobj):
       
    42                             RCSFile = os.path.basename(f)+',v'
       
    43                             Source = os.path.join(self._repo.root, f)+',v'
       
    44                             Revision = c.changectx()
       
    45                             Date = util.datestr(date=c.date())
       
    46                             Author = c.user()
       
    47                             revdateauth = '%s %s %s' % (
       
    48                                     Revision,
       
    49                                     util.datestr(date=c.date(),
       
    50                                         format=util.defaultdateformats[0]),
       
    51                                     util.shortuser(Author))
       
    52                             Header = '%s %s' % (Source, revdateauth)
       
    53                             Id = '%s %s' % (RCSFile, revdateauth)
       
    54                             return '$%s: %s $' % (
       
    55                                     matchobj.group(1), eval(matchobj.group(1)))
       
    56 
       
    57                         return re_kw.sub(kwexpand, data)
    53             return data
    58             return data
    54 
    59 
    55         def add(self, text, meta, tr, link, p1=None, p2=None):
    60         def add(self, text, meta, tr, link, p1=None, p2=None):
    56             if (not util.binary(text) and
    61             if (not util.binary(text) and
    57                    self._repo.ui.config('keyword', 'remove', True)):
    62                    self._repo.ui.config('keyword', 'remove', True)):