hgkw/pretxnkw.py
author Christian Ebert <blacktrash@gmx.net>
Mon, 18 Dec 2006 01:42:06 +0100
branchupdatehook
changeset 30 bc3bdd329831
parent 27 d00d45c7ddaf
child 32 b70b38b15fa4
permissions -rw-r--r--
Test for binary
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
6dc2b4268920 Simplify for $Hg$ expansion scheme
Christian Ebert <blacktrash@gmx.net>
parents: 7
diff changeset
     1
# $Hg$
7
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     2
20
6dc2b4268920 Simplify for $Hg$ expansion scheme
Christian Ebert <blacktrash@gmx.net>
parents: 7
diff changeset
     3
import kwexpander
26
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
     4
from mercurial import cmdutil, commands
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
     5
import sys
7
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     6
20
6dc2b4268920 Simplify for $Hg$ expansion scheme
Christian Ebert <blacktrash@gmx.net>
parents: 7
diff changeset
     7
def pretxnkw(ui, repo, hooktype, **args):
7
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     8
    '''Important: returns False on success, True on failure.'''
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     9
20
6dc2b4268920 Simplify for $Hg$ expansion scheme
Christian Ebert <blacktrash@gmx.net>
parents: 7
diff changeset
    10
    if hooktype != 'pretxncommit':
7
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    11
        # bail out with error
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    12
        return True
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    13
26
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    14
    # reparse args, opts again as pretxncommit hook is silent about them
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    15
    sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[2:]
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    16
    files, match, anypats = cmdutil.matchpats(repo, sysargs, cmdopts)
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    17
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    18
    # validity checks should have been done already
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    19
    modified, added = repo.status(files=files, match=match)[:2]
7
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    20
    candidates = modified + added
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    21
26
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    22
    if candidates:
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    23
        r = repo.changelog.tip()
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    24
        n = args['node'][:12]
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    25
        # TODO: check whether we need parent1&2 like in updatekw
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    26
        return kwexpander.expandkw(ui, repo, r, n, candidates, update=False)