hgkw/kwutil.py
author Christian Ebert <blacktrash@gmx.net>
Thu, 21 Dec 2006 16:00:45 +0100
branchmodular
changeset 46 67e9fb23a32b
permissions -rw-r--r--
Make keyword.py depend on resurrected kwutil.py This makes pretxnkw perhaps a bit slower, but is more readable.

'''
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)))