diff options
| author | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-22 10:36:24 +0000 |
| commit | 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 (patch) | |
| tree | 7cc7169181b4bdd73fd8817f8c1d7cce6e6998a8 /src/review/diff.rs | |
| parent | 9dc9087d89891c6e5ef7e5dc084dd13c8611843e (diff) | |
| download | aur-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/review/diff.rs')
| -rw-r--r-- | src/review/diff.rs | 124 |
1 files changed, 75 insertions, 49 deletions
diff --git a/src/review/diff.rs b/src/review/diff.rs index 39d9066..f997b3c 100644 --- a/src/review/diff.rs +++ b/src/review/diff.rs @@ -1,7 +1,8 @@ use crate::config::Config; -use crate::db::{self, *}; +use crate::db::{self, CandidateRow, Db, Recipe, ReleaseRow, SourceDigest, UpstreamPin}; use crate::error::Result; use crate::git; +use std::fmt::Write as _; #[derive(Debug, Clone)] pub struct Panel { @@ -31,9 +32,7 @@ pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow> } out.push(digest_delta(base, c)); out.push(pin_delta(base, c)); - let old_recipe = recipe_of(db, base.candidate_id.and_then(|cid| { - candidate_snapshot_id(db, cid) - })); + let old_recipe = recipe_of(db, base.candidate_id.and_then(|cid| candidate_snapshot_id(db, cid))); let new_recipe = recipe_of(db, Some(c.snapshot_id)); if let (Some(old), Some(new)) = (&old_recipe, &new_recipe) { out.push(source_delta(old, new)); @@ -45,9 +44,7 @@ pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow> out.push(Panel { name: "recipe_full", title: "Full recipe", - body: snap - .map(|s| s.srcinfo_json.clone()) - .unwrap_or_else(|| "(no snapshot)".into()), + body: snap.map_or_else(|| "(no snapshot)".into(), |s| s.srcinfo_json.clone()), }); } Ok(out) @@ -67,27 +64,27 @@ fn source_delta(old: &Recipe, new: &Recipe) -> Panel { let mut body = String::new(); for s in &new.source { if !old.source.contains(s) { - body.push_str(&format!("+ {s}\n")); + let _ = writeln!(body, "+ {s}"); } } for s in &old.source { if !new.source.contains(s) { - body.push_str(&format!("- {s}\n")); + let _ = writeln!(body, "- {s}"); } } let old_hosts = crate::urlutil::hosts(&old.source); let new_hosts = crate::urlutil::hosts(&new.source); for h in new_hosts.difference(&old_hosts) { - body.push_str(&format!("! new source host: {h}\n")); + let _ = writeln!(body, "! new source host: {h}"); } for h in old_hosts.difference(&new_hosts) { - body.push_str(&format!("! source host gone: {h}\n")); + let _ = writeln!(body, "! source host gone: {h}"); } for (i, sum) in new.sha256sums.iter().enumerate() { if sum.eq_ignore_ascii_case("SKIP") { match old.sha256sums.get(i) { Some(prev) if prev != "SKIP" && !prev.is_empty() => { - body.push_str(&format!("! [{i}] checksum removed (was {prev}, now SKIP)\n")) + let _ = writeln!(body, "! [{i}] checksum removed (was {prev}, now SKIP)"); } _ => {} } @@ -115,10 +112,10 @@ fn dependency_delta(old: &Recipe, new: &Recipe) -> Panel { let oset: std::collections::BTreeSet<String> = crate::pkgver::dep_names(o).into_iter().collect(); let nset: std::collections::BTreeSet<String> = crate::pkgver::dep_names(n).into_iter().collect(); for d in nset.difference(&oset) { - body.push_str(&format!("+ {label}: {d}\n")); + let _ = writeln!(body, "+ {label}: {d}"); } for d in oset.difference(&nset) { - body.push_str(&format!("- {label}: {d}\n")); + let _ = writeln!(body, "- {label}: {d}"); } } if !old.checkdepends.is_empty() && new.checkdepends.is_empty() { @@ -131,34 +128,34 @@ fn build_env_delta(old: &Recipe, new: &Recipe) -> Panel { let mut body = String::new(); for o in &new.options { if !old.options.contains(o) { - body.push_str(&format!("+ options: {o}\n")); + let _ = writeln!(body, "+ options: {o}"); } } for o in &old.options { if !new.options.contains(o) { - body.push_str(&format!("- options: {o}\n")); + let _ = writeln!(body, "- options: {o}"); } } for a in &new.arch { if !old.arch.contains(a) { - body.push_str(&format!("+ arch: {a}\n")); + let _ = writeln!(body, "+ arch: {a}"); } } for a in &old.arch { if !new.arch.contains(a) { - body.push_str(&format!("- arch: {a}\n")); + let _ = writeln!(body, "- arch: {a}"); } } if old.pkgbase != new.pkgbase { - body.push_str(&format!("! pkgbase renamed: {} -> {}\n", old.pkgbase, new.pkgbase)); + let _ = writeln!(body, "! pkgbase renamed: {} -> {}", old.pkgbase, new.pkgbase); } let old_set: std::collections::BTreeSet<String> = old.pkgnames.iter().cloned().collect(); let new_set: std::collections::BTreeSet<String> = new.pkgnames.iter().cloned().collect(); for p in new_set.difference(&old_set) { - body.push_str(&format!("+ split package: {p}\n")); + let _ = writeln!(body, "+ split package: {p}"); } for p in old_set.difference(&new_set) { - body.push_str(&format!("- split package: {p}\n")); + let _ = writeln!(body, "- split package: {p}"); } Panel { name: "buildenv", title: "Build-env delta", body } } @@ -166,9 +163,15 @@ fn build_env_delta(old: &Recipe, new: &Recipe) -> Panel { fn install_delta(old: &Recipe, new: &Recipe) -> Panel { let mut body = String::new(); match (&old.install, &new.install) { - (None, Some(f)) => body.push_str(&format!("+ install script added: {f}\n")), - (Some(f), None) => body.push_str(&format!("- install script removed: {f}\n")), - (Some(a), Some(b)) if a != b => body.push_str(&format!("! install script changed: {a} -> {b}\n")), + (None, Some(f)) => { + let _ = writeln!(body, "+ install script added: {f}"); + } + (Some(f), None) => { + let _ = writeln!(body, "- install script removed: {f}"); + } + (Some(a), Some(b)) if a != b => { + let _ = writeln!(body, "! install script changed: {a} -> {b}"); + } _ => {} } if crate::recipe::bodies_changed(&old.pkgbuild, &new.pkgbuild) { @@ -182,18 +185,20 @@ fn version_delta(base: Option<&ReleaseRow>, c: &CandidateRow) -> Panel { match base { Some(b) => { let (bv, cv) = (b.version(), c.version()); - body.push_str(&format!("{bv} -> {cv}\n")); + let _ = writeln!(body, "{bv} -> {cv}"); if b.epoch != c.epoch { - body.push_str(&format!("epoch bump: {} -> {}\n", b.epoch, c.epoch)); + let _ = writeln!(body, "epoch bump: {} -> {}", b.epoch, c.epoch); } if b.pkgrel != c.pkgrel && b.pkgver == c.pkgver { - body.push_str(&format!("pkgrel change: {} -> {}\n", b.pkgrel, c.pkgrel)); + let _ = writeln!(body, "pkgrel change: {} -> {}", b.pkgrel, c.pkgrel); } if crate::pkgver::is_downgrade(&bv, &cv) { body.push_str("DOWNGRADE: AUR now offers a lower version than we serve\n"); } } - None => body.push_str(&format!("first introduction: {}\n", c.version())), + None => { + let _ = writeln!(body, "first introduction: {}", c.version()); + } } Panel { name: "version", title: "Version delta", body } } @@ -205,24 +210,32 @@ fn digest_delta(base: &ReleaseRow, c: &CandidateRow) -> Panel { for n in &new { match old.iter().find(|o| o.index == n.index) { Some(o) if o.digest != n.digest => { - body.push_str(&format!( - "! [{}] {} {} -> {}\n", - n.index, n.url, short(&o.digest), short(&n.digest) - )); + let _ = writeln!(body, "! [{}] {} {} -> {}", n.index, n.url, short(&o.digest), short(&n.digest)); + } + Some(_) => { + let _ = writeln!(body, " [{}] {} unchanged", n.index, n.url); + } + None => { + let _ = writeln!( + body, + "+ [{}] {} NEW ({}{})", + n.index, + n.url, + n.kind, + if n.skip_declared && !n.is_vcs() { + ", sha256sums=SKIP" + } else if n.is_vcs() { + ", pinned commit" + } else { + "" + } + ); } - Some(_) => body.push_str(&format!(" [{}] {} unchanged\n", n.index, n.url)), - None => body.push_str(&format!( - "+ [{}] {} NEW ({}{})\n", - n.index, - n.url, - n.kind, - if n.skip_declared && !n.is_vcs() { ", sha256sums=SKIP" } else if n.is_vcs() { ", pinned commit" } else { "" } - )), } } for o in &old { if !new.iter().any(|n| n.index == o.index) { - body.push_str(&format!("- [{}] {} REMOVED\n", o.index, o.url)); + let _ = writeln!(body, "- [{}] {} REMOVED", o.index, o.url); } } Panel { name: "digests", title: "Source digest delta", body } @@ -238,26 +251,39 @@ fn pin_delta(base: &ReleaseRow, c: &CandidateRow) -> Panel { for n in &new { match old.iter().find(|o| o.index == n.index) { Some(o) if o.commit != n.commit => { - body.push_str(&format!( - "! [{}] {} {} -> {} (branch {})\n", - n.index, n.url, short(&o.commit), short(&n.commit), n.branch.as_deref().unwrap_or("?") - )); + let _ = writeln!( + body, + "! [{}] {} {} -> {} (branch {})", + n.index, + n.url, + short(&o.commit), + short(&n.commit), + n.branch.as_deref().unwrap_or("?") + ); + } + Some(_) => { + let _ = writeln!(body, " [{}] {} unchanged", n.index, n.url); + } + None => { + let _ = writeln!(body, "+ [{}] {} at {}", n.index, n.url, short(&n.commit)); } - Some(_) => body.push_str(&format!(" [{}] {} unchanged\n", n.index, n.url)), - None => body.push_str(&format!("+ [{}] {} at {}\n", n.index, n.url, short(&n.commit))), } } Panel { name: "upstream", title: "Upstream delta", body } } fn short(s: &str) -> String { - if s.len() > 12 { s[..12].to_string() } else { s.to_string() } + if s.len() > 12 { + s[..12].to_string() + } else { + s.to_string() + } } pub fn render_text(ps: &[Panel]) -> String { let mut s = String::new(); for p in ps { - s.push_str(&format!("### {}\n{}\n", p.title, p.body)); + let _ = write!(s, "### {}\n{}\n", p.title, p.body); } s } |
