hgkw/keyword.py
branchkwmap-templates
changeset 122 d5c80df59655
parent 120 4a8a861da58c
child 123 6cf933de685a
--- a/hgkw/keyword.py	Tue Jan 23 15:26:33 2007 +0000
+++ b/hgkw/keyword.py	Fri Jan 26 12:10:53 2007 +0000
@@ -108,20 +108,6 @@
         sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
         return os.path.splitext(os.path.basename(__file__))[0]
 
-def kwfmatches(ui, repo, files):
-    '''Selects and weeds out candidates for keyword substitution
-    by patterns configured in [keyword] section in hgrc.'''
-    inc, exc = [], ['.hg*']
-    for pat, opt in ui.configitems('keyword'):
-        if opt != 'ignore':
-            inc.append(pat)
-        else:
-            exc.append(pat)
-    if not inc:
-        return []
-    kwfmatcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
-    return [f for f in files if kwfmatcher(f)]
-
 class kwtemplater(object):
     '''
     Sets up keyword templates, corresponding keyword regex, and
@@ -155,6 +141,17 @@
     if not repo.local():
         return
 
+    inc, exc = [], ['.hg*']
+    for pat, opt in ui.configitems('keyword'):
+        if opt != 'ignore':
+            inc.append(pat)
+        else:
+            exc.append(pat)
+    if not inc:
+        return
+
+    ui.kwfmatcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
+
     class kwrepo(repo.__class__):
         def file(self, f):
             if f[0] == '/':
@@ -172,7 +169,7 @@
             self._repo = repo
             self._path = path
             # only init kwtemplater if needed
-            if not isinstance(repo, int) and kwfmatches(ui, repo, [path]):
+            if not isinstance(repo, int) and ui.kwfmatcher(path):
                 self.kwt = kwtemplater(ui, repo)
             else:
                 self.kwt = None
@@ -221,7 +218,7 @@
 
     files, match, anypats = cmdutil.matchpats(repo, sysargs, cmdopts)
     modified, added = repo.status(files=files, match=match)[:2]
-    candidates = kwfmatches(ui, repo, modified+added)
+    candidates = [f for f in modified + added if ui.kwfmatcher(f)]
     if not candidates:
         return