url: Remove the proxy env variables only when needed (issue2451) stable
authorRenato Cunha <renatoc@gmail.com>
Thu, 08 Sep 2011 20:40:24 -0300
branchstable
changeset 15077 02734d2baa79
parent 15075 77325c92db95
child 15081 d30ec2d16c5a
child 15084 deed405e8980
url: Remove the proxy env variables only when needed (issue2451) This is an attempt to fix issue 2451 and its duplicates (2599 and 2949, AFAIK). Its main idea is that it is only necessary to clean the proxy environment variables *when* http_proxy is set in the config file (since it takes precedence over the environment variables). Otherwise, hg shouldn't bother with them, since they will most likely be used to reach the server.
mercurial/url.py
--- a/mercurial/url.py	Sat Sep 10 13:23:41 2011 +0100
+++ b/mercurial/url.py	Thu Sep 08 20:40:24 2011 -0300
@@ -93,13 +93,15 @@
             proxies = {}
 
         # urllib2 takes proxy values from the environment and those
-        # will take precedence if found, so drop them
-        for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]:
-            try:
-                if env in os.environ:
-                    del os.environ[env]
-            except OSError:
-                pass
+        # will take precedence if found. So, if there's a config entry
+        # defining a proxy, drop the environment ones
+        if ui.config("http_proxy", "host"):
+            for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]:
+                try:
+                    if env in os.environ:
+                        del os.environ[env]
+                except OSError:
+                    pass
 
         urllib2.ProxyHandler.__init__(self, proxies)
         self.ui = ui