diff -r 5acf520f2115 -r 67e9fb23a32b hgkw/kwutil.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgkw/kwutil.py Thu Dec 21 16:00:45 2006 +0100 @@ -0,0 +1,26 @@ +''' +kwutil provides required little helpers for the Mercurial +keyword extension and the Python pretxncommit hook pretxnkw. +''' + +from mercurial import util +import os.path + +# supported keywords for use in regexes +hgkeywords = 'Id|Header|Author|Date|Revision|RCSFile|Source' + +def kwexpand(matchobj, repo, Revision, f, date, Author): + '''Called by keyword extension and pretxnkw pretxncomit hook, + sets supported keywords as local variables and evaluates them + to their expansion if matchobj is equal to their string + representation.''' + RCSFile = os.path.basename(f)+',v' + Source = os.path.join(repo.root, f)+',v' + Date = util.datestr(date) + revdateauth = '%s %s %s' % (Revision, + util.datestr(date=date, format=util.defaultdateformats[0]), + # %Y-%m-%d %H:%M:%S + util.shortuser(Author)) + Header = '%s %s' % (Source, revdateauth) + Id = '%s %s' % (RCSFile, revdateauth) + return '$%s: %s $' % (matchobj.group(1), eval(matchobj.group(1)))