changeset 44856:27fe8cc1338f

rust-chg: clean up excessive indents Differential Revision: https://phab.mercurial-scm.org/D8450
author Yuya Nishihara <yuya@tcha.org>
date Sat, 11 Apr 2020 17:43:29 +0900
parents 4b0185841058
children f365dfede78f
files rust/chg/src/attachio.rs rust/chg/src/locator.rs rust/chg/src/uihandler.rs
diffstat 3 files changed, 77 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/rust/chg/src/attachio.rs	Sat Apr 11 02:51:03 2020 +0900
+++ b/rust/chg/src/attachio.rs	Sat Apr 11 17:43:29 2020 +0900
@@ -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",
+                ));
+            }
         }
     }
 }
--- a/rust/chg/src/locator.rs	Sat Apr 11 02:51:03 2020 +0900
+++ b/rust/chg/src/locator.rs	Sat Apr 11 17:43:29 2020 +0900
@@ -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
--- a/rust/chg/src/uihandler.rs	Sat Apr 11 02:51:03 2020 +0900
+++ b/rust/chg/src/uihandler.rs	Sat Apr 11 17:43:29 2020 +0900
@@ -67,16 +67,11 @@
 
     async fn run_system(&mut self, spec: &CommandSpec) -> io::Result<i32> {
         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)
     }
 }