# HG changeset patch # User Christian Ebert # Date 1166081724 -3600 # Node ID 7e618d820490cd8ac8f6455e3febdd31391ad98a # Parent b9f2c0853da3bc1cf896a43a1c31cf757318fb9d decodefilter branch: add decode filter with kwutil module diff -r b9f2c0853da3 -r 7e618d820490 hgkw/hgkwdecode.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgkw/hgkwdecode.py Thu Dec 14 08:35:24 2006 +0100 @@ -0,0 +1,14 @@ +# $Hg: hgkwdecode.py,v$ + +from mercurial.demandload import demandload +demandload(globals(), 'hgkw:kwutil mercurial:localrepo re sys') + +def kwdecode(): + '''Expands keywords into IO stream.''' + + lr = localrepo.localrepository(None) + + kword = kwutil.mkkw(lr, tip=False, node='') + re_kw = kwutil.rekw() + + sys.stdout.write(re_kw.sub(kword, sys.stdin.read())) diff -r b9f2c0853da3 -r 7e618d820490 hgkw/kwutil.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgkw/kwutil.py Thu Dec 14 08:35:24 2006 +0100 @@ -0,0 +1,29 @@ +# $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).*?\$') diff -r b9f2c0853da3 -r 7e618d820490 hgkwdecode --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgkwdecode Thu Dec 14 08:35:24 2006 +0100 @@ -0,0 +1,6 @@ +#!/usr/bin/env python +# $Hg: hgkwdecode,v$ + +from hgkw import hgkwdecode + +hgkwdecode.kwdecode()