##// END OF EJS Templates
copies: compute the exact set of revision to walk...
copies: compute the exact set of revision to walk This change make the code clearer by removing the revision queue. It comes without very noticeable performance impact. However the simpler code will be easier to update in later changesets. revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29 before: ! wall 1.430082 comb 1.430000 user 1.390000 sys 0.040000 (median of 10) after: ! wall 1.405192 comb 1.410000 user 1.390000 sys 0.020000 (median of 10) revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2 before: ! wall 1.971366 comb 1.970000 user 1.950000 sys 0.020000 (median of 10) after: ! wall 1.892541 comb 1.890000 user 1.870000 sys 0.020000 (median of 10) revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0 before: ! wall 0.252594 comb 0.250000 user 0.240000 sys 0.010000 (median of 38) after: ! wall 0.240075 comb 0.240000 user 0.240000 sys 0.000000 (median of 40) revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f before: ! wall 0.013100 comb 0.010000 user 0.010000 sys 0.000000 (median of 226) after: ! wall 0.013247 comb 0.010000 user 0.010000 sys 0.000000 (median of 223) revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63 before: ! wall 0.001633 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) after: ! wall 0.001670 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e before: ! wall 0.000078 comb 0.000000 user 0.000000 sys 0.000000 (median of 11984) after: ! wall 0.000119 comb 0.000000 user 0.000000 sys 0.000000 (median of 7982) revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe before: ! wall 0.207093 comb 0.210000 user 0.210000 sys 0.000000 (median of 47) after: ! wall 0.201551 comb 0.200000 user 0.200000 sys 0.000000 (median of 48) revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d before: ! wall 0.038462 comb 0.040000 user 0.040000 sys 0.000000 (median of 100) after: ! wall 0.036578 comb 0.030000 user 0.030000 sys 0.000000 (median of 100) Differential Revision: https://phab.mercurial-scm.org/D7076

File last commit:

r40324:87c76e5f default
r43593:83bb1e89 default
Show More
main.rs
98 lines | 2.9 KiB | application/rls-services+xml | RustLexer
Yuya Nishihara
rust-chg: add project skeleton...
r40003 // Copyright 2018 Yuya Nishihara <yuya@tcha.org>
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
Yuya Nishihara
rust-chg: add main program...
r40015 extern crate chg;
extern crate futures;
Yuya Nishihara
rust-chg: install logger if $CHGDEBUG is set...
r40324 extern crate log;
Yuya Nishihara
rust-chg: add main program...
r40015 extern crate tokio;
extern crate tokio_hglib;
use chg::{ChgClientExt, ChgUiHandler};
use chg::locator;
Yuya Nishihara
rust-chg: install signal handlers to forward signals to server...
r40156 use chg::procutil;
Yuya Nishihara
rust-chg: add main program...
r40015 use futures::sync::oneshot;
use std::env;
use std::io;
use std::process;
Yuya Nishihara
rust-chg: install logger if $CHGDEBUG is set...
r40324 use std::time::Instant;
Yuya Nishihara
rust-chg: add main program...
r40015 use tokio::prelude::*;
use tokio_hglib::UnixClient;
Yuya Nishihara
rust-chg: install logger if $CHGDEBUG is set...
r40324 struct DebugLogger {
start: Instant,
}
impl DebugLogger {
pub fn new() -> DebugLogger {
DebugLogger {
start: Instant::now(),
}
}
}
impl log::Log for DebugLogger {
fn enabled(&self, metadata: &log::Metadata) -> bool {
metadata.target().starts_with("chg::")
}
fn log(&self, record: &log::Record) {
if self.enabled(record.metadata()) {
// just make the output looks similar to chg of C
let l = format!("{}", record.level()).to_lowercase();
let t = self.start.elapsed();
writeln!(io::stderr(), "chg: {}: {}.{:06} {}",
l, t.as_secs(), t.subsec_micros(), record.args()).unwrap_or(());
}
}
fn flush(&self) {
}
}
Yuya Nishihara
rust-chg: add project skeleton...
r40003 fn main() {
Yuya Nishihara
rust-chg: install logger if $CHGDEBUG is set...
r40324 if env::var_os("CHGDEBUG").is_some() {
log::set_boxed_logger(Box::new(DebugLogger::new()))
.expect("any logger should not be installed yet");
log::set_max_level(log::LevelFilter::Debug);
}
Yuya Nishihara
rust-chg: add main program...
r40015 let code = run().unwrap_or_else(|err| {
Yuya Nishihara
rust-chg: suppress panic while writing chg error to stderr...
r40322 writeln!(io::stderr(), "chg: abort: {}", err).unwrap_or(());
Yuya Nishihara
rust-chg: add main program...
r40015 255
});
process::exit(code);
Yuya Nishihara
rust-chg: add project skeleton...
r40003 }
Yuya Nishihara
rust-chg: add main program...
r40015
fn run() -> io::Result<i32> {
let current_dir = env::current_dir()?;
let sock_path = locator::prepare_server_socket_path()?;
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)
})
.and_then(|client| {
client.attach_io(io::stdin(), io::stdout(), io::stderr())
})
.and_then(|client| {
Yuya Nishihara
rust-chg: install signal handlers to forward signals to server...
r40156 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| {
Yuya Nishihara
rust-chg: add main program...
r40015 client.run_command_chg(handler, env::args_os().skip(1))
})
.map(|(_client, _handler, code)| {
Yuya Nishihara
rust-chg: install signal handlers to forward signals to server...
r40156 procutil::restore_signal_handler_once()?;
Yuya Nishihara
rust-chg: add main program...
r40015 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")))
}