mercurial/cmdutil.py
changeset 4686 849f011dbf79
parent 4671 150afe6becf6
child 4714 a741293793f6
equal deleted inserted replaced
4683:8c3d449ecc63 4686:849f011dbf79
    18 class AmbiguousCommand(Exception):
    18 class AmbiguousCommand(Exception):
    19     """Exception raised if command shortcut matches more than one command."""
    19     """Exception raised if command shortcut matches more than one command."""
    20 class ParseError(Exception):
    20 class ParseError(Exception):
    21     """Exception raised on errors in parsing the command line."""
    21     """Exception raised on errors in parsing the command line."""
    22 
    22 
    23 def runcatch(ui, args):
    23 def runcatch(ui, args, argv0=None):
    24     def catchterm(*args):
    24     def catchterm(*args):
    25         raise util.SignalInterrupt
    25         raise util.SignalInterrupt
    26 
    26 
    27     for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
    27     for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM':
    28         num = getattr(signal, name, None)
    28         num = getattr(signal, name, None)
    32         try:
    32         try:
    33             # enter the debugger before command execution
    33             # enter the debugger before command execution
    34             if '--debugger' in args:
    34             if '--debugger' in args:
    35                 pdb.set_trace()
    35                 pdb.set_trace()
    36             try:
    36             try:
    37                 return dispatch(ui, args)
    37                 return dispatch(ui, args, argv0=argv0)
    38             finally:
    38             finally:
    39                 ui.flush()
    39                 ui.flush()
    40         except:
    40         except:
    41             # enter the debugger when we hit an exception
    41             # enter the debugger when we hit an exception
    42             if '--debugger' in args:
    42             if '--debugger' in args:
   253     for opt in aliases:
   253     for opt in aliases:
   254         if opt in args:
   254         if opt in args:
   255             return args[args.index(opt) + 1]
   255             return args[args.index(opt) + 1]
   256     return None
   256     return None
   257 
   257 
   258 def dispatch(ui, args):
   258 def dispatch(ui, args, argv0=None):
       
   259     # remember how to call 'hg' before changing the working dir
       
   260     util.set_hgexecutable(argv0)
       
   261 
   259     # check for cwd first
   262     # check for cwd first
   260     cwd = earlygetopt(['--cwd'], args)
   263     cwd = earlygetopt(['--cwd'], args)
   261     if cwd:
   264     if cwd:
   262         os.chdir(cwd)
   265         os.chdir(cwd)
   263 
   266