D3238: httppeer: allow opener to be passed to makepeer()

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Wed Apr 11 01:29:19 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This allows us to use makepeer() in `hg debugwireproto`.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3238

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/httppeer.py

CHANGE DETAILS

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -620,9 +620,12 @@
 
     return respurl, set(rawcaps.split())
 
-def makepeer(ui, path, requestbuilder=urlreq.request):
+def makepeer(ui, path, opener=None, requestbuilder=urlreq.request):
     """Construct an appropriate HTTP peer instance.
 
+    ``opener`` is an ``url.opener`` that should be used to establish
+    connections, perform HTTP requests.
+
     ``requestbuilder`` is the type used for constructing HTTP requests.
     It exists as an argument so extensions can override the default.
     """
@@ -635,7 +638,7 @@
     url, authinfo = u.authinfo()
     ui.debug('using %s\n' % url)
 
-    opener = urlmod.opener(ui, authinfo)
+    opener = opener or urlmod.opener(ui, authinfo)
 
     respurl, caps = performhandshake(ui, url, opener, requestbuilder)
 
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2915,12 +2915,7 @@
             raise error.Abort(_('--peer %s not supported with HTTP peers') %
                               opts['peer'])
         else:
-            url, caps = httppeer.performhandshake(ui, url, opener,
-                                                  httppeer.urlreq.request)
-
-            peer = httppeer.httppeer(ui, path, url, opener,
-                                     httppeer.urlreq.request,
-                                     caps)
+            peer = httppeer.makepeer(ui, path, opener=opener)
 
         # We /could/ populate stdin/stdout with sock.makefile()...
     else:



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list