Implement configurable exclusion of files from expansion kwmap-templates
authorChristian Ebert <blacktrash@gmx.net>
Tue, 16 Jan 2007 19:17:54 +0100
branchkwmap-templates
changeset 107 fe4a0495eca8
parent 106 61afa140949e
child 108 25dac950a1f0
Implement configurable exclusion of files from expansion
hgkw/keyword.py
--- a/hgkw/keyword.py	Tue Jan 16 15:45:57 2007 +0100
+++ b/hgkw/keyword.py	Tue Jan 16 19:17:54 2007 +0100
@@ -37,8 +37,10 @@
     # hgext.keyword =
     
     # filename patterns for expansion are configured in this section
+    # files matching patterns with value 'ignore' are ignored
     [keyword]
-    **.py = expand
+    **.py =
+    x* = ignore
     ...
     # in case you prefer your own keyword maps over the cvs-like defaults:
     [keywordmaps]
@@ -75,11 +77,12 @@
 def kwfmatches(ui, repo, files):
     '''Selects candidates for keyword substitution
     configured in keyword section in hgrc.'''
-    names = [pat for pat, opt in ui.configitems('keyword') if opt == 'expand']
-    if not names:
-        ui.warn(_('keyword: no filename patterns for expansion\n'))
+    inc = [pat for pat, opt in ui.configitems('keyword') if opt != 'ignore']
+    if not inc:
+        ui.warn(_('keyword: no filename globs for expansion\n'))
         return []
-    kwfmatcher = util.matcher(repo.root, cwd='', names=names, exc=['.hg*'])[1]
+    exc = [pat for pat, opt in ui.configitems('keyword') if opt == 'ignore']
+    kwfmatcher = util.matcher(repo.root, inc=inc, exc=['.hg*']+exc)[1]
     return [f for f in files if kwfmatcher(f)]
 
 
@@ -95,6 +98,7 @@
         self.re_kw = re.compile(r'\$(%s)[^$]*?\$' %
                 '|'.join(re.escape(k) for k in self.templates.keys()))
         self.t = cmdutil.changeset_templater(ui, repo, False, '', False)
+            
 
     def expand(self, mobj, path, node):
         '''Expands keyword with corresponding template.'''