From patchwork Thu Apr 16 12:31:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D8448: rust-chg: modernize entry function From: phabricator X-Patchwork-Id: 46153 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Thu, 16 Apr 2020 12:31:04 +0000 yuja created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY Finally the entire build passes. There's a bug that run() no longer waits for the spawned pager, which will be fixed by the next patch. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D8448 AFFECTED FILES rust/chg/Cargo.toml rust/chg/src/main.rs CHANGE DETAILS To: yuja, #hg-reviewers Cc: mercurial-devel diff --git a/rust/chg/src/main.rs b/rust/chg/src/main.rs --- a/rust/chg/src/main.rs +++ b/rust/chg/src/main.rs @@ -5,13 +5,12 @@ use chg::locator::{self, Locator}; use chg::procutil; -use chg::{ChgClientExt, ChgUiHandler}; -use futures::sync::oneshot; +use chg::ChgUiHandler; use std::env; use std::io; +use std::io::Write; use std::process; use std::time::Instant; -use tokio::prelude::*; struct DebugLogger { start: Instant, @@ -67,31 +66,22 @@ process::exit(code); } -fn run(umask: u32) -> io::Result { +#[tokio::main] +async fn run(umask: u32) -> io::Result { let mut loc = Locator::prepare_from_env()?; loc.set_early_args(locator::collect_early_args(env::args_os().skip(1))); - let handler = ChgUiHandler::new(); - let (result_tx, result_rx) = oneshot::channel(); - let fut = loc - .connect() - .and_then(|(_, client)| client.attach_io(io::stdin(), io::stdout(), io::stderr())) - .and_then(move |client| client.set_umask(umask)) - .and_then(|client| { - let pid = client.server_spec().process_id.unwrap(); - let pgid = client.server_spec().process_group_id; - procutil::setup_signal_handler_once(pid, pgid)?; - Ok(client) - }) - .and_then(|client| client.run_command_chg(handler, env::args_os().skip(1))) - .map(|(_client, _handler, code)| { - procutil::restore_signal_handler_once()?; - Ok(code) - }) - .or_else(|err| Ok(Err(err))) // pass back error to caller - .map(|res| result_tx.send(res).unwrap()); - tokio::run(fut); - result_rx.wait().unwrap_or(Err(io::Error::new( - io::ErrorKind::Other, - "no exit code set", - ))) + let mut handler = ChgUiHandler::new(); + let mut client = loc.connect().await?; + client + .attach_io(&io::stdin(), &io::stdout(), &io::stderr()) + .await?; + client.set_umask(umask).await?; + let pid = client.server_spec().process_id.unwrap(); + let pgid = client.server_spec().process_group_id; + procutil::setup_signal_handler_once(pid, pgid)?; + let code = client + .run_command_chg(&mut handler, env::args_os().skip(1)) + .await?; + procutil::restore_signal_handler_once()?; + Ok(code) } diff --git a/rust/chg/Cargo.toml b/rust/chg/Cargo.toml --- a/rust/chg/Cargo.toml +++ b/rust/chg/Cargo.toml @@ -6,9 +6,6 @@ license = "GPL-2.0+" edition = "2018" -# TODO: enable auto discovery -autobins = false - [dependencies] async-trait = "0.1" bytes = "0.5"