##// END OF EJS Templates
rust-chg: add interface to chdir the server
Yuya Nishihara -
r40014:045ea159 default
parent child Browse files
Show More
@@ -1,51 +1,64 b''
1 // Copyright 2018 Yuya Nishihara <yuya@tcha.org>
1 // Copyright 2018 Yuya Nishihara <yuya@tcha.org>
2 //
2 //
3 // This software may be used and distributed according to the terms of the
3 // This software may be used and distributed according to the terms of the
4 // GNU General Public License version 2 or any later version.
4 // GNU General Public License version 2 or any later version.
5
5
6 //! cHg extensions to command server client.
6 //! cHg extensions to command server client.
7
7
8 use std::ffi::OsStr;
8 use std::ffi::OsStr;
9 use std::os::unix::ffi::OsStrExt;
9 use std::os::unix::io::AsRawFd;
10 use std::os::unix::io::AsRawFd;
11 use std::path::Path;
10 use tokio_hglib::{Client, Connection};
12 use tokio_hglib::{Client, Connection};
13 use tokio_hglib::protocol::OneShotRequest;
11
14
12 use super::attachio::AttachIo;
15 use super::attachio::AttachIo;
13 use super::message;
16 use super::message;
14 use super::runcommand::ChgRunCommand;
17 use super::runcommand::ChgRunCommand;
15 use super::uihandler::SystemHandler;
18 use super::uihandler::SystemHandler;
16
19
17 pub trait ChgClientExt<C>
20 pub trait ChgClientExt<C>
18 where C: Connection + AsRawFd,
21 where C: Connection + AsRawFd,
19 {
22 {
20 /// Attaches the client file descriptors to the server.
23 /// Attaches the client file descriptors to the server.
21 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E>
24 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E>
22 where I: AsRawFd,
25 where I: AsRawFd,
23 O: AsRawFd,
26 O: AsRawFd,
24 E: AsRawFd;
27 E: AsRawFd;
25
28
29 /// Changes the working directory of the server.
30 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
31 where P: AsRef<Path>;
32
26 /// Runs the specified Mercurial command with cHg extension.
33 /// Runs the specified Mercurial command with cHg extension.
27 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
34 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
28 where I: IntoIterator<Item = P>,
35 where I: IntoIterator<Item = P>,
29 P: AsRef<OsStr>,
36 P: AsRef<OsStr>,
30 H: SystemHandler;
37 H: SystemHandler;
31 }
38 }
32
39
33 impl<C> ChgClientExt<C> for Client<C>
40 impl<C> ChgClientExt<C> for Client<C>
34 where C: Connection + AsRawFd,
41 where C: Connection + AsRawFd,
35 {
42 {
36 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E>
43 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E>
37 where I: AsRawFd,
44 where I: AsRawFd,
38 O: AsRawFd,
45 O: AsRawFd,
39 E: AsRawFd,
46 E: AsRawFd,
40 {
47 {
41 AttachIo::with_client(self, stdin, stdout, Some(stderr))
48 AttachIo::with_client(self, stdin, stdout, Some(stderr))
42 }
49 }
43
50
51 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
52 where P: AsRef<Path>,
53 {
54 OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes())
55 }
56
44 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
57 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
45 where I: IntoIterator<Item = P>,
58 where I: IntoIterator<Item = P>,
46 P: AsRef<OsStr>,
59 P: AsRef<OsStr>,
47 H: SystemHandler,
60 H: SystemHandler,
48 {
61 {
49 ChgRunCommand::with_client(self, handler, message::pack_args_os(args))
62 ChgRunCommand::with_client(self, handler, message::pack_args_os(args))
50 }
63 }
51 }
64 }
General Comments 0
You need to be logged in to leave comments. Login now