hgkw/keyword.py
branchmodular
changeset 46 67e9fb23a32b
parent 44 dc6e7d0e607f
--- a/hgkw/keyword.py	Thu Dec 21 11:02:21 2006 +0100
+++ b/hgkw/keyword.py	Thu Dec 21 16:00:45 2006 +0100
@@ -1,9 +1,13 @@
-from mercurial import hg, filelog, revlog, context, util
-import os.path, re
-
-hgkeywords = 'Id|Header|Author|Date|Revision|RCSFile|Source'
+from mercurial.i18n import _
+from mercurial import filelog, revlog, context, util
+import re
 
 def reposetup(ui, repo):
+    try:
+        from hgkw import kwutil
+    except ImportError, e:
+        raise util.Abort(_('%s\nkeyword extension needs package hgkw\n') % e)
+
     if not repo.local():
         return
 
@@ -36,31 +40,20 @@
                     mf = util.matcher(self._repo.root,
                             '', [pat], [], [])[1]
                     if mf(f):
-                        re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
 
                         def kwexpand(matchobj):
-                            RCSFile = os.path.basename(f)+',v'
-                            Source = os.path.join(self._repo.root, f)+',v'
-                            Revision = c.changectx()
-                            Date = util.datestr(date=c.date())
-                            Author = c.user()
-                            revdateauth = '%s %s %s' % (
-                                    Revision,
-                                    util.datestr(date=c.date(),
-                                        format=util.defaultdateformats[0]),
-                                    util.shortuser(Author))
-                            Header = '%s %s' % (Source, revdateauth)
-                            Id = '%s %s' % (RCSFile, revdateauth)
-                            return '$%s: %s $' % (
-                                    matchobj.group(1), eval(matchobj.group(1)))
+                            return kwutil.kwexpand(matchobj,
+                                    self._repo, c.changectx(), f,
+                                    c.date(), c.user())
 
+                        re_kw = re.compile(r'\$(%s)\$' % kwutil.hgkeywords)
                         return re_kw.sub(kwexpand, data)
             return data
 
         def add(self, text, meta, tr, link, p1=None, p2=None):
             if (not util.binary(text) and
                    self._repo.ui.config('keyword', 'remove', True)):
-                re_kw = re.compile(r'\$(%s): [^$]+? \$' % hgkeywords)
+                re_kw = re.compile(r'\$(%s): [^$]+? \$' % kwutil.hgkeywords)
                 text = re_kw.sub(r'$\1$', text)
             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)