Only 1 all-purpose regex, compiled at load solo-extension
authorChristian Ebert <blacktrash@gmx.net>
Fri, 29 Dec 2006 16:34:01 +0100
branchsolo-extension
changeset 59 94b26168791d
parent 58 9b428ae6ff15
child 60 9771775ef322
Only 1 all-purpose regex, compiled at load
hgkw/keyword.py
--- a/hgkw/keyword.py	Fri Dec 29 15:36:50 2006 +0100
+++ b/hgkw/keyword.py	Fri Dec 29 16:34:01 2006 +0100
@@ -43,8 +43,10 @@
 from mercurial import cmdutil, commands, context, filelog, revlog, util
 import os.path, re, sys
 
-# supported keywords for use in regexes
-hgkeywords = 'Id|Header|Author|Date|Revision|RCSFile|Source'
+
+re_kw = re.compile(
+        r'\$(Id|Header|Author|Date|Revision|RCSFile|Source)[^$]*?\$')
+
 
 def kwexpand(matchobj, repo, path, changeid=None, fileid=None, filelog=None):
     '''Called by kwfilelog.read and pretxnkw.
@@ -94,7 +96,6 @@
                         mf = util.matcher(self._repo.root,
                                 '', [pat], [], [])[1]
                         if mf(self._path):
-                            re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
                             return re_kw.sub(lambda m:
                                     kwexpand(m, self._repo, self._path,
                                         fileid=node, filelog=self),
@@ -103,7 +104,6 @@
 
         def add(self, text, meta, tr, link, p1=None, p2=None):
             if not util.binary(text):
-                re_kw = re.compile(r'\$(%s): [^$]+? \$' % hgkeywords)
                 text = re_kw.sub(r'$\1$', text)
             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
 
@@ -155,9 +155,6 @@
     if not files:
         return False
 
-    # update both expanded and unexpanded keywords
-    re_kw = re.compile(r'\$(%s)(: [^$]+? )?\$' % hgkeywords)
-
     for f in files:
         data = repo.wfile(f).read()
         if not util.binary(data):