[PATCH 1 of 2] cmdutil: break import cycle

Gregory Szorc gregory.szorc at gmail.com
Sat Aug 8 23:32:15 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1439020039 25200
#      Sat Aug 08 00:47:19 2015 -0700
# Node ID 9c8e6fd8ca8285cb629e4a9ebd9cfe50b6537472
# Parent  1903e8255b5ba7fda2e702ca522d8196559f8a65
cmdutil: break import cycle

This was the easiest place to break the chain, as there were only
2 uses of the imported module in the file.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -9,9 +9,9 @@ from node import hex, bin, nullid, nullr
 from i18n import _
 import os, sys, errno, re, tempfile, cStringIO, shutil
 import util, scmutil, templater, patch, error, templatekw, revlog, copies
 import match as matchmod
-import context, repair, graphmod, revset, phases, obsolete, pathutil
+import repair, graphmod, revset, phases, obsolete, pathutil
 import changelog
 import bookmarks
 import encoding
 import formatter
@@ -847,8 +847,10 @@ def tryimportone(ui, repo, hunk, parents
            (used in case we need to save it when failing)
     :updatefunc: a function that update a repo to a given node
                  updatefunc(<repo>, <node>)
     """
+    # avoid cycle context -> subrepo -> cmdutil
+    import context
     tmpname, message, user, date, branch, nodeid, p1, p2 = \
         patch.extract(ui, hunk)
 
     update = not opts.get('bypass')
@@ -2463,8 +2465,11 @@ def commit(ui, repo, commitfunc, pats, o
 
     return commitfunc(ui, repo, message, matcher, opts)
 
 def amend(ui, repo, commitfunc, old, extra, pats, opts):
+    # avoid cycle context -> subrepo -> cmdutil
+    import context
+
     # amend will reuse the existing user if not specified, but the obsolete
     # marker creation requires that the current user's name is specified.
     if obsolete.isenabled(repo, obsolete.createmarkersopt):
         ui.username() # raise exception if username not set
diff --git a/tests/test-module-imports.t b/tests/test-module-imports.t
--- a/tests/test-module-imports.t
+++ b/tests/test-module-imports.t
@@ -126,8 +126,7 @@ these may expose other cycles.
      relative:  config, error, templatefilters, templatekw, util
   mercurial/ui.py mixed imports
      stdlib:    formatter
      relative:  config, error, progress, scmutil, util
-  Import cycle: mercurial.cmdutil -> mercurial.context -> mercurial.subrepo -> mercurial.cmdutil
   Import cycle: hgext.largefiles.basestore -> hgext.largefiles.localstore -> hgext.largefiles.basestore
   Import cycle: mercurial.commands -> mercurial.commandserver -> mercurial.dispatch -> mercurial.commands
   [1]


More information about the Mercurial-devel mailing list