Patchwork [1,of,2,RFC] dispatch: remember command table per extension (PoC DO NOT PUSH)

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 22, 2018, 2:54 p.m.
Message ID <e2030eaec92b1ed12577.1519311286@mimosa>
Download mbox | patch
Permalink /patch/28259/
State New
Headers show

Comments

Yuya Nishihara - Feb. 22, 2018, 2:54 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1516797703 -32400
#      Wed Jan 24 21:41:43 2018 +0900
# Node ID e2030eaec92b1ed12577cbe48cd0495d106818a9
# Parent  b8d0761a85c7421071750de23228415306852d69
dispatch: remember command table per extension (PoC DO NOT PUSH)

The next patch will make it possible to look up commands shadowed by user
aliases.

This patch shouldn't be published because namespace[] cannot be updated by
extensions.wrapcommand(). That might be okay, but wouldn't be what we want.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -64,10 +64,12 @@  from . import (
 
 release = lockmod.release
 
+# commands table per extension ('' for built-in commands)
+namespace = {'': {}}
+# active commands table (may be updated by dispatcher and extensions)
 table = {}
-table.update(debugcommandsmod.command._table)
-
-command = registrar.command(table)
+
+command = registrar.command()
 readonly = registrar.command.readonly
 
 # common command options
@@ -5606,4 +5608,11 @@  def loadcmdtable(ui, name, cmdtable):
     if overrides:
         ui.warn(_("extension '%s' overrides commands: %s\n")
                 % (name, " ".join(overrides)))
+    namespace[name] = cmdtable
     table.update(cmdtable)
+
+# load built-in commands
+namespace[''].update(debugcommandsmod.command._table)
+namespace[''].update(command._table)
+table.update(debugcommandsmod.command._table)
+table.update(command._table)