hgcommands: rewrite hg debughttp in Rust

Summary: As an example of using EdenAPI in a pure-Rust context, reimplement `hg debughttp` in Rust.

Reviewed By: quark-zju

Differential Revision: D18156042

fbshipit-source-id: 19a4ad10d276b413f87fd41e569e271e3e243449
This commit is contained in:
Arun Kulshreshtha 2019-10-28 11:11:11 -07:00 committed by Facebook Github Bot
parent 903b86bce5
commit fa95cf8c21
6 changed files with 20 additions and 15 deletions

View File

@ -1186,11 +1186,6 @@ def debugwaitonprefetch(ui, repo, **opts):
return debugcommands.debugwaitonprefetch(repo)
@command("debughttp", [], _("hg debughttp"))
def debughttp(ui, repo, **opts):
return debugcommands.debughttp(ui, repo, **opts)
@command("debuggetfiles|debuggetfile", [], _("hg debuggetfiles"))
def debuggetfiles(ui, repo, **opts):
"""download file content from the API server

View File

@ -514,16 +514,6 @@ def debugwaitonprefetch(repo):
pass
def debughttp(ui, repo, **opts):
"""Query the hostname of the API server."""
edenapi.bailifdisabled(ui)
try:
hostname = repo.edenapi.hostname()
ui.write(_("successfully connected to: %s\n") % hostname)
except RuntimeError as e:
raise error.Abort(e)
def debuggetfiles(ui, repo, **opts):
edenapi.bailifdisabled(ui)

View File

@ -9,6 +9,7 @@ blackbox = { path = "../blackbox" }
clidispatch = { path = "../clidispatch" }
cliparser = { path = "../cliparser", features = ["python"] }
cpython-ext = { path = "../cpython-ext" }
edenapi = { path = "../edenapi" }
failure = "0.1"
indexedlog = { path = "../indexedlog" }
libc = "0.2"

View File

@ -9,6 +9,7 @@ use clidispatch::{
};
use cliparser::define_flags;
use edenapi::{Config as EdenApiConfig, EdenApi, EdenApiCurlClient};
use revisionstore::{
CorruptionPolicy, DataPackStore, DataStore, IndexedLogDataStore, UnionDataStore,
};
@ -45,6 +46,11 @@ pub fn table() -> CommandTable {
"debugindexedlog-repair",
"repair indexedlog log",
);
table.register(
debughttp,
"debughttp",
"check whether api server is reachable",
);
table
}
@ -75,6 +81,8 @@ define_flags! {
#[args]
args: Vec<String>,
}
pub struct DebugHttpOpts {}
}
pub fn root(opts: RootOpts, io: &mut IO, repo: Repo) -> Fallible<u8> {
@ -165,3 +173,11 @@ pub fn debugindexedlogrepair(opts: DebugArgsOpts, io: &mut IO) -> Fallible<u8> {
}
Ok(0)
}
pub fn debughttp(_opts: DebugHttpOpts, io: &mut IO, repo: Repo) -> Fallible<u8> {
let config = EdenApiConfig::from_hg_config(repo.config())?;
let client = EdenApiCurlClient::new(config)?;
let hostname = client.hostname()?;
io.write(format!("successfully connected to: {}\n", hostname))?;
Ok(0)
}

View File

@ -111,6 +111,7 @@ Show debug commands if there are no other candidates
debugformat
debugfsinfo
debuggetbundle
debughttp
debugignore
debugindex
debugindexdot
@ -304,6 +305,7 @@ Show all commands + options
debugformat: template
debugfsinfo:
debuggetbundle: head, common, type
debughttp:
debugignore:
debugindex: changelog, manifest, dir, format
debugindexdot: changelog, manifest, dir

View File

@ -986,6 +986,7 @@ Test list of internal help commands
(no help text available)
debuggetbundle
retrieves a bundle from a repo
debughttp check whether api server is reachable
debugignore display the combined ignore pattern and information about
ignored files
debugindex dump the contents of an index file