hgkw/keyword.py
branchkwmap-templates
changeset 106 61afa140949e
parent 105 2a8b0a71c2ec
child 107 fe4a0495eca8
--- a/hgkw/keyword.py	Tue Jan 16 12:09:37 2007 +0100
+++ b/hgkw/keyword.py	Tue Jan 16 15:45:57 2007 +0100
@@ -91,12 +91,10 @@
     def __init__(self, ui, repo):
         self.ui = ui
         self.repo = repo
-        self.templates = (dict(self.ui.configitems('keywordmaps'))
-                or deftemplates)
+        self.templates = dict(ui.configitems('keywordmaps')) or deftemplates
         self.re_kw = re.compile(r'\$(%s)[^$]*?\$' %
                 '|'.join(re.escape(k) for k in self.templates.keys()))
-        self.t = cmdutil.changeset_templater(self.ui, self.repo,
-                False, '', False)
+        self.t = cmdutil.changeset_templater(ui, repo, False, '', False)
 
     def expand(self, mobj, path, node):
         '''Expands keyword with corresponding template.'''
@@ -130,12 +128,15 @@
             super(kwfilelog, self).__init__(opener, path, defversion)
             self._repo = repo
             self._path = path
-            self.kwt = kwtemplater(ui, self._repo)
+            # only init kwtemplater if needed
+            if not isinstance(repo, int) and kwfmatches(ui, repo, [path]):
+                self.kwt = kwtemplater(ui, repo)
+            else:
+                self.kwt = None
 
         def iskwcandidate(self, data):
             '''Decides whether to act on keywords.'''
-            return (kwfmatches(ui, self._repo, [self._path])
-                    and not util.binary(data))
+            return self.kwt is not None and not util.binary(data)
 
         def read(self, node):
             '''Substitutes keywords when reading filelog.'''