comparison mercurial/dispatch.py @ 28391:73905484ef70

dispatch: make loading extra information from extension extensible This patch makes loading extra information from extension module at dispatching extensible. Factoring 'loadcmdtable()' into commands.py is a part of generalization of loading extra information. This extensibility assumes registration of new function like below, for example: - revset predicate - fileset predicate - template keyword - template filter - template function - internal merge tool - web command This patch requires not loader function itself but container module and the name of it, because listing loader function directly up implies actual loading module of it, even if it isn't used at runtime (for example, extensions don't always define revset predicate)
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 08 Mar 2016 23:04:53 +0900
parents aa73d6a5d9ea
children dcb4209bd30d
comparison
equal deleted inserted replaced
28386:1c658391b22f 28391:73905484ef70
741 d = lambda: fn(ui, *args[1:]) 741 d = lambda: fn(ui, *args[1:])
742 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d, 742 return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d,
743 [], {}) 743 [], {})
744 744
745 _loaded = set() 745 _loaded = set()
746
747 # list of (objname, loadermod, loadername) tuple:
748 # - objname is the name of an object in extension module, from which
749 # extra information is loaded
750 # - loadermod is the module where loader is placed
751 # - loadername is the name of the function, which takes (ui, extensionname,
752 # extraobj) arguments
753 extraloaders = [
754 ('cmdtable', commands, 'loadcmdtable'),
755 ]
756
746 def _dispatch(req): 757 def _dispatch(req):
747 args = req.args 758 args = req.args
748 ui = req.ui 759 ui = req.ui
749 760
750 # check for cwd 761 # check for cwd
770 ui.__class__ = lui.__class__ 781 ui.__class__ = lui.__class__
771 782
772 # (uisetup and extsetup are handled in extensions.loadall) 783 # (uisetup and extsetup are handled in extensions.loadall)
773 784
774 for name, module in exts: 785 for name, module in exts:
775 cmdtable = getattr(module, 'cmdtable', {}) 786 for objname, loadermod, loadername in extraloaders:
776 overrides = [cmd for cmd in cmdtable if cmd in commands.table] 787 extraobj = getattr(module, objname, None)
777 if overrides: 788 if extraobj is not None:
778 ui.warn(_("extension '%s' overrides commands: %s\n") 789 getattr(loadermod, loadername)(ui, name, extraobj)
779 % (name, " ".join(overrides)))
780 commands.table.update(cmdtable)
781 _loaded.add(name) 790 _loaded.add(name)
782 791
783 # (reposetup is handled in hg.repository) 792 # (reposetup is handled in hg.repository)
784 793
785 addaliases(lui, commands.table) 794 addaliases(lui, commands.table)