Mercurial > hg-stable
annotate rust/chg/src/clientext.rs @ 43836:ce088b38f92b
rust: run rustfmt
# skip-blame automated reformatting
Differential Revision: https://phab.mercurial-scm.org/D7578
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 07 Dec 2019 13:06:25 -0800 |
parents | 045ea159418d |
children | 97e6d435ff7e |
rev | line source |
---|---|
39978
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; |
39979
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39978
diff
changeset
|
9 use std::os::unix::ffi::OsStrExt; |
39978
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; |
39979
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39978
diff
changeset
|
11 use std::path::Path; |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
12 use tokio_hglib::protocol::OneShotRequest; |
39978
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> |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
21 where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
22 C: Connection + AsRawFd, |
39978
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> |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
26 where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
27 I: AsRawFd, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
28 O: AsRawFd, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
29 E: AsRawFd; |
39978
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
30 |
39979
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39978
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:
39978
diff
changeset
|
32 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C> |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
33 where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
34 P: AsRef<Path>; |
39979
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39978
diff
changeset
|
35 |
39978
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
36 /// 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
|
37 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H> |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
38 where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
39 I: IntoIterator<Item = P>, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
40 P: AsRef<OsStr>, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
41 H: SystemHandler; |
39978
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
42 } |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
43 |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
44 impl<C> ChgClientExt<C> for Client<C> |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
45 where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
46 C: Connection + AsRawFd, |
39978
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
47 { |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
48 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E> |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
49 where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
50 I: AsRawFd, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
51 O: AsRawFd, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
52 E: AsRawFd, |
39978
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 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
|
55 } |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
56 |
39979
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39978
diff
changeset
|
57 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C> |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
58 where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
59 P: AsRef<Path>, |
39979
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39978
diff
changeset
|
60 { |
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39978
diff
changeset
|
61 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:
39978
diff
changeset
|
62 } |
045ea159418d
rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents:
39978
diff
changeset
|
63 |
39978
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
64 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H> |
43836
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
65 where |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
66 I: IntoIterator<Item = P>, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
67 P: AsRef<OsStr>, |
ce088b38f92b
rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39979
diff
changeset
|
68 H: SystemHandler, |
39978
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
69 { |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
70 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
|
71 } |
74da9d999cd7
rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
72 } |