--- a/hgkw/kwexpander.py Tue Dec 19 09:56:41 2006 +0100
+++ b/hgkw/kwexpander.py Tue Dec 19 10:00:28 2006 +0100
@@ -1,8 +1,6 @@
-# $Hg$
-
from mercurial.i18n import _
from mercurial import util
-import re
+import os.path, re
def expandkw(ui, repo, rev, cid, candidates, update=False):
'''Expands logged <Dollar>Hg<Dollar> in working directory.'''
@@ -12,10 +10,10 @@
# update only needs string search for encoded keyword
# as hgkwencode always runs before
- kwstr = '%sHg$' % '$'
+ kwstr = '$Hg$'
# pretxncommit looks for both encoded and decoded keywords
- kwpat = r'[$]Hg(: %s,v [a-z0-9]{12} [^$]+? )?\$'
+ re_kw = re.compile(r'\$Hg[^$]*?\$')
def wwritekw(ui, repo, f, text):
'''Writes text with kwupdates keywords to f in working directory.'''
@@ -24,24 +22,25 @@
repo.wfile(f, 'w').write(text)
# only check files that have hgkwencode assigned as encode filter
- files = []
+# files = []
# python2.4: files = set()
- for pat, cmd in repo.ui.configitems('encode'):
- if cmd.endswith(kwencodefilter):
- mf = util.matcher(repo.root, '', [pat], [], [])[1]
- for candidate in candidates:
- if mf(candidate) and candidate not in files:
- files.append(candidate)
+# for pat, cmd in repo.ui.configitems('encode'):
+# if cmd.endswith(kwencodefilter):
+# mf = util.matcher(repo.root, '', [pat], [], [])[1]
+# for candidate in candidates:
+# if mf(candidate) and candidate not in files:
+# files.append(candidate)
# python2.4:
# if mf(candidate): files.add(candidate)
- if not files: # nothing to do
- return False
+# if not files: # nothing to do
+# return False
+ files = candidates
user, date = repo.changelog.read(rev)[1:3]
user = util.shortuser(user)
- date = util.datestr(date=date, format=util.defaultdateformats[2])
- # %Y-%m-%d %H:%M
+ date = util.datestr(date=date, format=util.defaultdateformats[0])
+ # %Y-%m-%d %H:%M:%S
# collect filenames that were changed by hg update
kwupdates = []
@@ -54,7 +53,8 @@
# TODO for update:
# walk back through file history onto last add/modify
# like "hg log -l1 f"
- kw = '%sHg: %s,v %s %s %s $' % ('$', f, cid, date, user)
+ kw = '$Hg: %s,v %s %s %s $' % (
+ os.path.basename(f), cid, date, user)
if update and text.find(kwstr) > -1:
text = text.replace(kwstr, kw)
@@ -62,7 +62,6 @@
kwupdates.append(f)
elif not update:
- re_kw = re.compile(kwpat % f)
text, kwct = re_kw.subn(kw, text)
if kwct:
wwritekw(ui, repo, f, text)