Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 2944:2efa9b8aed30
load extensions from every hgrc.
before this change only extensions in global hgrc files were loaded.
now extensions in per-repo hgrc are loaded.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Fri, 18 Aug 2006 14:13:24 -0700 |
parents | 8e59010158ce |
children | 731f6b3d27c2 |
comparison
equal
deleted
inserted
replaced
2943:8e59010158ce | 2944:2efa9b8aed30 |
---|---|
3447 for k, v in external.iteritems(): | 3447 for k, v in external.iteritems(): |
3448 if k.endswith('.' + name) or k.endswith('/' + name) or v == name: | 3448 if k.endswith('.' + name) or k.endswith('/' + name) or v == name: |
3449 return sys.modules[v] | 3449 return sys.modules[v] |
3450 raise KeyError(name) | 3450 raise KeyError(name) |
3451 | 3451 |
3452 def load_extensions(ui, extensions): | 3452 def load_extensions(ui): |
3453 for ext_name, load_from_name in extensions: | 3453 added = [] |
3454 for ext_name, load_from_name in ui.extensions(): | |
3455 if ext_name in external: | |
3456 continue | |
3454 try: | 3457 try: |
3455 if load_from_name: | 3458 if load_from_name: |
3456 # the module will be loaded in sys.modules | 3459 # the module will be loaded in sys.modules |
3457 # choose an unique name so that it doesn't | 3460 # choose an unique name so that it doesn't |
3458 # conflicts with other modules | 3461 # conflicts with other modules |
3468 try: | 3471 try: |
3469 mod = importh("hgext.%s" % ext_name) | 3472 mod = importh("hgext.%s" % ext_name) |
3470 except ImportError: | 3473 except ImportError: |
3471 mod = importh(ext_name) | 3474 mod = importh(ext_name) |
3472 external[ext_name] = mod.__name__ | 3475 external[ext_name] = mod.__name__ |
3476 added.append((mod, ext_name)) | |
3473 except (util.SignalInterrupt, KeyboardInterrupt): | 3477 except (util.SignalInterrupt, KeyboardInterrupt): |
3474 raise | 3478 raise |
3475 except Exception, inst: | 3479 except Exception, inst: |
3476 ui.warn(_("*** failed to import extension %s: %s\n") % | 3480 ui.warn(_("*** failed to import extension %s: %s\n") % |
3477 (ext_name, inst)) | 3481 (ext_name, inst)) |
3478 if ui.print_exc(): | 3482 if ui.print_exc(): |
3479 return 1 | 3483 return 1 |
3480 | 3484 |
3481 for name in external.itervalues(): | 3485 for mod, name in added: |
3482 mod = sys.modules[name] | |
3483 uisetup = getattr(mod, 'uisetup', None) | 3486 uisetup = getattr(mod, 'uisetup', None) |
3484 if uisetup: | 3487 if uisetup: |
3485 uisetup(u) | 3488 uisetup(ui) |
3486 cmdtable = getattr(mod, 'cmdtable', {}) | 3489 cmdtable = getattr(mod, 'cmdtable', {}) |
3487 for t in cmdtable: | 3490 for t in cmdtable: |
3488 if t in table: | 3491 if t in table: |
3489 ui.warn(_("module %s overrides %s\n") % (name, t)) | 3492 ui.warn(_("module %s overrides %s\n") % (name, t)) |
3490 table.update(cmdtable) | 3493 table.update(cmdtable) |
3493 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': | 3496 for name in 'SIGBREAK', 'SIGHUP', 'SIGTERM': |
3494 num = getattr(signal, name, None) | 3497 num = getattr(signal, name, None) |
3495 if num: signal.signal(num, catchterm) | 3498 if num: signal.signal(num, catchterm) |
3496 | 3499 |
3497 try: | 3500 try: |
3498 u = ui.ui(traceback='--traceback' in sys.argv[1:]) | 3501 u = ui.ui(traceback='--traceback' in sys.argv[1:], |
3502 readhooks=[load_extensions]) | |
3499 except util.Abort, inst: | 3503 except util.Abort, inst: |
3500 sys.stderr.write(_("abort: %s\n") % inst) | 3504 sys.stderr.write(_("abort: %s\n") % inst) |
3501 return -1 | 3505 return -1 |
3502 | |
3503 load_extensions(u, u.extensions()) | |
3504 | 3506 |
3505 try: | 3507 try: |
3506 cmd, func, args, options, cmdoptions = parse(u, args) | 3508 cmd, func, args, options, cmdoptions = parse(u, args) |
3507 if options["time"]: | 3509 if options["time"]: |
3508 def get_times(): | 3510 def get_times(): |