##// END OF EJS Templates
Never exit directly from commands.dispatch(), but pass return code to caller....
Thomas Arendsen Hein -
r2057:fef2d653 default
parent child Browse files
Show More
@@ -2258,7 +2258,7 b' def recover(ui, repo):'
2258 """
2258 """
2259 if repo.recover():
2259 if repo.recover():
2260 return repo.verify()
2260 return repo.verify()
2261 return False
2261 return 1
2262
2262
2263 def remove(ui, repo, pat, *pats, **opts):
2263 def remove(ui, repo, pat, *pats, **opts):
2264 """remove the specified files on the next commit
2264 """remove the specified files on the next commit
@@ -3258,38 +3258,32 b' def dispatch(args):'
3258 u = ui.ui()
3258 u = ui.ui()
3259 except util.Abort, inst:
3259 except util.Abort, inst:
3260 sys.stderr.write(_("abort: %s\n") % inst)
3260 sys.stderr.write(_("abort: %s\n") % inst)
3261 sys.exit(1)
3261 return -1
3262
3262
3263 external = []
3263 external = []
3264 for x in u.extensions():
3264 for x in u.extensions():
3265 def on_exception(exc, inst):
3265 try:
3266 u.warn(_("*** failed to import extension %s: %s\n") % (x[0], inst))
3266 if x[1]:
3267 if "--traceback" in sys.argv[1:]:
3268 traceback.print_exc()
3269 sys.exit(0)
3270 if x[1]:
3271 try:
3272 mod = imp.load_source(x[0], x[1])
3267 mod = imp.load_source(x[0], x[1])
3273 except Exception, inst:
3268 else:
3274 on_exception(Exception, inst)
3269 def importh(name):
3275 continue
3270 mod = __import__(name)
3276 else:
3271 components = name.split('.')
3277 def importh(name):
3272 for comp in components[1:]:
3278 mod = __import__(name)
3273 mod = getattr(mod, comp)
3279 components = name.split('.')
3274 return mod
3280 for comp in components[1:]:
3281 mod = getattr(mod, comp)
3282 return mod
3283 try:
3284 try:
3275 try:
3285 mod = importh("hgext." + x[0])
3276 mod = importh("hgext." + x[0])
3286 except ImportError:
3277 except ImportError:
3287 mod = importh(x[0])
3278 mod = importh(x[0])
3288 except Exception, inst:
3279 external.append(mod)
3289 on_exception(Exception, inst)
3280 except Exception, inst:
3290 continue
3281 u.warn(_("*** failed to import extension %s: %s\n") % (x[0], inst))
3291
3282 if "--traceback" in sys.argv[1:]:
3292 external.append(mod)
3283 traceback.print_exc()
3284 return 1
3285 continue
3286
3293 for x in external:
3287 for x in external:
3294 cmdtable = getattr(x, 'cmdtable', {})
3288 cmdtable = getattr(x, 'cmdtable', {})
3295 for t in cmdtable:
3289 for t in cmdtable:
@@ -3331,14 +3325,11 b' def dispatch(args):'
3331 repo = path and hg.repository(u, path=path) or None
3325 repo = path and hg.repository(u, path=path) or None
3332
3326
3333 if options['help']:
3327 if options['help']:
3334 help_(u, cmd, options['version'])
3328 return help_(u, cmd, options['version'])
3335 sys.exit(0)
3336 elif options['version']:
3329 elif options['version']:
3337 show_version(u)
3330 return show_version(u)
3338 sys.exit(0)
3339 elif not cmd:
3331 elif not cmd:
3340 help_(u, 'shortlist')
3332 return help_(u, 'shortlist')
3341 sys.exit(0)
3342
3333
3343 if cmd not in norepo.split():
3334 if cmd not in norepo.split():
3344 try:
3335 try:
@@ -3393,15 +3384,12 b' def dispatch(args):'
3393 else:
3384 else:
3394 u.warn(_("hg: %s\n") % inst.args[1])
3385 u.warn(_("hg: %s\n") % inst.args[1])
3395 help_(u, 'shortlist')
3386 help_(u, 'shortlist')
3396 sys.exit(-1)
3397 except AmbiguousCommand, inst:
3387 except AmbiguousCommand, inst:
3398 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
3388 u.warn(_("hg: command '%s' is ambiguous:\n %s\n") %
3399 (inst.args[0], " ".join(inst.args[1])))
3389 (inst.args[0], " ".join(inst.args[1])))
3400 sys.exit(1)
3401 except UnknownCommand, inst:
3390 except UnknownCommand, inst:
3402 u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
3391 u.warn(_("hg: unknown command '%s'\n") % inst.args[0])
3403 help_(u, 'shortlist')
3392 help_(u, 'shortlist')
3404 sys.exit(1)
3405 except hg.RepoError, inst:
3393 except hg.RepoError, inst:
3406 u.warn(_("abort: "), inst, "!\n")
3394 u.warn(_("abort: "), inst, "!\n")
3407 except lock.LockHeld, inst:
3395 except lock.LockHeld, inst:
@@ -3448,7 +3436,6 b' def dispatch(args):'
3448 u.warn(_("abort: %s\n") % inst.strerror)
3436 u.warn(_("abort: %s\n") % inst.strerror)
3449 except util.Abort, inst:
3437 except util.Abort, inst:
3450 u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n')
3438 u.warn(_('abort: '), inst.args[0] % inst.args[1:], '\n')
3451 sys.exit(1)
3452 except TypeError, inst:
3439 except TypeError, inst:
3453 # was this an argument error?
3440 # was this an argument error?
3454 tb = traceback.extract_tb(sys.exc_info()[2])
3441 tb = traceback.extract_tb(sys.exc_info()[2])
@@ -3457,9 +3444,10 b' def dispatch(args):'
3457 u.debug(inst, "\n")
3444 u.debug(inst, "\n")
3458 u.warn(_("%s: invalid arguments\n") % cmd)
3445 u.warn(_("%s: invalid arguments\n") % cmd)
3459 help_(u, cmd)
3446 help_(u, cmd)
3460 except SystemExit:
3447 except SystemExit, inst:
3461 # don't catch this in the catch-all below
3448 # Commands shouldn't sys.exit directly, but give a return code.
3462 raise
3449 # Just in case catch this and and pass exit code to caller.
3450 return inst.code
3463 except:
3451 except:
3464 u.warn(_("** unknown exception encountered, details follow\n"))
3452 u.warn(_("** unknown exception encountered, details follow\n"))
3465 u.warn(_("** report bug details to mercurial@selenic.com\n"))
3453 u.warn(_("** report bug details to mercurial@selenic.com\n"))
@@ -3467,4 +3455,4 b' def dispatch(args):'
3467 % version.get_version())
3455 % version.get_version())
3468 raise
3456 raise
3469
3457
3470 sys.exit(-1)
3458 return -1
@@ -6,7 +6,7 b' 255'
6 abort: repository a not found!
6 abort: repository a not found!
7 255
7 255
8 abort: destination '../a' already exists
8 abort: destination '../a' already exists
9 1
9 255
10 abort: repository a not found!
10 abort: repository a not found!
11 255
11 255
12 abort: destination 'q' already exists
12 abort: destination 'q' already exists
General Comments 0
You need to be logged in to leave comments. Login now