mercurial/cmdutil.py
changeset 4630 e6d105a51ec7
parent 4622 6fc26982f203
child 4632 8d46056960ab
equal deleted inserted replaced
4629:a04b5f37eda7 4630:e6d105a51ec7
     7 
     7 
     8 from node import *
     8 from node import *
     9 from i18n import _
     9 from i18n import _
    10 import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex
    10 import os, sys, atexit, signal, pdb, traceback, socket, errno, shlex
    11 import mdiff, bdiff, util, templater, patch, commands, hg, lock, time
    11 import mdiff, bdiff, util, templater, patch, commands, hg, lock, time
    12 import fancyopts, revlog, version, extensions
    12 import fancyopts, revlog, version, extensions, hook
    13 
    13 
    14 revrangesep = ':'
    14 revrangesep = ':'
    15 
    15 
    16 class UnknownCommand(Exception):
    16 class UnknownCommand(Exception):
    17     """Exception raised if command is not in the command table."""
    17     """Exception raised if command is not in the command table."""
   270     # check for fallback encoding
   270     # check for fallback encoding
   271     fallback = lui.config('ui', 'fallbackencoding')
   271     fallback = lui.config('ui', 'fallbackencoding')
   272     if fallback:
   272     if fallback:
   273         util._fallbackencoding = fallback
   273         util._fallbackencoding = fallback
   274 
   274 
       
   275     fullargs = args
   275     cmd, func, args, options, cmdoptions = parse(ui, args)
   276     cmd, func, args, options, cmdoptions = parse(ui, args)
   276 
   277 
   277     if options["encoding"]:
   278     if options["encoding"]:
   278         util._encoding = options["encoding"]
   279         util._encoding = options["encoding"]
   279     if options["encodingmode"]:
   280     if options["encodingmode"]:
   300     elif options['version']:
   301     elif options['version']:
   301         return commands.version_(ui)
   302         return commands.version_(ui)
   302     elif not cmd:
   303     elif not cmd:
   303         return commands.help_(ui, 'shortlist')
   304         return commands.help_(ui, 'shortlist')
   304 
   305 
       
   306     repo = None
   305     if cmd not in commands.norepo.split():
   307     if cmd not in commands.norepo.split():
   306         repo = None
       
   307         try:
   308         try:
   308             repo = hg.repository(ui, path=path)
   309             repo = hg.repository(ui, path=path)
   309             ui = repo.ui
   310             ui = repo.ui
   310             if not repo.local():
   311             if not repo.local():
   311                 raise util.Abort(_("repository '%s' is not local") % path)
   312                 raise util.Abort(_("repository '%s' is not local") % path)
   314                 raise
   315                 raise
   315         d = lambda: func(ui, repo, *args, **cmdoptions)
   316         d = lambda: func(ui, repo, *args, **cmdoptions)
   316     else:
   317     else:
   317         d = lambda: func(ui, *args, **cmdoptions)
   318         d = lambda: func(ui, *args, **cmdoptions)
   318 
   319 
   319     return runcommand(ui, options, cmd, d)
   320     # run pre-hook, and abort if it fails
       
   321     ret = hook.hook(ui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs))
       
   322     if ret:
       
   323         return ret
       
   324     ret = runcommand(ui, options, cmd, d)
       
   325     # run post-hook, passing command result
       
   326     hook.hook(ui, repo, "post-%s" % cmd, False, args=" ".join(fullargs),
       
   327                     result = ret)
       
   328     return ret
   320 
   329 
   321 def runcommand(ui, options, cmd, cmdfunc):
   330 def runcommand(ui, options, cmd, cmdfunc):
   322     def checkargs():
   331     def checkargs():
   323         try:
   332         try:
   324             return cmdfunc()
   333             return cmdfunc()