--- a/hgkw/kwexpander.py Sun Dec 17 14:48:08 2006 +0100
+++ b/hgkw/kwexpander.py Sun Dec 17 15:32:34 2006 +0100
@@ -4,19 +4,23 @@
from mercurial import util
import re
-def expandkw(ui, repo, node, cid, candidates, update=False):
+def expandkw(ui, repo, rev, cid, candidates, update=False):
'''Important: returns False on success, True on failure.'''
# name of keyword encode filter:
kwencodefilter = 'hgkwencode'
- # look for <Dollar>Hg<Dollar>
- kwtrigger = '%sHg$' % '$'
+ # update only needs string search for encoded keyword
+ # as hgkwencode always runs before
+ kwstr = '%sHg$' % '$'
+
+ # pretxncommit looks for both encoded and decoded keywords
+ kwpat = r'[$]Hg(: %s,v [a-z0-9]{12} [^$]+? )?\$'
def wwritekw(ui, repo, f, text):
'''Writes text with kwupdates keywords to f in working directory.'''
ui.note(_('expanding keywords in %s\n' % f))
- # # backup file (?)
+ # # backup file in case of commit (?)
# absfile = repo.wjoin(f)
# util.copyfile(absfile, absfile+'.kwbak')
repo.wfile(f, 'w').write(text)
@@ -36,7 +40,7 @@
if not files: # nothing to do
return False
- user, date = repo.changelog.read(node)[1:3]
+ 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
@@ -47,21 +51,19 @@
for f in files:
text = repo.wfile(f).read()
- kwrepl = '%sHg: %s,v %s %s %s $' % ('$', f, cid, date, user)
+ kw = '%sHg: %s,v %s %s %s $' % ('$', f, cid, date, user)
- if update and text.find(kwtrigger) > -1:
- text = text.replace(kwtrigger, kwrepl)
+ if update and text.find(kwstr) > -1:
+ text = text.replace(kwstr, kw)
wwritekw(ui, repo, f, text)
kwupdates.append(f)
elif not update:
- re_kw = re.compile(r'[$]Hg(: %s,v [a-z0-9]{12} [^$]+? )?\$' % f)
- text, kwct = re_kw.subn(kwrepl, text)
+ re_kw = re.compile(kwpat % f)
+ text, kwct = re_kw.subn(kw, text)
if kwct:
wwritekw(ui, repo, f, text)
if kwupdates:
# cheat hg to believe that updated files were not modified
repo.dirstate.update(kwupdates, 'n')
-
- return False