remotefilelog: properly check whether Eden API is enabled

Summary: Previously the debug commands for the Eden API did not check whether HTTP data fetching was enabled before trying to access the client singleton, which would result in a crash if HTTP was disabled. This diff adds explicit checks so that the commands will abort instead of crashing.

Reviewed By: quark-zju

Differential Revision: D14692893

fbshipit-source-id: d36e241d8460dadb555a15c92aca9334ba00f34c
This commit is contained in:
Arun Kulshreshtha 2019-03-29 18:44:09 -07:00 committed by Facebook Github Bot
parent b5d29d31b4
commit b549fab666
3 changed files with 15 additions and 1 deletions

View File

@ -423,7 +423,7 @@ def setupclient(ui, repo):
shallowrepo.wraprepo(repo)
repo.store = shallowstore.wrapstore(repo.store)
if ui.configbool("edenapi", "enabled"):
if edenapi.enabled(ui):
repo.edenapi = edenapi.initclient(ui, repo)

View File

@ -496,6 +496,7 @@ def debugwaitonprefetch(repo):
def debughttp(ui, repo, **opts):
"""Perform a health check of the API server."""
edenapi.bailifdisabled(ui)
try:
repo.edenapi.health_check()
ui.write(_("successfully connected to: %s\n") % edenapi.getbaseurl(ui))
@ -504,6 +505,7 @@ def debughttp(ui, repo, **opts):
def debuggetfiles(ui, repo, **opts):
edenapi.bailifdisabled(ui)
input = (line.split() for line in sys.stdin.readlines())
keys = [(path, node) for node, path in input]
packpath = repo.edenapi.get_files(keys)
@ -511,6 +513,7 @@ def debuggetfiles(ui, repo, **opts):
def debuggethistory(ui, repo, **opts):
edenapi.bailifdisabled(ui)
input = (line.split() for line in sys.stdin.readlines())
keys = [(path, node) for node, path in input]
depth = opts.get("depth") or None

View File

@ -12,6 +12,17 @@ from edenscm.mercurial.rust.bindings import edenapi
from . import shallowutil
def enabled(ui):
"""Check whether HTTP data fetching is enabled."""
return ui.configbool("edenapi", "enabled")
def bailifdisabled(ui):
"""Abort if HTTP data fetching is disabled."""
if not enabled(ui):
raise error.Abort(_("HTTP data fetching is disabled"))
def getbaseurl(ui):
"""Get the base URL of the API server."""
url = ui.config("edenapi", "url")