##// END OF EJS Templates
rust-chg: modernize entry function...
Yuya Nishihara -
r45238:9fc9526e default
parent child Browse files
Show More
@@ -6,9 +6,6 b' description = "Client for Mercurial comm'
6 license = "GPL-2.0+"
6 license = "GPL-2.0+"
7 edition = "2018"
7 edition = "2018"
8
8
9 # TODO: enable auto discovery
10 autobins = false
11
12 [dependencies]
9 [dependencies]
13 async-trait = "0.1"
10 async-trait = "0.1"
14 bytes = "0.5"
11 bytes = "0.5"
@@ -5,13 +5,12 b''
5
5
6 use chg::locator::{self, Locator};
6 use chg::locator::{self, Locator};
7 use chg::procutil;
7 use chg::procutil;
8 use chg::{ChgClientExt, ChgUiHandler};
8 use chg::ChgUiHandler;
9 use futures::sync::oneshot;
10 use std::env;
9 use std::env;
11 use std::io;
10 use std::io;
11 use std::io::Write;
12 use std::process;
12 use std::process;
13 use std::time::Instant;
13 use std::time::Instant;
14 use tokio::prelude::*;
15
14
16 struct DebugLogger {
15 struct DebugLogger {
17 start: Instant,
16 start: Instant,
@@ -67,31 +66,22 b' fn main() {'
67 process::exit(code);
66 process::exit(code);
68 }
67 }
69
68
70 fn run(umask: u32) -> io::Result<i32> {
69 #[tokio::main]
70 async fn run(umask: u32) -> io::Result<i32> {
71 let mut loc = Locator::prepare_from_env()?;
71 let mut loc = Locator::prepare_from_env()?;
72 loc.set_early_args(locator::collect_early_args(env::args_os().skip(1)));
72 loc.set_early_args(locator::collect_early_args(env::args_os().skip(1)));
73 let handler = ChgUiHandler::new();
73 let mut handler = ChgUiHandler::new();
74 let (result_tx, result_rx) = oneshot::channel();
74 let mut client = loc.connect().await?;
75 let fut = loc
75 client
76 .connect()
76 .attach_io(&io::stdin(), &io::stdout(), &io::stderr())
77 .and_then(|(_, client)| client.attach_io(io::stdin(), io::stdout(), io::stderr()))
77 .await?;
78 .and_then(move |client| client.set_umask(umask))
78 client.set_umask(umask).await?;
79 .and_then(|client| {
79 let pid = client.server_spec().process_id.unwrap();
80 let pid = client.server_spec().process_id.unwrap();
80 let pgid = client.server_spec().process_group_id;
81 let pgid = client.server_spec().process_group_id;
81 procutil::setup_signal_handler_once(pid, pgid)?;
82 procutil::setup_signal_handler_once(pid, pgid)?;
82 let code = client
83 Ok(client)
83 .run_command_chg(&mut handler, env::args_os().skip(1))
84 })
84 .await?;
85 .and_then(|client| client.run_command_chg(handler, env::args_os().skip(1)))
85 procutil::restore_signal_handler_once()?;
86 .map(|(_client, _handler, code)| {
86 Ok(code)
87 procutil::restore_signal_handler_once()?;
88 Ok(code)
89 })
90 .or_else(|err| Ok(Err(err))) // pass back error to caller
91 .map(|res| result_tx.send(res).unwrap());
92 tokio::run(fut);
93 result_rx.wait().unwrap_or(Err(io::Error::new(
94 io::ErrorKind::Other,
95 "no exit code set",
96 )))
97 }
87 }
General Comments 0
You need to be logged in to leave comments. Login now