remove dead code from fbconduit hg extension

Summary:
Since it's not calling conduit anymore we can remove all conduit related
functions.

Reviewed By: quark-zju

Differential Revision: D18733121

fbshipit-source-id: 20a6022d9ac7ae6e9afea2791a8daac57cefb22c
This commit is contained in:
Mateusz Kwapich 2019-12-03 05:54:17 -08:00 committed by Facebook Github Bot
parent fa8571f49a
commit 7a0665c9fc
5 changed files with 11 additions and 118 deletions

View File

@ -28,6 +28,10 @@ class ClientError(Exception):
self.code = code
class GraphQLConfigError(Exception):
pass
class Client(object):
def __init__(self, repodir=None, ca_bundle=None, repo=None):
if repo is not None:
@ -59,6 +63,11 @@ class Client(object):
app_id = repo.ui.config("phabricator", "graphql_app_id")
app_token = repo.ui.config("phabricator", "graphql_app_token")
self._host = repo.ui.config("phabricator", "graphql_host")
if app_id is None or app_token is None or self._host is None:
raise GraphQLConfigError(
"GraphQL unavailable because of missing configuration"
)
self._client = phabricator_graphql_client.PhabricatorGraphQLClient(
phabricator_graphql_client_urllib.PhabricatorGraphQLClientRequests(),
self._cert,

View File

@ -29,33 +29,16 @@ from .extlib.phabricator import arcconfig, graphql
namespacepredicate = registrar.namespacepredicate()
conduit_host = None
conduit_path = None
conduit_protocol = None
connection = None
DEFAULT_TIMEOUT = 60
MAX_CONNECT_RETRIES = 3
class ConduitError(Exception):
pass
class HttpError(Exception):
pass
githashre = re.compile("g([0-9a-f]{40})")
svnrevre = re.compile("^r[A-Z]+(\d+)$")
phabhashre = re.compile("^r([A-Z]+)([0-9a-f]{12,40})$")
def uisetup(ui):
if not conduit_config(ui):
ui.warn(_("No conduit host specified in config; disabling fbconduit\n"))
return
def _globalrevswrapper(loaded):
if loaded:
globalrevsmod = extensions.find("globalrevs")
@ -70,68 +53,6 @@ def uisetup(ui):
gitnode._weight = 10
def conduit_config(ui, host=None, path=None, protocol=None):
global conduit_host, conduit_path, conduit_protocol
conduit_host = host or ui.config("fbconduit", "host")
conduit_path = path or ui.config("fbconduit", "path")
conduit_protocol = protocol or ui.config("fbconduit", "protocol")
if conduit_host is None:
return False
if conduit_protocol is None:
conduit_protocol = "https"
return True
def call_conduit(method, timeout=DEFAULT_TIMEOUT, **kwargs):
global connection, conduit_host, conduit_path, conduit_protocol
# start connection
# TODO: move to python-requests
if connection is None:
if conduit_protocol == "https":
connection = httplib.HTTPSConnection(conduit_host, timeout=timeout)
elif conduit_protocol == "http":
connection = httplib.HTTPConnection(conduit_host, timeout=timeout)
# send request
path = conduit_path + method
args = urlencode({"params": json.dumps(kwargs)})
headers = {
"Connection": "Keep-Alive",
"Content-Type": "application/x-www-form-urlencoded",
}
e = None
for attempt in range(MAX_CONNECT_RETRIES):
try:
connection.request("POST", path, args, headers)
break
except httplib.HTTPException:
connection.connect()
if e:
raise e
# read http response
response = connection.getresponse()
if response.status != 200:
raise HttpError(response.reason)
result = response.read()
# strip jsonp header and parse
assert result.startswith("for(;;);")
result = json.loads(result[8:])
# check for conduit errors
if result["error_code"]:
raise ConduitError(result["error_info"])
# return RPC result
return result["result"]
# don't close the connection b/c we want to avoid the connection overhead
@templater.templatefunc("mirrornode")
def mirrornode(ctx, mapping, args):
"""template: find this commit in other repositories"""

View File

@ -31,27 +31,6 @@ conduit = None
FASTLOG_TIMEOUT_IN_SECS = 0.5
def createconduit(ui):
try:
conduit = extensions.find("fbconduit")
except KeyError:
try:
from edenscm.hgext import fbconduit as conduit
except ImportError:
ui.log("linkrevfixup", _("unable to find fbconduit extension\n"))
return False
if not util.safehasattr(conduit, "conduit_config"):
ui.log("linkrevfixup", _("incompatible conduit module; disabling fastlog\n"))
return False
if not conduit.conduit_config(ui):
ui.log(
"linkrevfixup",
_("no conduit host specified in config; disabling fastlog\n"),
)
return False
return conduit
class remotefilectx(context.filectx):
def __init__(
self,
@ -78,17 +57,6 @@ class remotefilectx(context.filectx):
def size(self):
return self._filelog.size(self._filenode)
@propertycache
def _conduit(self):
global conduit
if conduit is None:
conduit = createconduit(self._repo.ui)
# If createconduit fails, conduit will be set to False. We use this to
# avoid calling createconduit multiple times
if conduit is False:
return None
return conduit
@propertycache
def _changeid(self):
if "_changeid" in self.__dict__:
@ -347,8 +315,6 @@ class remotefilectx(context.filectx):
start = time.time()
reponame = repo.ui.config("fbconduit", "reponame")
logmsg = ""
if self._conduit is None:
return None
try:
srchex = repo[srcrev].hex()
client = graphql.Client(repo=self._repo)

View File

@ -64,8 +64,8 @@ New errors are not allowed. Warnings are strongly discouraged.
Skipping tests/test-hgsql-encoding.t it has no-che?k-code (glob)
Skipping tests/test-hgsql-race-conditions.t it has no-che?k-code (glob)
Skipping tests/test-rustthreading.py it has no-che?k-code (glob)
edenscm/hgext/extlib/phabricator/graphql.py:37: use foobar, not foo_bar naming --> ca_bundle = repo.ui.configpath("web", "cacerts")
edenscm/hgext/extlib/phabricator/graphql.py:418: use foobar, not foo_bar naming --> def scmquery_log(
edenscm/hgext/extlib/phabricator/graphql.py:*: use foobar, not foo_bar naming --> ca_bundle = repo.ui.configpath("web", "cacerts") (glob)
edenscm/hgext/extlib/phabricator/graphql.py:*: use foobar, not foo_bar naming --> def scmquery_log( (glob)
tests/run-tests.py:*: don't use camelcase in identifiers --> self.testsSkipped = 0 (glob)
@commands in debugcommands.py should be in alphabetical order.

View File

@ -55,9 +55,6 @@ New errors are not allowed. Warnings are strongly discouraged.
undocumented: fastlog.enabled (bool)
undocumented: fbconduit.backingrepos (list) [[reponame]]
undocumented: fbconduit.gitcallsigns (list)
undocumented: fbconduit.host (str)
undocumented: fbconduit.path (str)
undocumented: fbconduit.protocol (str)
undocumented: fbconduit.reponame (str)
undocumented: fbhistedit.exec_in_user_shell (str)
undocumented: format.usehgsql (bool)