hgkw/pretxnkw.py
author Christian Ebert <blacktrash@gmx.net>
Mon, 18 Dec 2006 12:10:05 +0100
branchupdatehook
changeset 32 b70b38b15fa4
parent 27 d00d45c7ddaf
child 37 3dc31476c148
permissions -rw-r--r--
Update function descriptions
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):
32
b70b38b15fa4 Update function descriptions
Christian Ebert <blacktrash@gmx.net>
parents: 27
diff changeset
     8
    '''Collects candidates for keyword expansion on commit
b70b38b15fa4 Update function descriptions
Christian Ebert <blacktrash@gmx.net>
parents: 27
diff changeset
     9
    and passes them to kwexpander.'''
7
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    10
20
6dc2b4268920 Simplify for $Hg$ expansion scheme
Christian Ebert <blacktrash@gmx.net>
parents: 7
diff changeset
    11
    if hooktype != 'pretxncommit':
7
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    12
        # bail out with error
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    13
        return True
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    14
26
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    15
    # 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
    16
    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
    17
    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
    18
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    19
    # 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
    20
    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
    21
    candidates = modified + added
e5f131217f87 Add pretxnkw module for updatehook branch
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    22
26
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    23
    if candidates:
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    24
        r = repo.changelog.tip()
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    25
        n = args['node'][:12]
bda0dec1aaf1 Reparse cmdline to avoid expansion in uncommitted files
Christian Ebert <blacktrash@gmx.net>
parents: 20
diff changeset
    26
        # 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
    27
        return kwexpander.expandkw(ui, repo, r, n, candidates, update=False)