No reposetup when no filenames are specified for expansion kwmap-templates
authorChristian Ebert <blacktrash@gmx.net>
Fri, 26 Jan 2007 12:10:53 +0000
branchkwmap-templates
changeset 122 d5c80df59655
parent 121 85ed7d71ba0f
child 123 6cf933de685a
No reposetup when no filenames are specified for expansion Second stab at stopping reposetup. This time kwtemplater is still initialized in kwfilelog and pretxnkw, and not in reposetup. Watchout: Giving ui an extra-attribute in reposetup might still be problematic.
hgkw/keyword.py
--- 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