summaryrefslogtreecommitdiffstats
path: root/src/git.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-22 10:36:24 +0000
committeraur-build <aur-build@localhost>2026-11-22 10:36:24 +0000
commit3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch)
tree7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /src/git.rs
parent9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff)
downloadaur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.tar.gz
aur-build-3dc71b2f5160ef9bd46143eed0edb5d2557b58e6.zip
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.
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs38
1 files changed, 10 insertions, 28 deletions
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<String> {
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<String> {
+fn ok(out: &Output, args: &[&str]) -> Result<String> {
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<Option<String>> {
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<Option<String>> {
pub fn ls_remote_ref(url: &str, refname: &str) -> Result<Option<String>> {
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<BTreeMap<String,
stdout.read_exact(&mut newline)?;
out.insert(id, body);
}
- _ => {
- 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(())
}