mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
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:
parent
b5d29d31b4
commit
b549fab666
@ -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)
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user