annotate rust/chg/src/clientext.rs @ 44683:065048e66f32

rust-chg: send client side umask to server This is equivalent to forwardumask() of hgclient.c. Differential Revision: https://phab.mercurial-scm.org/D8382
author Yuya Nishihara <yuya@tcha.org>
date Thu, 04 Oct 2018 22:44:37 +0900
parents 43513444bb88
children 80d6e3415636
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
44683
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
8 use bytes::{BufMut, Bytes, BytesMut};
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
9 use std::ffi::OsStr;
44680
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
10 use std::io;
44683
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
11 use std::mem;
39978
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39977
diff changeset
12 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
13 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
14 use std::path::Path;
44680
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
15 use tokio_hglib::protocol::{OneShotQuery, OneShotRequest};
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
16 use tokio_hglib::{Client, Connection};
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
17
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
18 use super::attachio::AttachIo;
44680
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
19 use super::message::{self, Instruction};
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
20 use super::runcommand::ChgRunCommand;
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
21 use super::uihandler::SystemHandler;
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
22
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
23 pub trait ChgClientExt<C>
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
24 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
25 C: Connection + AsRawFd,
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
26 {
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
27 /// 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
28 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
29 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
30 I: AsRawFd,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
31 O: AsRawFd,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
32 E: AsRawFd;
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
33
39978
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39977
diff changeset
34 /// 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
35 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
36 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
37 P: AsRef<Path>;
39978
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39977
diff changeset
38
44675
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
39 /// 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
40 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
41 where
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
42 I: IntoIterator<Item = (P, P)>,
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
43 P: AsRef<OsStr>;
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
44
44683
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
45 /// Changes the umask of the server process.
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
46 fn set_umask(self, mask: u32) -> OneShotRequest<C>;
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
47
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
48 /// 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
49 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
50 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
51 I: IntoIterator<Item = P>,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
52 P: AsRef<OsStr>,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
53 H: SystemHandler;
44680
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
54
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
55 /// Validates if the server can run Mercurial commands with the expected
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
56 /// configuration.
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
57 ///
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
58 /// The `args` should contain early command arguments such as `--config`
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
59 /// and `-R`.
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
60 ///
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
61 /// Client-side environment must be sent prior to this request, by
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
62 /// `set_current_dir()` and `set_env_vars_os()`.
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
63 fn validate<I, P>(self, args: I) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
64 where
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
65 I: IntoIterator<Item = P>,
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
66 P: AsRef<OsStr>;
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
67 }
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
68
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
69 impl<C> ChgClientExt<C> for Client<C>
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
70 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
71 C: Connection + AsRawFd,
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
72 {
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
73 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
74 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
75 I: AsRawFd,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
76 O: AsRawFd,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
77 E: AsRawFd,
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
78 {
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
79 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
80 }
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
81
39978
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39977
diff changeset
82 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
83 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
84 P: AsRef<Path>,
39978
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39977
diff changeset
85 {
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39977
diff changeset
86 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
87 }
045ea159418d rust-chg: add interface to chdir the server
Yuya Nishihara <yuya@tcha.org>
parents: 39977
diff changeset
88
44675
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
89 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
90 where
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
91 I: IntoIterator<Item = (P, P)>,
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
92 P: AsRef<OsStr>,
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
93 {
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
94 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
95 }
97e6d435ff7e rust-chg: send client-side environment variables to server
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
96
44683
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
97 fn set_umask(self, mask: u32) -> OneShotRequest<C> {
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
98 let mut args = BytesMut::with_capacity(mem::size_of_val(&mask));
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
99 args.put_u32_be(mask);
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
100 OneShotRequest::start_with_args(self, b"setumask2", args)
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
101 }
065048e66f32 rust-chg: send client side umask to server
Yuya Nishihara <yuya@tcha.org>
parents: 44680
diff changeset
102
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
103 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
104 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
105 I: IntoIterator<Item = P>,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
106 P: AsRef<OsStr>,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39978
diff changeset
107 H: SystemHandler,
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
108 {
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
109 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
110 }
44680
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
111
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
112 fn validate<I, P>(self, args: I) -> OneShotQuery<C, fn(Bytes) -> io::Result<Vec<Instruction>>>
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
113 where
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
114 I: IntoIterator<Item = P>,
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
115 P: AsRef<OsStr>,
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
116 {
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
117 OneShotQuery::start_with_args(
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
118 self,
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
119 b"validate",
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
120 message::pack_args_os(args),
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
121 message::parse_instructions,
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
122 )
43513444bb88 rust-chg: add interface to run "validate" request
Yuya Nishihara <yuya@tcha.org>
parents: 44675
diff changeset
123 }
39977
74da9d999cd7 rust-chg: add Client extensions to run cHg-specific requests
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
124 }