hgkw/keyword.py
branchsolo-extension
changeset 57 f95c21f87e9c
parent 56 e8834575128b
child 58 9b428ae6ff15
--- a/hgkw/keyword.py	Fri Dec 29 14:14:23 2006 +0100
+++ b/hgkw/keyword.py	Fri Dec 29 15:23:58 2006 +0100
@@ -46,13 +46,19 @@
 # supported keywords for use in regexes
 hgkeywords = 'Id|Header|Author|Date|Revision|RCSFile|Source'
 
-def kwexpand(matchobj, repo, Revision, f, date, Author):
+def kwexpand(matchobj, repo, path, changeid=None, fileid=None, filelog=None):
     '''Called by kwfilelog.read and pretxnkw.
     Sets supported keywords as local variables and evaluates them to
     their expansion if matchobj is equal to string representation.'''
 
-    RCSFile = os.path.basename(f)+',v'
-    Source = repo.wjoin(f)+',v'
+    c = context.filectx(repo, path,
+            changeid=changeid, fileid=fileid, filelog=filelog)
+    date = c.date()
+
+    Revision = c.changectx()
+    Author = c.user()
+    RCSFile = os.path.basename(path)+',v'
+    Source = repo.wjoin(path)+',v'
     Date = util.datestr(date=date)
     revdateauth = '%s %s %s' % (Revision,
             util.datestr(date=date, format=util.defaultdateformats[0]),
@@ -88,14 +94,9 @@
                         mf = util.matcher(self._repo.root,
                                 '', [pat], [], [])[1]
                         if mf(self._path):
-                            c = context.filectx(self._repo, self._path,
-                                    fileid=node, filelog=self)
-
                             def kwexpander(matchobj):
-                                return kwexpand(matchobj,
-                                        self._repo, c.changectx(), self._path,
-                                        c.date(), c.user())
-
+                                return kwexpand(matchobj, self._repo,
+                                        self._path, fileid=node, filelog=self)
                             re_kw = re.compile(r'\$(%s)\$' % hgkeywords)
                             return re_kw.sub(kwexpander, data)
             return data
@@ -154,18 +155,14 @@
     if not files:
         return False
 
-    user, date = repo.changelog.read(repo.changelog.tip())[1:3]
     # 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):
-
             def kwexpander(matchobj):
-                return kwexpand(matchobj,
-                        repo, args['node'][:12], f, date, user)
-
+                return kwexpand(matchobj, repo, f, changeid=args['node'])
             data, kwct = re_kw.subn(kwexpander, data)
             if kwct:
                 ui.note(_('expanding keywords in %s\n' % f))