annotate rust/chg/src/runcommand.rs @ 44695:f87804825df5

rust-chg: indent process_message() to prepare mass rewrite to futures-0.3 I'll start upgrading the codebase to modern async/await-based implementation, which cannot be done incrementally. This is the last non-breaking patch to prepare for the rewrite. Differential Revision: https://phab.mercurial-scm.org/D8403
author Yuya Nishihara <yuya@tcha.org>
date Fri, 10 Apr 2020 22:30:50 +0900
parents 6bef9d43cc55
children 94cace4b80ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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::codec::ChannelMessage;
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::protocol::MessageLoop;
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
16 use tokio_hglib::{Client, Connection};
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
17
44689
6bef9d43cc55 rust-chg: use "crate::" to import local modules
Yuya Nishihara <yuya@tcha.org>
parents: 44685
diff changeset
18 use crate::attachio::AttachIo;
6bef9d43cc55 rust-chg: use "crate::" to import local modules
Yuya Nishihara <yuya@tcha.org>
parents: 44685
diff changeset
19 use crate::message::{self, CommandType};
6bef9d43cc55 rust-chg: use "crate::" to import local modules
Yuya Nishihara <yuya@tcha.org>
parents: 44685
diff changeset
20 use crate::uihandler::SystemHandler;
39975
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>
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
29 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
30 C: Connection,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
31 H: SystemHandler,
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
32 {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
33 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
34 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
35 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
36 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
37 Finished,
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
44685
90e05b304902 rust-chg: silence warning about dated coding style
Yuya Nishihara <yuya@tcha.org>
parents: 43818
diff changeset
40 type CommandPoll<C, H> = io::Result<AsyncS<(Client<C>, H, i32), CommandState<C, H>>>;
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
41
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
42 /// 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
43 #[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
44 pub struct ChgRunCommand<C, H>
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
45 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
46 C: Connection,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
47 H: SystemHandler,
39975
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 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
50 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
51
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
52 impl<C, H> ChgRunCommand<C, H>
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
53 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
54 C: Connection + AsRawFd,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
55 H: SystemHandler,
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
56 {
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
57 pub fn with_client(client: Client<C>, handler: H, packed_args: Bytes) -> ChgRunCommand<C, H> {
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
58 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
59 ChgRunCommand {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
60 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
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 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
64
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
65 impl<C, H> Future for ChgRunCommand<C, H>
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
66 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
67 C: Connection + AsRawFd,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
68 H: SystemHandler,
39975
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 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
71 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
72
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
73 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
74 loop {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
75 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
76 match state.poll()? {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
77 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
78 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
79 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
80 AsyncS::NotReady(newstate) => {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
81 self.state = newstate;
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
82 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
83 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
84 AsyncS::PollAgain(newstate) => {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
85 self.state = newstate;
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 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
90 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
91
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
92 impl<C, H> CommandState<C, H>
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
93 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
94 C: Connection + AsRawFd,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
95 H: SystemHandler,
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
96 {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
97 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
98 match self {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
99 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
100 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
101 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
102 } else {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
103 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
104 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
105 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
106 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
107 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
108 let fut = AttachIo::with_client(client, io::stdin(), pin, None);
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
109 Ok(AsyncS::PollAgain(CommandState::AttachingPager(
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
110 fut, handler,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
111 )))
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
112 } else {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
113 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
114 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
115 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
116 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
117 if let Async::Ready(client) = fut.poll()? {
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
118 let msg_loop = MessageLoop::start(client, b""); // terminator
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
119 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
120 } else {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
121 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
122 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
123 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
124 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
125 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
126 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
127 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
128 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
129 } else {
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
130 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
131 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
132 }
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
133 CommandState::Finished => panic!("poll ChgRunCommand after it's done"),
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
134 }
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 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
137
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
138 fn process_message<C, H>(client: Client<C>, handler: H, msg: ChannelMessage) -> CommandPoll<C, H>
43818
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
139 where
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
140 C: Connection,
ce088b38f92b rust: run rustfmt
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39975
diff changeset
141 H: SystemHandler,
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
142 {
44695
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
143 {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
144 match msg {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
145 ChannelMessage::Data(b'r', data) => {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
146 let code = message::parse_result_code(data)?;
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
147 Ok(AsyncS::Ready((client, handler, code)))
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
148 }
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
149 ChannelMessage::Data(..) => {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
150 // just ignores data sent to optional channel
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
151 let msg_loop = MessageLoop::resume(client);
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
152 Ok(AsyncS::PollAgain(CommandState::Running(msg_loop, handler)))
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
153 }
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
154 ChannelMessage::InputRequest(..) | ChannelMessage::LineRequest(..) => Err(
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
155 io::Error::new(io::ErrorKind::InvalidData, "unsupported request"),
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
156 ),
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
157 ChannelMessage::SystemRequest(data) => {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
158 let (cmd_type, cmd_spec) = message::parse_command_spec(data)?;
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
159 match cmd_type {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
160 CommandType::Pager => {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
161 let fut = handler.spawn_pager(cmd_spec).into_future();
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
162 Ok(AsyncS::PollAgain(CommandState::SpawningPager(client, fut)))
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
163 }
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
164 CommandType::System => {
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
165 let fut = handler.run_system(cmd_spec).into_future();
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
166 Ok(AsyncS::PollAgain(CommandState::WaitingSystem(client, fut)))
f87804825df5 rust-chg: indent process_message() to prepare mass rewrite to futures-0.3
Yuya Nishihara <yuya@tcha.org>
parents: 44689
diff changeset
167 }
39975
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
168 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
169 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
170 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
171 }
571d8eb39095 rust-chg: add state machine to handle "runcommand" request with cHg extension
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
172 }