hgkw/kwutil.py
branchmodular
changeset 46 67e9fb23a32b
equal deleted inserted replaced
45:5acf520f2115 46:67e9fb23a32b
       
     1 '''
       
     2 kwutil provides required little helpers for the Mercurial
       
     3 keyword extension and the Python pretxncommit hook pretxnkw.
       
     4 '''
       
     5 
       
     6 from mercurial import util
       
     7 import os.path
       
     8 
       
     9 # supported keywords for use in regexes
       
    10 hgkeywords = 'Id|Header|Author|Date|Revision|RCSFile|Source'
       
    11 
       
    12 def kwexpand(matchobj, repo, Revision, f, date, Author):
       
    13     '''Called by keyword extension and pretxnkw pretxncomit hook,
       
    14     sets supported keywords as local variables and evaluates them
       
    15     to their expansion if matchobj is equal to their string
       
    16     representation.'''
       
    17     RCSFile = os.path.basename(f)+',v'
       
    18     Source = os.path.join(repo.root, f)+',v'
       
    19     Date = util.datestr(date)
       
    20     revdateauth = '%s %s %s' % (Revision,
       
    21             util.datestr(date=date, format=util.defaultdateformats[0]),
       
    22                                                 # %Y-%m-%d %H:%M:%S
       
    23             util.shortuser(Author))
       
    24     Header = '%s %s' % (Source, revdateauth)
       
    25     Id = '%s %s' % (RCSFile, revdateauth)
       
    26     return '$%s: %s $' % (matchobj.group(1), eval(matchobj.group(1)))