[PATCH 2 of 2] commandserver: cut import cycle by itself

Yuya Nishihara yuya at tcha.org
Sun Dec 13 08:49:03 CST 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1448373834 -32400
#      Tue Nov 24 23:03:54 2015 +0900
# Node ID 374b960b42acf96be105d8eb429fd041a30929c7
# Parent  d5bbc726e292099326891eedd2e5d1c309d84b8f
commandserver: cut import cycle by itself

We generally make modules importable from the front-end layer, dispatch ->
commands -> x. So the import cycle to dispatch should be resolved by the
commandserver module.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -23,6 +23,7 @@ import setdiscovery, treediscovery, dagu
 import phases, obsolete, exchange, bundle2, repair, lock as lockmod
 import ui as uimod
 import streamclone
+import commandserver
 
 table = {}
 
@@ -6185,7 +6186,6 @@ def serve(ui, repo, **opts):
         s.serve_forever()
 
     if opts["cmdserver"]:
-        import commandserver
         service = commandserver.createservice(ui, repo, opts)
     else:
         service = hgweb.createservice(ui, repo, opts)
diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -16,7 +16,6 @@ import traceback
 
 from .i18n import _
 from . import (
-    dispatch,
     encoding,
     error,
     util,
@@ -186,6 +185,7 @@ class server(object):
     def runcommand(self):
         """ reads a list of \0 terminated arguments, executes
         and writes the return code to the result channel """
+        from . import dispatch  # avoid cycle
 
         length = struct.unpack('>I', self._read(4))[0]
         if not length:


More information about the Mercurial-devel mailing list