Skip to content

Commit c9d614e

Browse files
committed
chore(cleanup): reformat code
1 parent 37b3999 commit c9d614e

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

asyncgit/src/sync/sign.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ impl SignBuilder {
155155
String::from("x509"),
156156
)),
157157
"ssh" => {
158-
let program = config
159-
.get_string("gpg.ssh.program")
160-
.unwrap_or_else(|_| "ssh-keygen".to_string());
158+
let program = config
159+
.get_string("gpg.ssh.program")
160+
.unwrap_or_else(|_| "ssh-keygen".to_string());
161161

162162
let signing_key = config
163163
.get_string("user.signingKey")
@@ -166,7 +166,11 @@ impl SignBuilder {
166166
err.to_string(),
167167
)
168168
})
169-
.and_then(|signing_key| { SignBuilder::signing_key_into_path(&signing_key) })?;
169+
.and_then(|signing_key| {
170+
SignBuilder::signing_key_into_path(
171+
&signing_key,
172+
)
173+
})?;
170174

171175
Ok(Box::new(SSHSign {
172176
program,
@@ -177,20 +181,22 @@ impl SignBuilder {
177181
}
178182
}
179183

180-
fn signing_key_into_path(signing_key: &str) -> Result<PathBuf, SignBuilderError> {
181-
let key_path = PathBuf::from(signing_key);
182-
if key_path.is_file() {
183-
Ok(key_path)
184-
} else {
185-
if signing_key.starts_with("ssh-") {
186-
Ok(key_path) //TODO: write key to temp file
187-
} else {
188-
Err(SignBuilderError::SSHSigningKey(String::from(
184+
fn signing_key_into_path(
185+
signing_key: &str,
186+
) -> Result<PathBuf, SignBuilderError> {
187+
let key_path = PathBuf::from(signing_key);
188+
if key_path.is_file() {
189+
Ok(key_path)
190+
} else {
191+
if signing_key.starts_with("ssh-") {
192+
Ok(key_path) //TODO: write key to temp file
193+
} else {
194+
Err(SignBuilderError::SSHSigningKey(String::from(
189195
"ssh key could not be resolve. Either the key is not a file or the key is not a valid public ssh key",
190196
)))
191-
}
192-
}
193-
}
197+
}
198+
}
199+
}
194200
}
195201

196202
/// Sign commit data using `OpenPGP`
@@ -278,7 +284,7 @@ impl Sign for SSHSign {
278284
&self,
279285
commit: &[u8],
280286
) -> Result<(String, Option<String>), SignError> {
281-
use std::io::Write;
287+
use std::io::Write;
282288
use std::process::{Command, Stdio};
283289

284290
let mut cmd = Command::new(&self.program);
@@ -295,22 +301,22 @@ impl Sign for SSHSign {
295301
log::trace!("signing command: {cmd:?}");
296302

297303
let mut child = cmd
298-
.spawn()
304+
.spawn()
299305
.map_err(|e| SignError::Spawn(e.to_string()))?;
300306

301307
let mut stdin = child.stdin.take().ok_or(SignError::Stdin)?;
302308

303309
stdin
304-
.write_all(commit)
310+
.write_all(commit)
305311
.map_err(|e| SignError::WriteBuffer(e.to_string()))?;
306312
drop(stdin);
307313

308314
let output = child
309-
.wait_with_output()
315+
.wait_with_output()
310316
.map_err(|e| SignError::Output(e.to_string()))?;
311317

312318
if !output.status.success() {
313-
return Err(SignError::Shellout(format!(
319+
return Err(SignError::Shellout(format!(
314320
"failed to sign data, program '{}' exited non-zero: {}",
315321
&self.program,
316322
std::str::from_utf8(&output.stderr)
@@ -319,7 +325,7 @@ impl Sign for SSHSign {
319325
}
320326

321327
let signed_commit = std::str::from_utf8(&output.stdout)
322-
.map_err(|e| SignError::Shellout(e.to_string()))?;
328+
.map_err(|e| SignError::Shellout(e.to_string()))?;
323329

324330
Ok((signed_commit.to_string(), None))
325331
}

0 commit comments

Comments
 (0)