hgkw/kwutil.py
branchdecodefilter
changeset 4 7e618d820490
child 14 b60345141aa5
equal deleted inserted replaced
3:b9f2c0853da3 4:7e618d820490
       
     1 # $Hg: kwutil.py,v$
       
     2 
       
     3 from mercurial.demandload import demandload
       
     4 demandload(globals(), 'mercurial:util re')
       
     5 
       
     6 def mkkw(repo, tip=False, node=''):
       
     7     '''Gathers info for Hg keyword and returns it as raw replacement string.'''
       
     8 
       
     9     # get hex
       
    10     if tip:
       
    11         parent1 = repo.changelog.tip()
       
    12     else:
       
    13         parent1 = repo.dirstate.parents()[0]
       
    14 
       
    15     if not node:
       
    16         node = repo.changectx(parent1)
       
    17 
       
    18     user, date = repo.changelog.read(parent1)[1:3]
       
    19     user = util.shortuser(user)
       
    20     date = util.datestr(date=date, format=util.defaultdateformats[0])
       
    21                                                # %Y-%m-%d %H:%M:%S
       
    22 
       
    23     return r'\1 %s %s %s $' % (node, date, user)
       
    24 
       
    25 
       
    26 def rekw():
       
    27     '''Returns compiled regex to detect hg keywords.'''
       
    28 
       
    29     return re.compile(r'([$]Hg: .+?,v).*?\$')