Skip to content

Commit 0817928

Browse files
committed
style: Inline fmt args
1 parent bfef2d5 commit 0817928

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

src/hooks.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Hooks {
8989

9090
let mut cmd = std::process::Command::new(sh_path);
9191
cmd.arg("-c")
92-
.arg(format!("{} \"$@\"", bin_name))
92+
.arg(format!("{bin_name} \"$@\""))
9393
.arg(bin_name) // "$@" expands "$1" "$2" "$3" ... but we also must specify $0.
9494
.args(args)
9595
.env("PATH", path)
@@ -131,7 +131,7 @@ impl Hooks {
131131
let mut stdin = String::new();
132132
for (old_oid, new_oid) in changed_oids {
133133
use std::fmt::Write;
134-
writeln!(stdin, "{} {}", old_oid, new_oid).expect("Always writeable");
134+
writeln!(stdin, "{old_oid} {new_oid}").expect("Always writeable");
135135
}
136136

137137
match self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[]) {
@@ -188,7 +188,7 @@ impl Hooks {
188188
let mut stdin = String::new();
189189
for (old_oid, new_oid, ref_name) in changed_refs {
190190
use std::fmt::Write;
191-
writeln!(stdin, "{} {} {}", old_oid, new_oid, ref_name).expect("Always writeable");
191+
writeln!(stdin, "{old_oid} {new_oid} {ref_name}").expect("Always writeable");
192192
}
193193

194194
let code = self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[])?;
@@ -198,7 +198,7 @@ impl Hooks {
198198
log::trace!("Hook `{}` failed with code {}", name, code);
199199
Err(std::io::Error::new(
200200
std::io::ErrorKind::Interrupted,
201-
format!("`{}` hook failed with code {}", name, code),
201+
format!("`{name}` hook failed with code {code}"),
202202
))
203203
}
204204
}
@@ -220,7 +220,7 @@ impl Hooks {
220220
let mut stdin = String::new();
221221
for (old_oid, new_oid, ref_name) in changed_refs {
222222
use std::fmt::Write;
223-
writeln!(stdin, "{} {} {}", old_oid, new_oid, ref_name).expect("Always writeable");
223+
writeln!(stdin, "{old_oid} {new_oid} {ref_name}").expect("Always writeable");
224224
}
225225

226226
match self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[]) {
@@ -251,7 +251,7 @@ impl Hooks {
251251
let mut stdin = String::new();
252252
for (old_oid, new_oid, ref_name) in changed_refs {
253253
use std::fmt::Write;
254-
writeln!(stdin, "{} {} {}", old_oid, new_oid, ref_name).expect("Always writeable");
254+
writeln!(stdin, "{old_oid} {new_oid} {ref_name}").expect("Always writeable");
255255
}
256256

257257
match self.run_hook(repo, name, &args, Some(stdin.as_bytes()), &[]) {

src/ops.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn cherry_pick(
113113
return Err(git2::Error::new(
114114
git2::ErrorCode::Unmerged,
115115
git2::ErrorClass::Index,
116-
format!("cherry-pick conflicts:\n {}\n", conflicts),
116+
format!("cherry-pick conflicts:\n {conflicts}\n"),
117117
));
118118
}
119119

@@ -219,7 +219,7 @@ pub fn squash(
219219
return Err(git2::Error::new(
220220
git2::ErrorCode::Unmerged,
221221
git2::ErrorClass::Index,
222-
format!("squash conflicts:\n {}\n", conflicts),
222+
format!("squash conflicts:\n {conflicts}\n"),
223223
));
224224
}
225225
let result_id = result_index.write_tree_to(repo)?;
@@ -362,7 +362,7 @@ impl UserSign {
362362
_ => Err(git2::Error::new(
363363
git2::ErrorCode::Invalid,
364364
git2::ErrorClass::Config,
365-
format!("invalid valid for gpg.format: {}", format),
365+
format!("invalid valid for gpg.format: {format}"),
366366
)),
367367
}
368368
}
@@ -459,15 +459,15 @@ impl Sign for SshSign {
459459
git2::Error::new(
460460
git2::ErrorCode::GenericError,
461461
git2::ErrorClass::Os,
462-
format!("failed writing ssh signing key: {}", e),
462+
format!("failed writing ssh signing key: {e}"),
463463
)
464464
})?;
465465

466466
std::fs::write(temp.path(), literal_key).map_err(|e| {
467467
git2::Error::new(
468468
git2::ErrorCode::GenericError,
469469
git2::ErrorClass::Os,
470-
format!("failed writing ssh signing key: {}", e),
470+
format!("failed writing ssh signing key: {e}"),
471471
)
472472
})?;
473473
let path = temp.path().to_owned();
@@ -487,14 +487,14 @@ impl Sign for SshSign {
487487
git2::Error::new(
488488
git2::ErrorCode::GenericError,
489489
git2::ErrorClass::Os,
490-
format!("failed writing buffer: {}", e),
490+
format!("failed writing buffer: {e}"),
491491
)
492492
})?;
493493
std::fs::write(buffer_file.path(), buffer).map_err(|e| {
494494
git2::Error::new(
495495
git2::ErrorCode::GenericError,
496496
git2::ErrorClass::Os,
497-
format!("failed writing buffer: {}", e),
497+
format!("failed writing buffer: {e}"),
498498
)
499499
})?;
500500

@@ -557,15 +557,15 @@ impl Sign for SshSign {
557557
git2::Error::new(
558558
git2::ErrorCode::GenericError,
559559
git2::ErrorClass::Os,
560-
format!("failed writing buffer: {}", e),
560+
format!("failed writing buffer: {e}"),
561561
)
562562
})?;
563563
if let Some(literal_key_file) = literal_key_file {
564564
literal_key_file.close().map_err(|e| {
565565
git2::Error::new(
566566
git2::ErrorCode::GenericError,
567567
git2::ErrorClass::Os,
568-
format!("failed writing ssh signing key: {}", e),
568+
format!("failed writing ssh signing key: {e}"),
569569
)
570570
})?;
571571
}
@@ -591,7 +591,7 @@ fn pipe_command(
591591
.spawn()?;
592592
if let Some(stdin) = stdin {
593593
let mut stdin_sync = child.stdin.take().expect("stdin is piped");
594-
write!(stdin_sync, "{}", stdin)?;
594+
write!(stdin_sync, "{stdin}")?;
595595
}
596596
child.wait_with_output()
597597
}
@@ -630,20 +630,14 @@ fn get_default_ssh_signing_key(config: &git2::Config) -> Result<Option<String>,
630630
git2::Error::new(
631631
git2::ErrorCode::Invalid,
632632
git2::ErrorClass::Config,
633-
format!(
634-
"malformed gpg.ssh.defaultKeyCommand: {}",
635-
ssh_default_key_command
636-
),
633+
format!("malformed gpg.ssh.defaultKeyCommand: {ssh_default_key_command}"),
637634
)
638635
})?;
639636
if ssh_default_key_args.is_empty() {
640637
return Err(git2::Error::new(
641638
git2::ErrorCode::Invalid,
642639
git2::ErrorClass::Config,
643-
format!(
644-
"malformed gpg.ssh.defaultKeyCommand: {}",
645-
ssh_default_key_command
646-
),
640+
format!("malformed gpg.ssh.defaultKeyCommand: {ssh_default_key_command}"),
647641
));
648642
}
649643

src/testing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Git {
169169
pub(crate) fn get_base_env(&self, time: isize) -> Vec<(OsString, OsString)> {
170170
// Required for determinism, as these values will be baked into the commit
171171
// hash.
172-
let date: OsString = format!("{date} -{time:0>2}", date = DUMMY_DATE, time = time).into();
172+
let date: OsString = format!("{DUMMY_DATE} -{time:0>2}").into();
173173

174174
// Fake "editor" which accepts the default contents of any commit
175175
// messages. Usually, we can set this with `git commit -m`, but we have
@@ -332,7 +332,7 @@ stderr:
332332
if let Some(dir) = path.parent() {
333333
std::fs::create_dir_all(self.repo_path.join(dir))?;
334334
}
335-
let file_path = self.repo_path.join(format!("{}.txt", name));
335+
let file_path = self.repo_path.join(format!("{name}.txt"));
336336
std::fs::write(file_path, contents)?;
337337
Ok(())
338338
}
@@ -348,7 +348,7 @@ stderr:
348348
self.write_file(name, contents)?;
349349
self.run(&["add", "."])?;
350350
self.run_with_options(
351-
&["commit", "-m", &format!("create {}.txt", name)],
351+
&["commit", "-m", &format!("create {name}.txt")],
352352
&GitRunOptions {
353353
time,
354354
..Default::default()
@@ -366,7 +366,7 @@ stderr:
366366
/// Commit a file with default contents. The `time` argument is used to set
367367
/// the commit timestamp, which is factored into the commit hash.
368368
pub(crate) fn commit_file(&self, name: &str, time: isize) -> eyre::Result<git2::Oid> {
369-
self.commit_file_with_contents(name, time, &format!("{} contents\n", name))
369+
self.commit_file_with_contents(name, time, &format!("{name} contents\n"))
370370
}
371371

372372
/// Get a `Repo` object for this repository.

tests/testsuite/ops.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn cherry_pick_conflict() {
6060

6161
let dest_id = git2_ext::ops::cherry_pick(&repo, base_id, source_id, None);
6262

63-
println!("{:#?}", dest_id);
63+
println!("{dest_id:#?}");
6464
assert!(dest_id.is_err());
6565
assert!(!git2_ext::ops::is_dirty(&repo));
6666
}
@@ -91,7 +91,7 @@ fn squash_clean() {
9191

9292
let dest_id = git2_ext::ops::squash(&repo, source_id, base_id, None).unwrap();
9393

94-
println!("{:#?}", dest_id);
94+
println!("{dest_id:#?}");
9595
assert!(!git2_ext::ops::is_dirty(&repo));
9696
}
9797

@@ -119,7 +119,7 @@ fn reword() {
119119

120120
let new_id = git2_ext::ops::reword(&repo, feature2_id, "New message", None).unwrap();
121121

122-
println!("{:#?}", new_id);
122+
println!("{new_id:#?}");
123123
assert!(!git2_ext::ops::is_dirty(&repo));
124124
}
125125

0 commit comments

Comments
 (0)