##// END OF EJS Templates
extensions: extract closure that looks for commands from disabled module...
Yuya Nishihara -
r37995:b45f4c15 default
parent child Browse files
Show More
@@ -655,6 +655,28 b' def disabledext(name):'
655 655 if name in paths:
656 656 return _disabledhelp(paths[name])
657 657
658 def _finddisabledcmd(ui, cmd, name, path, strict):
659 try:
660 mod = loadpath(path, 'hgext.%s' % name)
661 except Exception:
662 return
663 try:
664 aliases, entry = cmdutil.findcmd(cmd,
665 getattr(mod, 'cmdtable', {}), strict)
666 except (error.AmbiguousCommand, error.UnknownCommand):
667 return
668 except Exception:
669 ui.warn(_('warning: error finding commands in %s\n') % path)
670 ui.traceback()
671 return
672 for c in aliases:
673 if c.startswith(cmd):
674 cmd = c
675 break
676 else:
677 cmd = aliases[0]
678 return (cmd, name, mod)
679
658 680 def disabledcmd(ui, cmd, strict=False):
659 681 '''import disabled extensions until cmd is found.
660 682 returns (cmdname, extname, module)'''
@@ -663,37 +685,15 b' def disabledcmd(ui, cmd, strict=False):'
663 685 if not paths:
664 686 raise error.UnknownCommand(cmd)
665 687
666 def findcmd(cmd, name, path):
667 try:
668 mod = loadpath(path, 'hgext.%s' % name)
669 except Exception:
670 return
671 try:
672 aliases, entry = cmdutil.findcmd(cmd,
673 getattr(mod, 'cmdtable', {}), strict)
674 except (error.AmbiguousCommand, error.UnknownCommand):
675 return
676 except Exception:
677 ui.warn(_('warning: error finding commands in %s\n') % path)
678 ui.traceback()
679 return
680 for c in aliases:
681 if c.startswith(cmd):
682 cmd = c
683 break
684 else:
685 cmd = aliases[0]
686 return (cmd, name, mod)
687
688 688 ext = None
689 689 # first, search for an extension with the same name as the command
690 690 path = paths.pop(cmd, None)
691 691 if path:
692 ext = findcmd(cmd, cmd, path)
692 ext = _finddisabledcmd(ui, cmd, cmd, path, strict=strict)
693 693 if not ext:
694 694 # otherwise, interrogate each extension until there's a match
695 695 for name, path in paths.iteritems():
696 ext = findcmd(cmd, name, path)
696 ext = _finddisabledcmd(ui, cmd, name, path, strict=strict)
697 697 if ext:
698 698 break
699 699 if ext:
General Comments 0
You need to be logged in to leave comments. Login now