From fa95cf8c2143431635351ed4a23ebe809a203ac2 Mon Sep 17 00:00:00 2001 From: Arun Kulshreshtha Date: Mon, 28 Oct 2019 11:11:11 -0700 Subject: [PATCH] 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 --- edenscm/hgext/remotefilelog/__init__.py | 5 ----- edenscm/hgext/remotefilelog/debugcommands.py | 10 ---------- lib/hgcommands/Cargo.toml | 1 + lib/hgcommands/src/commands.rs | 16 ++++++++++++++++ tests/test-completion.t | 2 ++ tests/test-help.t | 1 + 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/edenscm/hgext/remotefilelog/__init__.py b/edenscm/hgext/remotefilelog/__init__.py index 4a753122ff..0f02801d7f 100644 --- a/edenscm/hgext/remotefilelog/__init__.py +++ b/edenscm/hgext/remotefilelog/__init__.py @@ -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 diff --git a/edenscm/hgext/remotefilelog/debugcommands.py b/edenscm/hgext/remotefilelog/debugcommands.py index f4e6cbc9c2..f5fb159c7b 100644 --- a/edenscm/hgext/remotefilelog/debugcommands.py +++ b/edenscm/hgext/remotefilelog/debugcommands.py @@ -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) diff --git a/lib/hgcommands/Cargo.toml b/lib/hgcommands/Cargo.toml index 9b59705fd7..a57f7109f9 100644 --- a/lib/hgcommands/Cargo.toml +++ b/lib/hgcommands/Cargo.toml @@ -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" diff --git a/lib/hgcommands/src/commands.rs b/lib/hgcommands/src/commands.rs index 3ce35a32d9..85af44e09a 100644 --- a/lib/hgcommands/src/commands.rs +++ b/lib/hgcommands/src/commands.rs @@ -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, } + + pub struct DebugHttpOpts {} } pub fn root(opts: RootOpts, io: &mut IO, repo: Repo) -> Fallible { @@ -165,3 +173,11 @@ pub fn debugindexedlogrepair(opts: DebugArgsOpts, io: &mut IO) -> Fallible { } Ok(0) } + +pub fn debughttp(_opts: DebugHttpOpts, io: &mut IO, repo: Repo) -> Fallible { + 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) +} diff --git a/tests/test-completion.t b/tests/test-completion.t index e6b9bf33e9..c942f84e8b 100644 --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -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 diff --git a/tests/test-help.t b/tests/test-help.t index 8f4053a9a6..7cf69aa2d6 100644 --- a/tests/test-help.t +++ b/tests/test-help.t @@ -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