Patchwork [1,of,3] revset: don't import discovery at module level

login
register
mail settings
Submitter Gregory Szorc
Date April 14, 2015, 6:19 p.m.
Message ID <3e3ba5bfa939902f9942.1429035584@gps-mbp.local>
Download mbox | patch
Permalink /patch/8655/
State Accepted
Headers show

Comments

Gregory Szorc - April 14, 2015, 6:19 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1429030456 14400
#      Tue Apr 14 12:54:16 2015 -0400
# Node ID 3e3ba5bfa939902f994227b3bcb321b5b251a398
# Parent  1791cb41a8e21b61c5f3ee76129d5070a5d573ac
revset: don't import discovery at module level

discovery.py imports a lot of the world. Pierre-Yves told me to move it
to a function-level import to avoid an import cycle in a future patch.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -5,9 +5,9 @@ 
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
 import re
-import parser, util, error, discovery, hbisect, phases
+import parser, util, error, hbisect, phases
 import node
 import heapq
 import match as matchmod
 from i18n import _
@@ -1370,9 +1370,11 @@  def outgoing(repo, subset, x):
     """``outgoing([path])``
     Changesets not found in the specified destination repository, or the
     default push location.
     """
-    import hg # avoid start-up nasties
+    # Avoid cycles.
+    import discovery
+    import hg
     # i18n: "outgoing" is a keyword
     l = getargs(x, 0, 1, _("outgoing takes one or no arguments"))
     # i18n: "outgoing" is a keyword
     dest = l and getstring(l[0], _("outgoing requires a repository path")) or ''
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
@@ -31,9 +31,9 @@  these may expose other cycles.
      stdlib:    parser
      relative:  error, merge, util
   mercurial/revset.py mixed imports
      stdlib:    parser
-     relative:  discovery, error, hbisect, phases, util
+     relative:  error, hbisect, phases, util
   mercurial/templater.py mixed imports
      stdlib:    parser
      relative:  config, error, templatefilters, templatekw, util
   mercurial/ui.py mixed imports