From 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 Mon Sep 17 00:00:00 2001 From: aur-build Date: Sun, 22 Nov 2026 10:36:24 +0000 Subject: rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off rustfmt.toml fixes the shape the tree is written in (120 columns, small items kept on one line) and one canonical pass makes it the truth. [lints.clippy] names the idiom lints worth enforcing and leaves out the two that would add doc-comment boilerplate rather than remove it. The tree pays them off here: write!/writeln! instead of push_str(&format!()), let-else instead of match-on-Option, borrows where a thread entry point only reads what it owns, no `&self` on a Copy state and no `self` nobody reads. ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and value are now emitted by the same call instead of three. --- src/git.rs | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'src/git.rs') diff --git a/src/git.rs b/src/git.rs index 5ee41dd..a14ac50 100644 --- a/src/git.rs +++ b/src/git.rs @@ -14,10 +14,10 @@ pub fn git(cwd: Option<&Path>, args: &[&str]) -> Result { cmd.env("GIT_CONFIG_NOSYSTEM", "1"); cmd.env("LC_ALL", "C"); let out = cmd.output().map_err(|e| Error::git(format!("git {args:?}: {e}")))?; - ok(out, args) + ok(&out, args) } -fn ok(out: Output, args: &[&str]) -> Result { +fn ok(out: &Output, args: &[&str]) -> Result { if !out.status.success() { return Err(Error::git(format!( "git {args:?} exited {}: {}", @@ -35,11 +35,7 @@ fn git_ok(cwd: Option<&Path>, args: &[&str]) -> bool { pub fn ls_remote_head(url: &str) -> Result> { match git(None, &["ls-remote", url, "HEAD"]) { Ok(out) => { - let sha = out - .split_whitespace() - .next() - .filter(|s| s.len() >= 7) - .map(|s| s.to_string()); + let sha = out.split_whitespace().next().filter(|s| s.len() >= 7).map(std::string::ToString::to_string); Ok(sha) } Err(e) if is_missing_remote(&e) => Ok(None), @@ -49,11 +45,9 @@ pub fn ls_remote_head(url: &str) -> Result> { pub fn ls_remote_ref(url: &str, refname: &str) -> Result> { match git(None, &["ls-remote", url, refname]) { - Ok(out) => Ok(out - .lines() - .next() - .and_then(|l| l.split_whitespace().next()) - .map(|s| s.to_string())), + Ok(out) => { + Ok(out.lines().next().and_then(|l| l.split_whitespace().next()).map(std::string::ToString::to_string)) + } Err(e) if is_missing_remote(&e) => Ok(None), Err(e) => Err(e), } @@ -85,10 +79,7 @@ pub fn clone_bare(url: &str, dest: &Path) -> Result<()> { if let Some(parent) = dest.parent() { std::fs::create_dir_all(parent)?; } - git( - None, - &["clone", "--quiet", "--bare", url, &dest.display().to_string()], - )?; + git(None, &["clone", "--quiet", "--bare", url, &dest.display().to_string()])?; Ok(()) } @@ -180,12 +171,7 @@ pub fn cat_file_batch(mirror: &Path, oids: &[String]) -> Result { - return Err(Error::git(format!( - "unreadable cat-file header {:?}", - header.trim_end() - ))) - } + _ => return Err(Error::git(format!("unreadable cat-file header {:?}", header.trim_end()))), } } @@ -215,15 +201,11 @@ pub fn materialize(mirror: &Path, commit: &str, dest: &Path) -> Result<()> { .output() .map_err(|e| Error::git(e.to_string()))?; if !out.status.success() { - return Err(Error::git(format!( - "git archive {commit}: {}", - String::from_utf8_lossy(&out.stderr).trim() - ))); + return Err(Error::git(format!("git archive {commit}: {}", String::from_utf8_lossy(&out.stderr).trim()))); } let mut ar = tar::Archive::new(std::io::Cursor::new(&out.stdout)); ar.set_preserve_permissions(true); - ar.unpack(dest) - .map_err(|e| Error::git(format!("unpack {commit}: {e}")))?; + ar.unpack(dest).map_err(|e| Error::git(format!("unpack {commit}: {e}")))?; Ok(()) } -- cgit v1.2.3