hgkw/kwutil.py
author Christian Ebert <blacktrash@gmx.net>
Thu, 14 Dec 2006 16:25:12 +0100
branchdecodefilter
changeset 12 d9c4fc735963
parent 4 7e618d820490
child 14 b60345141aa5
permissions -rw-r--r--
Added tag filename for changeset 56a61a5c696d

# $Hg: kwutil.py,v$

from mercurial.demandload import demandload
demandload(globals(), 'mercurial:util re')

def mkkw(repo, tip=False, node=''):
    '''Gathers info for Hg keyword and returns it as raw replacement string.'''

    # get hex
    if tip:
        parent1 = repo.changelog.tip()
    else:
        parent1 = repo.dirstate.parents()[0]

    if not node:
        node = repo.changectx(parent1)

    user, date = repo.changelog.read(parent1)[1:3]
    user = util.shortuser(user)
    date = util.datestr(date=date, format=util.defaultdateformats[0])
                                               # %Y-%m-%d %H:%M:%S

    return r'\1 %s %s %s $' % (node, date, user)


def rekw():
    '''Returns compiled regex to detect hg keywords.'''

    return re.compile(r'([$]Hg: .+?,v).*?\$')