author | Yuya Nishihara <yuya@tcha.org> |
Thu, 04 Oct 2018 23:07:48 +0900 | |
changeset 44675 | 97e6d435ff7e |
parent 43818 | ce088b38f92b |
child 44680 | 43513444bb88 |
permissions | -rw-r--r-- |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
1 |
// Copyright 2018 Yuya Nishihara <yuya@tcha.org> |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
2 |
// |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
3 |
// This software may be used and distributed according to the terms of the |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
4 |
// GNU General Public License version 2 or any later version. |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
5 |
|
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
6 |
//! cHg extensions to command server client. |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
7 |
|
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
8 |
use std::ffi::OsStr; |
39978
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
9 |
use std::os::unix::ffi::OsStrExt; |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
10 |
use std::os::unix::io::AsRawFd; |
39978
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
11 |
use std::path::Path; |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
12 |
use tokio_hglib::protocol::OneShotRequest; |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
13 |
use tokio_hglib::{Client, Connection}; |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
14 |
|
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
15 |
use super::attachio::AttachIo; |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
16 |
use super::message; |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
17 |
use super::runcommand::ChgRunCommand; |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
18 |
use super::uihandler::SystemHandler; |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
19 |
|
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
20 |
pub trait ChgClientExt<C> |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
21 |
where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
22 |
C: Connection + AsRawFd, |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
23 |
{ |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
24 |
/// Attaches the client file descriptors to the server. |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
25 |
fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E> |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
26 |
where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
27 |
I: AsRawFd, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
28 |
O: AsRawFd, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
29 |
E: AsRawFd; |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
30 |
|
39978
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
31 |
/// Changes the working directory of the server. |
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
32 |
fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C> |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
33 |
where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
34 |
P: AsRef<Path>; |
39978
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
35 |
|
44675
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
36 |
/// Updates the environment variables of the server. |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
37 |
fn set_env_vars_os<I, P>(self, vars: I) -> OneShotRequest<C> |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
38 |
where |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
39 |
I: IntoIterator<Item = (P, P)>, |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
40 |
P: AsRef<OsStr>; |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
41 |
|
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
42 |
/// Runs the specified Mercurial command with cHg extension. |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
43 |
fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H> |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
44 |
where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
45 |
I: IntoIterator<Item = P>, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
46 |
P: AsRef<OsStr>, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
47 |
H: SystemHandler; |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
48 |
} |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
49 |
|
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
50 |
impl<C> ChgClientExt<C> for Client<C> |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
51 |
where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
52 |
C: Connection + AsRawFd, |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
53 |
{ |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
54 |
fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E> |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
55 |
where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
56 |
I: AsRawFd, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
57 |
O: AsRawFd, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
58 |
E: AsRawFd, |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
59 |
{ |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
60 |
AttachIo::with_client(self, stdin, stdout, Some(stderr)) |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
61 |
} |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
62 |
|
39978
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
63 |
fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C> |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
64 |
where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
65 |
P: AsRef<Path>, |
39978
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
66 |
{ |
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
67 |
OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes()) |
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
68 |
} |
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39977
diff
changeset
|
69 |
|
44675
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
70 |
fn set_env_vars_os<I, P>(self, vars: I) -> OneShotRequest<C> |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
71 |
where |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
72 |
I: IntoIterator<Item = (P, P)>, |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
73 |
P: AsRef<OsStr>, |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
74 |
{ |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
75 |
OneShotRequest::start_with_args(self, b"setenv", message::pack_env_vars_os(vars)) |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
76 |
} |
97e6d435ff7e
rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents:
43818
diff
changeset
|
77 |
|
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
78 |
fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H> |
43818
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
79 |
where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
80 |
I: IntoIterator<Item = P>, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
81 |
P: AsRef<OsStr>, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39978
diff
changeset
|
82 |
H: SystemHandler, |
39977
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
83 |
{ |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
84 |
ChgRunCommand::with_client(self, handler, message::pack_args_os(args)) |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
85 |
} |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
86 |
} |