Make keyword do my hgkeyword; use basename again extension
authorChristian Ebert <blacktrash@gmx.net>
Tue, 19 Dec 2006 09:56:41 +0100
branchextension
changeset 34 3a79665dcbc3
parent 33 ebb39c6a1476
child 35 a730c9d4ec05
Make keyword do my hgkeyword; use basename again add() needs only str.replace(). TODO: Make even more compatible with cvs' $Id$? (date UTC, slashes) Check config before reading. And!: Use config file patterns, in cooperation with pretxnkw. This will expand keywords alread on commit!
hgkw/keyword.py
--- a/hgkw/keyword.py	Tue Dec 19 09:39:03 2006 +0100
+++ b/hgkw/keyword.py	Tue Dec 19 09:56:41 2006 +0100
@@ -1,5 +1,5 @@
 from mercurial import hg, filelog, revlog, context, util
-import re
+import os.path, re
 
 def reposetup(ui, repo):
     if not repo.local():
@@ -23,17 +23,18 @@
                 self._repo.ui.config("keywords", "expand", True)):
                 c = context.filectx(self._repo, self._path, fileid=node,
                                      filelog=self)
-                def author(): return "$Author %s $" % c.user()
-                def date(): return "$Date %s $" % util.datestr(c.date())
-
-                data = re.sub(r'\$Author\$', author(), data)
-                data = re.sub(r'\$Date\$', date(), data)
+                hgkw = '$Hg: %s,v %s %s %s $' % (
+                        os.path.basename(c.path()),
+                        c.changectx(),
+                        util.datestr(date=c.date(),
+                            format=util.defaultdateformats[0]),
+                        util.shortuser(c.user()))
+                data = data.replace('$Hg$', hgkw)
             return data
         def add(self, text, meta, tr, link, p1=None, p2=None):
             if (not util.binary(text) and
                    self._repo.ui.config("keywords", "remove", True)):
-                text = re.sub(r'\$Author[^\$]*\$', '$Author$', text)
-                text = re.sub(r'\$Date[^\$]*\$', '$Date$', text)
+                text = re.sub(r'\$Hg[^$]*?\$', '$Hg$', text)
             return super(kwfilelog, self).add(text, meta, tr, link, p1, p2)
 
     filelog.filelog = kwfilelog