Patchwork D8448: rust-chg: modernize entry function

login
register
mail settings
Submitter phabricator
Date April 16, 2020, 12:31 p.m.
Message ID <differential-rev-PHID-DREV-46ql3pwnpq7n3tl7fr5b-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46153/
State Superseded
Headers show

Comments

phabricator - April 16, 2020, 12:31 p.m.
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
phabricator - April 16, 2020, 4:29 p.m.
durin42 added inline comments.

INLINE COMMENTS

> main.rs:70
> +#[tokio::main]
> +async fn run(umask: u32) -> io::Result<i32> {
>      let mut loc = Locator::prepare_from_env()?;

With this series I get lots of

`+  error[E0670]: `async fn` is not permitted in the 2015 edition`

from `test-check-rust-format.t`. Am I doing something wrong?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8448/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8448

To: yuja, #hg-reviewers
Cc: durin42, mercurial-devel
Yuya Nishihara - April 17, 2020, 10:41 a.m.
> `+  error[E0670]: `async fn` is not permitted in the 2015 edition`

Appears that we need to specify `--edition=2018`. Sent patch.
phabricator - April 17, 2020, 10:48 a.m.
yuja added a comment.


  > `+  error[E0670]: `async fn` is not permitted in the 2015 edition`
  
  Appears that we need to specify `--edition=2018`. Sent patch.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8448/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8448

To: yuja, #hg-reviewers
Cc: durin42, mercurial-devel
phabricator - April 22, 2020, 4:15 p.m.
Herald added a subscriber: mercurial-patches.
marmoute added a comment.


  In D8448#126114 <https://phab.mercurial-scm.org/D8448#126114>, @yuja wrote:
  
  >> `+  error[E0670]: `async fn` is not permitted in the 2015 edition`
  >
  > Appears that we need to specify `--edition=2018`. Sent patch.
  
  Patch was sent, the series looks ready to land.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8448/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8448

To: yuja, #hg-reviewers, Alphare
Cc: marmoute, mercurial-patches, durin42, mercurial-devel

Patch

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<i32> {
+#[tokio::main]
+async fn run(umask: u32) -> io::Result<i32> {
     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"