Patchwork [7,of,8,chgtocore] chgserver: delay importing commands and dispatch modules

login
register
mail settings
Submitter Yuya Nishihara
Date Nov. 22, 2016, 4 p.m.
Message ID <c0640366366cf076e264.1479830400@mimosa>
Download mbox | patch
Permalink /patch/17706/
State Accepted
Headers show

Comments

Yuya Nishihara - Nov. 22, 2016, 4 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1476509838 -32400
#      Sat Oct 15 14:37:18 2016 +0900
# Node ID c0640366366cf076e2641ae53948be0770154611
# Parent  75a0cf247a94e7ca67e9280f6335ce95c8d6a5ad
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.

Patch

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -54,9 +54,7 @@  from mercurial.i18n import _
 
 from mercurial import (
     cmdutil,
-    commands,
     commandserver,
-    dispatch,
     error,
     extensions,
     osutil,
@@ -181,6 +179,8 @@  class hashstate(object):
 
 # 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 @@  def _newchgui(srcui, csystem):
     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 @@  class chgcmdserver(commandserver.server)
         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 @@  class chgcmdserver(commandserver.server)
         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,