diff --git a/rust/chg/src/attachio.rs b/rust/chg/src/attachio.rs --- a/rust/chg/src/attachio.rs +++ b/rust/chg/src/attachio.rs @@ -28,44 +28,41 @@ stdout: &impl AsRawFd, stderr: &impl AsRawFd, ) -> io::Result<()> { - // TODO: unindent - { - proto.send_command("attachio").await?; - loop { - match proto.fetch_response().await? { - ChannelMessage::Data(b'r', data) => { - let fd_cnt = message::parse_result_code(data)?; - if fd_cnt == 3 { - return Ok(()); - } else { - return Err(io::Error::new( - io::ErrorKind::InvalidData, - "unexpected attachio result", - )); - } - } - ChannelMessage::Data(..) => { - // just ignore data sent to uninteresting (optional) channel - } - ChannelMessage::InputRequest(1) => { - // this may fail with EWOULDBLOCK in theory, but the - // payload is quite small, and the send buffer should - // be empty so the operation will complete immediately - let sock_fd = proto.as_raw_fd(); - let ifd = stdin.as_raw_fd(); - let ofd = stdout.as_raw_fd(); - let efd = stderr.as_raw_fd(); - procutil::send_raw_fds(sock_fd, &[ifd, ofd, efd])?; - } - ChannelMessage::InputRequest(..) - | ChannelMessage::LineRequest(..) - | ChannelMessage::SystemRequest(..) => { + proto.send_command("attachio").await?; + loop { + match proto.fetch_response().await? { + ChannelMessage::Data(b'r', data) => { + let fd_cnt = message::parse_result_code(data)?; + if fd_cnt == 3 { + return Ok(()); + } else { return Err(io::Error::new( io::ErrorKind::InvalidData, - "unsupported request while attaching io", + "unexpected attachio result", )); } } + ChannelMessage::Data(..) => { + // just ignore data sent to uninteresting (optional) channel + } + ChannelMessage::InputRequest(1) => { + // this may fail with EWOULDBLOCK in theory, but the + // payload is quite small, and the send buffer should + // be empty so the operation will complete immediately + let sock_fd = proto.as_raw_fd(); + let ifd = stdin.as_raw_fd(); + let ofd = stdout.as_raw_fd(); + let efd = stderr.as_raw_fd(); + procutil::send_raw_fds(sock_fd, &[ifd, ofd, efd])?; + } + ChannelMessage::InputRequest(..) + | ChannelMessage::LineRequest(..) + | ChannelMessage::SystemRequest(..) => { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "unsupported request while attaching io", + )); + } } } } diff --git a/rust/chg/src/locator.rs b/rust/chg/src/locator.rs --- a/rust/chg/src/locator.rs +++ b/rust/chg/src/locator.rs @@ -88,22 +88,17 @@ } } - // TODO: unindent - { - { - let msg = format!( - concat!( - "too many redirections.\n", - "Please make sure {:?} is not a wrapper which ", - "changes sensitive environment variables ", - "before executing hg. If you have to use a ", - "wrapper, wrap chg instead of hg.", - ), - self.hg_command - ); - Err(io::Error::new(io::ErrorKind::Other, msg)) - } - } + let msg = format!( + concat!( + "too many redirections.\n", + "Please make sure {:?} is not a wrapper which ", + "changes sensitive environment variables ", + "before executing hg. If you have to use a ", + "wrapper, wrap chg instead of hg.", + ), + self.hg_command + ); + Err(io::Error::new(io::ErrorKind::Other, msg)) } /// Runs instructions received from the server. @@ -157,38 +152,33 @@ .unwrap_or(&self.base_sock_path) .clone(); debug!("try connect to {}", sock_path.display()); - // TODO: unindent - { - { - let mut client = match ChgClient::connect(sock_path).await { - Ok(client) => client, - Err(_) => { - // Prevent us from being re-connected to the outdated - // master server: We were told by the server to redirect - // to redirect_sock_path, which didn't work. We do not - // want to connect to the same master server again - // because it would probably tell us the same thing. - if self.redirect_sock_path.is_some() { - fs::remove_file(&self.base_sock_path).unwrap_or(()); - // may race - } - self.spawn_connect().await? - } - }; - check_server_capabilities(client.server_spec())?; - // It's purely optional, and the server might not support this command. - if client.server_spec().capabilities.contains("setprocname") { - client - .set_process_name(format!("chg[worker/{}]", self.process_id)) - .await?; + let mut client = match ChgClient::connect(sock_path).await { + Ok(client) => client, + Err(_) => { + // Prevent us from being re-connected to the outdated + // master server: We were told by the server to redirect + // to redirect_sock_path, which didn't work. We do not + // want to connect to the same master server again + // because it would probably tell us the same thing. + if self.redirect_sock_path.is_some() { + fs::remove_file(&self.base_sock_path).unwrap_or(()); + // may race } - client.set_current_dir(&self.current_dir).await?; - client - .set_env_vars_os(self.env_vars.iter().cloned()) - .await?; - Ok(client) + self.spawn_connect().await? } + }; + check_server_capabilities(client.server_spec())?; + // It's purely optional, and the server might not support this command. + if client.server_spec().capabilities.contains("setprocname") { + client + .set_process_name(format!("chg[worker/{}]", self.process_id)) + .await?; } + client.set_current_dir(&self.current_dir).await?; + client + .set_env_vars_os(self.env_vars.iter().cloned()) + .await?; + Ok(client) } /// Spawns new server process and connects to it. @@ -214,18 +204,13 @@ .env("CHGINTERNALMARK", "") .spawn()?; let client = self.connect_spawned(server, &sock_path).await?; - // TODO: unindent - { - { - debug!( - "rename {} to {}", - sock_path.display(), - self.base_sock_path.display() - ); - fs::rename(&sock_path, &self.base_sock_path)?; - Ok(client) - } - } + debug!( + "rename {} to {}", + sock_path.display(), + self.base_sock_path.display() + ); + fs::rename(&sock_path, &self.base_sock_path)?; + Ok(client) } /// Tries to connect to the just spawned server repeatedly until timeout diff --git a/rust/chg/src/uihandler.rs b/rust/chg/src/uihandler.rs --- a/rust/chg/src/uihandler.rs +++ b/rust/chg/src/uihandler.rs @@ -67,16 +67,11 @@ async fn run_system(&mut self, spec: &CommandSpec) -> io::Result { let status = new_shell_command(&spec).spawn()?.await?; - // TODO: unindent - { - { - let code = status - .code() - .or_else(|| status.signal().map(|n| -n)) - .expect("either exit code or signal should be set"); - Ok(code) - } - } + let code = status + .code() + .or_else(|| status.signal().map(|n| -n)) + .expect("either exit code or signal should be set"); + Ok(code) } }