diff -r 5acf520f2115 -r 67e9fb23a32b hgkw/pretxnkw.py --- a/hgkw/pretxnkw.py Thu Dec 21 11:02:21 2006 +0100 +++ b/hgkw/pretxnkw.py Thu Dec 21 16:00:45 2006 +0100 @@ -1,8 +1,7 @@ +from hgkw import kwutil from mercurial.i18n import _ from mercurial import cmdutil, commands, util -import os.path, re, sys - -hgkeywords = 'Id|Header|Author|Date|Revision|RCSFile|Source' +import re, sys def pretxnkw(ui, repo, hooktype, **args): '''Collects candidates for keyword expansion on commit @@ -43,28 +42,15 @@ return False user, date = repo.changelog.read(repo.changelog.tip())[1:3] - strdate = util.datestr(date=date) - shortuser = util.shortuser(user) - shortdate = util.datestr(date=date, format=util.defaultdateformats[0]) - # %Y-%m-%d %H:%M:%S - - re_kw = re.compile(r'\$(%s)(: [^$]+? )?\$' % hgkeywords) + re_kw = re.compile(r'\$(%s)(: [^$]+? )?\$' % kwutil.hgkeywords) for f in files: data = repo.wfile(f).read() if not util.binary(data): def kwexpand(matchobj): - RCSFile = os.path.basename(f)+',v' - Source = os.path.join(repo.root, f)+',v' - Revision = args['node'][:12] - Date = strdate - Author = user - revdateauth = '%s %s %s' % (Revision, shortdate, shortuser) - Header = '%s %s' % (Source, revdateauth) - Id = '%s %s' % (RCSFile, revdateauth) - return '$%s: %s $' % ( - matchobj.group(1), eval(matchobj.group(1))) + return kwutil.kwexpand(matchobj, + repo, args['node'][:12], f, date, user) data, kwct = re_kw.subn(kwexpand, data) if kwct: