Mercurial > public > mercurial-scm > hg-stable
diff rust/chg/src/main.rs @ 44672:bb936e25a84a
rust-chg: spawn server process if not running
This is the minimal reimplementation of gethgcmd(), execcmdserver(),
retryconnectcmdserver(), and connectcmdserver() in chg.c.
No config validation is implemented yet. And some Py3 workarounds would
be missing as this is the code I wrote in 2018.
Differential Revision: https://phab.mercurial-scm.org/D8360
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 06 Oct 2018 20:10:44 +0900 |
parents | ce088b38f92b |
children | 0a2516efc463 |
line wrap: on
line diff
--- a/rust/chg/src/main.rs Tue Mar 31 23:13:13 2020 +0900 +++ b/rust/chg/src/main.rs Sat Oct 06 20:10:44 2018 +0900 @@ -9,7 +9,7 @@ extern crate tokio; extern crate tokio_hglib; -use chg::locator; +use chg::locator::Locator; use chg::procutil; use chg::{ChgClientExt, ChgUiHandler}; use futures::sync::oneshot; @@ -18,7 +18,6 @@ use std::process; use std::time::Instant; use tokio::prelude::*; -use tokio_hglib::UnixClient; struct DebugLogger { start: Instant, @@ -64,6 +63,8 @@ log::set_max_level(log::LevelFilter::Debug); } + // TODO: add loop detection by $CHGINTERNALMARK + let code = run().unwrap_or_else(|err| { writeln!(io::stderr(), "chg: abort: {}", err).unwrap_or(()); 255 @@ -73,11 +74,12 @@ fn run() -> io::Result<i32> { let current_dir = env::current_dir()?; - let sock_path = locator::prepare_server_socket_path()?; + let loc = Locator::prepare_from_env()?; let handler = ChgUiHandler::new(); let (result_tx, result_rx) = oneshot::channel(); - let fut = UnixClient::connect(sock_path) - .and_then(|client| client.set_current_dir(current_dir)) + let fut = loc + .connect() + .and_then(|(_, client)| client.set_current_dir(current_dir)) .and_then(|client| client.attach_io(io::stdin(), io::stdout(), io::stderr())) .and_then(|client| { let pid = client.server_spec().process_id.unwrap();