D605: phabricator: add a config to use curl for communication

quark (Jun Wu) phabricator at mercurial-scm.org
Sun Sep 3 10:20:37 EDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG8b659b7388c0: phabricator: add a config to use curl for communication (authored by quark).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D605?vs=1568&id=1590

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

AFFECTED FILES
  contrib/phabricator.py

CHANGE DETAILS

diff --git a/contrib/phabricator.py b/contrib/phabricator.py
--- a/contrib/phabricator.py
+++ b/contrib/phabricator.py
@@ -28,6 +28,11 @@
     # callsign is "FOO".
     callsign = FOO
 
+    # curl command to use. If not set (default), use builtin HTTP library to
+    # communicate. If set, use the specified curl command. This could be useful
+    # if you need to specify advanced options that is not easily supported by
+    # the internal library.
+    curlcmd = curl --connect-timeout 2 --retry 3 --silent
 """
 
 from __future__ import absolute_import
@@ -108,12 +113,20 @@
     """call Conduit API, params is a dict. return json.loads result, or None"""
     host, token = readurltoken(repo)
     url, authinfo = util.url('/'.join([host, 'api', name])).authinfo()
-    urlopener = urlmod.opener(repo.ui, authinfo)
     repo.ui.debug('Conduit Call: %s %s\n' % (url, params))
     params = params.copy()
     params['api.token'] = token
-    request = util.urlreq.request(url, data=urlencodenested(params))
-    body = urlopener.open(request).read()
+    data = urlencodenested(params)
+    curlcmd = repo.ui.config('phabricator', 'curlcmd')
+    if curlcmd:
+        sin, sout = util.popen2('%s -d @- %s' % (curlcmd, util.shellquote(url)))
+        sin.write(data)
+        sin.close()
+        body = sout.read()
+    else:
+        urlopener = urlmod.opener(repo.ui, authinfo)
+        request = util.urlreq.request(url, data=data)
+        body = urlopener.open(request).read()
     repo.ui.debug('Conduit Response: %s\n' % body)
     parsed = json.loads(body)
     if parsed.get(r'error_code'):



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


More information about the Mercurial-devel mailing list