Mercurial > hg
annotate rust/chg/src/runcommand.rs @ 40440:09a37a5d8f5d
extensions: fix up many many debug logs that use %r
This gets us a bunch closer on Python 3, but I'll still have to use a
ton of sad globs. A previous version of this patch tried to preserve
the %r formatting, but upon review Yuya noted that special characters
in extension names is very unlikely, so we can just use %s and not
sweat the quoting.
Differential Revision: https://phab.mercurial-scm.org/D5002
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 12 Oct 2018 12:30:47 -0400 |
parents | 571d8eb39095 |
children | ce088b38f92b |
rev | line source |
---|---|
39975
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
1 // Copyright 2018 Yuya Nishihara <yuya@tcha.org> |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
2 // |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
3 // This software may be used and distributed according to the terms of the |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
4 // GNU General Public License version 2 or any later version. |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
5 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
6 //! Functions to run Mercurial command in cHg-aware command server. |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
7 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
8 use bytes::Bytes; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
9 use futures::future::IntoFuture; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
10 use futures::{Async, Future, Poll}; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
11 use std::io; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
12 use std::mem; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
13 use std::os::unix::io::AsRawFd; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
14 use tokio_hglib::{Client, Connection}; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
15 use tokio_hglib::codec::ChannelMessage; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
16 use tokio_hglib::protocol::MessageLoop; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
17 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
18 use super::attachio::AttachIo; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
19 use super::message::{self, CommandType}; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
20 use super::uihandler::SystemHandler; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
21 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
22 enum AsyncS<R, S> { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
23 Ready(R), |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
24 NotReady(S), |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
25 PollAgain(S), |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
26 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
27 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
28 enum CommandState<C, H> |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
29 where C: Connection, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
30 H: SystemHandler, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
31 { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
32 Running(MessageLoop<C>, H), |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
33 SpawningPager(Client<C>, <H::SpawnPagerResult as IntoFuture>::Future), |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
34 AttachingPager(AttachIo<C, io::Stdin, H::PagerStdin, H::PagerStdin>, H), |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
35 WaitingSystem(Client<C>, <H::RunSystemResult as IntoFuture>::Future), |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
36 Finished, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
37 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
38 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
39 type CommandPoll<C, H> = io::Result<(AsyncS<(Client<C>, H, i32), CommandState<C, H>>)>; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
40 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
41 /// Future resolves to `(exit_code, client)`. |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
42 #[must_use = "futures do nothing unless polled"] |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
43 pub struct ChgRunCommand<C, H> |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
44 where C: Connection, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
45 H: SystemHandler, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
46 { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
47 state: CommandState<C, H>, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
48 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
49 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
50 impl<C, H> ChgRunCommand<C, H> |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
51 where C: Connection + AsRawFd, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
52 H: SystemHandler, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
53 { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
54 pub fn with_client(client: Client<C>, handler: H, packed_args: Bytes) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
55 -> ChgRunCommand<C, H> { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
56 let msg_loop = MessageLoop::start_with_args(client, b"runcommand", packed_args); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
57 ChgRunCommand { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
58 state: CommandState::Running(msg_loop, handler), |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
59 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
60 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
61 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
62 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
63 impl<C, H> Future for ChgRunCommand<C, H> |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
64 where C: Connection + AsRawFd, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
65 H: SystemHandler, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
66 { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
67 type Item = (Client<C>, H, i32); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
68 type Error = io::Error; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
69 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
70 fn poll(&mut self) -> Poll<Self::Item, Self::Error> { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
71 loop { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
72 let state = mem::replace(&mut self.state, CommandState::Finished); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
73 match state.poll()? { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
74 AsyncS::Ready((client, handler, code)) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
75 return Ok(Async::Ready((client, handler, code))); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
76 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
77 AsyncS::NotReady(newstate) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
78 self.state = newstate; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
79 return Ok(Async::NotReady); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
80 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
81 AsyncS::PollAgain(newstate) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
82 self.state = newstate; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
83 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
84 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
85 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
86 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
87 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
88 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
89 impl<C, H> CommandState<C, H> |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
90 where C: Connection + AsRawFd, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
91 H: SystemHandler, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
92 { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
93 fn poll(self) -> CommandPoll<C, H> { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
94 match self { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
95 CommandState::Running(mut msg_loop, handler) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
96 if let Async::Ready((client, msg)) = msg_loop.poll()? { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
97 process_message(client, handler, msg) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
98 } else { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
99 Ok(AsyncS::NotReady(CommandState::Running(msg_loop, handler))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
100 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
101 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
102 CommandState::SpawningPager(client, mut fut) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
103 if let Async::Ready((handler, pin)) = fut.poll()? { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
104 let fut = AttachIo::with_client(client, io::stdin(), pin, None); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
105 Ok(AsyncS::PollAgain(CommandState::AttachingPager(fut, handler))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
106 } else { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
107 Ok(AsyncS::NotReady(CommandState::SpawningPager(client, fut))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
108 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
109 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
110 CommandState::AttachingPager(mut fut, handler) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
111 if let Async::Ready(client) = fut.poll()? { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
112 let msg_loop = MessageLoop::start(client, b""); // terminator |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
113 Ok(AsyncS::PollAgain(CommandState::Running(msg_loop, handler))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
114 } else { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
115 Ok(AsyncS::NotReady(CommandState::AttachingPager(fut, handler))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
116 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
117 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
118 CommandState::WaitingSystem(client, mut fut) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
119 if let Async::Ready((handler, code)) = fut.poll()? { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
120 let data = message::pack_result_code(code); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
121 let msg_loop = MessageLoop::resume_with_data(client, data); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
122 Ok(AsyncS::PollAgain(CommandState::Running(msg_loop, handler))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
123 } else { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
124 Ok(AsyncS::NotReady(CommandState::WaitingSystem(client, fut))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
125 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
126 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
127 CommandState::Finished => panic!("poll ChgRunCommand after it's done") |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
128 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
129 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
130 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
131 |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
132 fn process_message<C, H>(client: Client<C>, handler: H, msg: ChannelMessage) -> CommandPoll<C, H> |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
133 where C: Connection, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
134 H: SystemHandler, |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
135 { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
136 match msg { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
137 ChannelMessage::Data(b'r', data) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
138 let code = message::parse_result_code(data)?; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
139 Ok(AsyncS::Ready((client, handler, code))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
140 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
141 ChannelMessage::Data(..) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
142 // just ignores data sent to optional channel |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
143 let msg_loop = MessageLoop::resume(client); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
144 Ok(AsyncS::PollAgain(CommandState::Running(msg_loop, handler))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
145 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
146 ChannelMessage::InputRequest(..) | ChannelMessage::LineRequest(..) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
147 Err(io::Error::new(io::ErrorKind::InvalidData, "unsupported request")) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
148 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
149 ChannelMessage::SystemRequest(data) => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
150 let (cmd_type, cmd_spec) = message::parse_command_spec(data)?; |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
151 match cmd_type { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
152 CommandType::Pager => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
153 let fut = handler.spawn_pager(cmd_spec).into_future(); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
154 Ok(AsyncS::PollAgain(CommandState::SpawningPager(client, fut))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
155 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
156 CommandType::System => { |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
157 let fut = handler.run_system(cmd_spec).into_future(); |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
158 Ok(AsyncS::PollAgain(CommandState::WaitingSystem(client, fut))) |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
159 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
160 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
161 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
162 } |
571d8eb39095
rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff
changeset
|
163 } |