hgkw/pretxnkw.py
author Christian Ebert <blacktrash@gmx.net>
Tue, 19 Dec 2006 09:56:41 +0100
branchextension
changeset 34 3a79665dcbc3
parent 32 b70b38b15fa4
child 37 3dc31476c148
permissions -rw-r--r--
Make keyword do my hgkeyword; use basename again add() needs only str.replace(). TODO: Make even more compatible with cvs' $Id$? (date UTC, slashes) Check config before reading. And!: Use config file patterns, in cooperation with pretxnkw. This will expand keywords alread on commit!

# $Hg$

import kwexpander
from mercurial import cmdutil, commands
import sys

def pretxnkw(ui, repo, hooktype, **args):
    '''Collects candidates for keyword expansion on commit
    and passes them to kwexpander.'''

    if hooktype != 'pretxncommit':
        # bail out with error
        return True

    # reparse args, opts again as pretxncommit hook is silent about them
    sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[2:]
    files, match, anypats = cmdutil.matchpats(repo, sysargs, cmdopts)

    # validity checks should have been done already
    modified, added = repo.status(files=files, match=match)[:2]
    candidates = modified + added

    if candidates:
        r = repo.changelog.tip()
        n = args['node'][:12]
        # TODO: check whether we need parent1&2 like in updatekw
        return kwexpander.expandkw(ui, repo, r, n, candidates, update=False)