hgkw/pretxnkw.py
branchupdatehook
changeset 26 bda0dec1aaf1
parent 20 6dc2b4268920
child 27 d00d45c7ddaf
equal deleted inserted replaced
25:aa3fbe81e9ad 26:bda0dec1aaf1
     1 # $Hg$
     1 # $Hg$
     2 
     2 
     3 import kwexpander
     3 import kwexpander
       
     4 from mercurial import cmdutil, commands
       
     5 import sys
     4 
     6 
     5 def pretxnkw(ui, repo, hooktype, **args):
     7 def pretxnkw(ui, repo, hooktype, **args):
     6     '''Important: returns False on success, True on failure.'''
     8     '''Important: returns False on success, True on failure.'''
     7 
     9 
     8     if hooktype != 'pretxncommit':
    10     if hooktype != 'pretxncommit':
     9         # bail out with error
    11         # bail out with error
    10         return True
    12         return True
    11 
    13 
    12     tip = repo.changelog.tip()
    14     # reparse args, opts again as pretxncommit hook is silent about them
    13     modified, added = repo.status()[:2]
    15     sysargs, globalopts, cmdopts = commands.parse(ui, sys.argv[1:])[2:]
       
    16     files, match, anypats = cmdutil.matchpats(repo, sysargs, cmdopts)
       
    17 
       
    18     # validity checks should have been done already
       
    19     modified, added = repo.status(files=files, match=match)[:2]
    14     candidates = modified + added
    20     candidates = modified + added
    15     # TODO: check whether we need parent1&2 like in updatekw
       
    16 
    21 
    17     return kwexpander.expandkw(ui, repo,
    22     if candidates:
    18             tip, args['node'][0:12], candidates, update=False)
    23         r = repo.changelog.tip()
       
    24         n = args['node'][:12]
       
    25         # TODO: check whether we need parent1&2 like in updatekw
       
    26         return kwexpander.expandkw(ui, repo, r, n, candidates, update=False)
       
    27 
       
    28     return False