hgkw/keyword.py
branchkwmap-templates
changeset 107 fe4a0495eca8
parent 106 61afa140949e
child 108 25dac950a1f0
equal deleted inserted replaced
106:61afa140949e 107:fe4a0495eca8
    35     hgext.keyword = /full/path/to/script
    35     hgext.keyword = /full/path/to/script
    36     # or, if script in hgext folder:
    36     # or, if script in hgext folder:
    37     # hgext.keyword =
    37     # hgext.keyword =
    38     
    38     
    39     # filename patterns for expansion are configured in this section
    39     # filename patterns for expansion are configured in this section
       
    40     # files matching patterns with value 'ignore' are ignored
    40     [keyword]
    41     [keyword]
    41     **.py = expand
    42     **.py =
       
    43     x* = ignore
    42     ...
    44     ...
    43     # in case you prefer your own keyword maps over the cvs-like defaults:
    45     # in case you prefer your own keyword maps over the cvs-like defaults:
    44     [keywordmaps]
    46     [keywordmaps]
    45     HGdate = {date|rfc822date}
    47     HGdate = {date|rfc822date}
    46     lastlog = {desc} ## same as {desc|firstline} in this context
    48     lastlog = {desc} ## same as {desc|firstline} in this context
    73 templater.common_filters['utcdate'] = utcdate
    75 templater.common_filters['utcdate'] = utcdate
    74 
    76 
    75 def kwfmatches(ui, repo, files):
    77 def kwfmatches(ui, repo, files):
    76     '''Selects candidates for keyword substitution
    78     '''Selects candidates for keyword substitution
    77     configured in keyword section in hgrc.'''
    79     configured in keyword section in hgrc.'''
    78     names = [pat for pat, opt in ui.configitems('keyword') if opt == 'expand']
    80     inc = [pat for pat, opt in ui.configitems('keyword') if opt != 'ignore']
    79     if not names:
    81     if not inc:
    80         ui.warn(_('keyword: no filename patterns for expansion\n'))
    82         ui.warn(_('keyword: no filename globs for expansion\n'))
    81         return []
    83         return []
    82     kwfmatcher = util.matcher(repo.root, cwd='', names=names, exc=['.hg*'])[1]
    84     exc = [pat for pat, opt in ui.configitems('keyword') if opt == 'ignore']
       
    85     kwfmatcher = util.matcher(repo.root, inc=inc, exc=['.hg*']+exc)[1]
    83     return [f for f in files if kwfmatcher(f)]
    86     return [f for f in files if kwfmatcher(f)]
    84 
    87 
    85 
    88 
    86 class kwtemplater(object):
    89 class kwtemplater(object):
    87     '''
    90     '''
    93         self.repo = repo
    96         self.repo = repo
    94         self.templates = dict(ui.configitems('keywordmaps')) or deftemplates
    97         self.templates = dict(ui.configitems('keywordmaps')) or deftemplates
    95         self.re_kw = re.compile(r'\$(%s)[^$]*?\$' %
    98         self.re_kw = re.compile(r'\$(%s)[^$]*?\$' %
    96                 '|'.join(re.escape(k) for k in self.templates.keys()))
    99                 '|'.join(re.escape(k) for k in self.templates.keys()))
    97         self.t = cmdutil.changeset_templater(ui, repo, False, '', False)
   100         self.t = cmdutil.changeset_templater(ui, repo, False, '', False)
       
   101             
    98 
   102 
    99     def expand(self, mobj, path, node):
   103     def expand(self, mobj, path, node):
   100         '''Expands keyword with corresponding template.'''
   104         '''Expands keyword with corresponding template.'''
   101         kw = mobj.group(1)
   105         kw = mobj.group(1)
   102         template = templater.parsestring(self.templates[kw], quoted=False)
   106         template = templater.parsestring(self.templates[kw], quoted=False)