chgserver: delay importing commands and dispatch modules
authorYuya Nishihara <yuya@tcha.org>
Sat, 15 Oct 2016 14:37:18 +0900
changeset 30512 cc374292a561
parent 30511 1873563e1ede
child 30513 ff7df4bb75de
chgserver: delay importing commands and dispatch modules This is a workaround for future import cycle: dispatch -> commands -> server -> chgserver -> commands. Some of the problems can be fixed later on pager and chg refactoring.
hgext/chgserver.py
--- a/hgext/chgserver.py	Sat Oct 15 14:24:29 2016 +0900
+++ b/hgext/chgserver.py	Sat Oct 15 14:37:18 2016 +0900
@@ -54,9 +54,7 @@
 
 from mercurial import (
     cmdutil,
-    commands,
     commandserver,
-    dispatch,
     error,
     extensions,
     osutil,
@@ -181,6 +179,8 @@
 
 # copied from hgext/pager.py:uisetup()
 def _setuppagercmd(ui, options, cmd):
+    from mercurial import commands  # avoid cycle
+
     if not ui.formatted():
         return
 
@@ -260,6 +260,8 @@
     return chgui(srcui)
 
 def _loadnewui(srcui, args):
+    from mercurial import dispatch  # avoid cycle
+
     newui = srcui.__class__()
     for a in ['fin', 'fout', 'ferr', 'environ']:
         setattr(newui, a, getattr(srcui, a))
@@ -439,6 +441,8 @@
         list, the client can continue with this server after completing all
         the instructions.
         """
+        from mercurial import dispatch  # avoid cycle
+
         args = self._readlist()
         try:
             self.ui, lui = _loadnewui(self.ui, args)
@@ -486,6 +490,8 @@
         If pager isn't enabled, this writes '\0' because channeledoutput
         does not allow to write empty data.
         """
+        from mercurial import dispatch  # avoid cycle
+
         args = self._readlist()
         try:
             cmd, _func, args, options, _cmdoptions = dispatch._parse(self.ui,