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

login
register
mail settings
Submitter phabricator
Date April 11, 2018, 1:29 a.m.
Message ID <differential-rev-PHID-DREV-muxt7i3mypvlhjzrb54u-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/30668/
State Superseded
Headers show

Comments

phabricator - April 11, 2018, 1:29 a.m.
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




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

Patch

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: