7 |
7 |
8 use std::ffi::OsStr; |
8 use std::ffi::OsStr; |
9 use std::os::unix::ffi::OsStrExt; |
9 use std::os::unix::ffi::OsStrExt; |
10 use std::os::unix::io::AsRawFd; |
10 use std::os::unix::io::AsRawFd; |
11 use std::path::Path; |
11 use std::path::Path; |
|
12 use tokio_hglib::protocol::OneShotRequest; |
12 use tokio_hglib::{Client, Connection}; |
13 use tokio_hglib::{Client, Connection}; |
13 use tokio_hglib::protocol::OneShotRequest; |
|
14 |
14 |
15 use super::attachio::AttachIo; |
15 use super::attachio::AttachIo; |
16 use super::message; |
16 use super::message; |
17 use super::runcommand::ChgRunCommand; |
17 use super::runcommand::ChgRunCommand; |
18 use super::uihandler::SystemHandler; |
18 use super::uihandler::SystemHandler; |
19 |
19 |
20 pub trait ChgClientExt<C> |
20 pub trait ChgClientExt<C> |
21 where C: Connection + AsRawFd, |
21 where |
|
22 C: Connection + AsRawFd, |
22 { |
23 { |
23 /// Attaches the client file descriptors to the server. |
24 /// Attaches the client file descriptors to the server. |
24 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E> |
25 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E> |
25 where I: AsRawFd, |
26 where |
26 O: AsRawFd, |
27 I: AsRawFd, |
27 E: AsRawFd; |
28 O: AsRawFd, |
|
29 E: AsRawFd; |
28 |
30 |
29 /// Changes the working directory of the server. |
31 /// Changes the working directory of the server. |
30 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C> |
32 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C> |
31 where P: AsRef<Path>; |
33 where |
|
34 P: AsRef<Path>; |
32 |
35 |
33 /// Runs the specified Mercurial command with cHg extension. |
36 /// Runs the specified Mercurial command with cHg extension. |
34 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H> |
37 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H> |
35 where I: IntoIterator<Item = P>, |
38 where |
36 P: AsRef<OsStr>, |
39 I: IntoIterator<Item = P>, |
37 H: SystemHandler; |
40 P: AsRef<OsStr>, |
|
41 H: SystemHandler; |
38 } |
42 } |
39 |
43 |
40 impl<C> ChgClientExt<C> for Client<C> |
44 impl<C> ChgClientExt<C> for Client<C> |
41 where C: Connection + AsRawFd, |
45 where |
|
46 C: Connection + AsRawFd, |
42 { |
47 { |
43 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E> |
48 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E> |
44 where I: AsRawFd, |
49 where |
45 O: AsRawFd, |
50 I: AsRawFd, |
46 E: AsRawFd, |
51 O: AsRawFd, |
|
52 E: AsRawFd, |
47 { |
53 { |
48 AttachIo::with_client(self, stdin, stdout, Some(stderr)) |
54 AttachIo::with_client(self, stdin, stdout, Some(stderr)) |
49 } |
55 } |
50 |
56 |
51 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C> |
57 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C> |
52 where P: AsRef<Path>, |
58 where |
|
59 P: AsRef<Path>, |
53 { |
60 { |
54 OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes()) |
61 OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes()) |
55 } |
62 } |
56 |
63 |
57 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H> |
64 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H> |
58 where I: IntoIterator<Item = P>, |
65 where |
59 P: AsRef<OsStr>, |
66 I: IntoIterator<Item = P>, |
60 H: SystemHandler, |
67 P: AsRef<OsStr>, |
|
68 H: SystemHandler, |
61 { |
69 { |
62 ChgRunCommand::with_client(self, handler, message::pack_args_os(args)) |
70 ChgRunCommand::with_client(self, handler, message::pack_args_os(args)) |
63 } |
71 } |
64 } |
72 } |