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/watch/upstream.rs | 52 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 31 deletions(-) (limited to 'src/watch/upstream.rs') diff --git a/src/watch/upstream.rs b/src/watch/upstream.rs index 7987178..523574a 100644 --- a/src/watch/upstream.rs +++ b/src/watch/upstream.rs @@ -5,7 +5,11 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::{Condvar, Mutex}; use crate::config::Config; -use crate::db::{self, model::*, Db, Pkgbase}; +use crate::db::{ + self, + model::{Recipe, StageBCacheRow, UpstreamPin}, + Db, Pkgbase, +}; use crate::error::{Error, Result, TransientCause}; use crate::git; @@ -116,12 +120,7 @@ pub(crate) struct StageB { impl StageB { fn from_cache(row: StageBCacheRow) -> Self { - StageB { - epoch: row.epoch, - pkgver: row.pkgver, - pkgrel: row.pkgrel, - pins: row.pins, - } + StageB { epoch: row.epoch, pkgver: row.pkgver, pkgrel: row.pkgrel, pins: row.pins } } fn as_row(&self) -> StageBCacheRow { @@ -143,14 +142,14 @@ static SLOT_LOCK: Mutex<()> = Mutex::new(()); /// only way to reach it, and the alias is what carries the /// feature-conditional visibility. mod stage_b_slot { - use super::*; + use super::{Ordering, RUNNING, SLOT_FREE, SLOT_LOCK}; pub struct StageBSlot(()); impl StageBSlot { pub fn acquire(cap: usize) -> Self { let cap = cap.max(1); - let guard = SLOT_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let guard = SLOT_LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner); let mut guard = guard; loop { let n = RUNNING.load(Ordering::SeqCst); @@ -159,7 +158,7 @@ mod stage_b_slot { drop(guard); return StageBSlot(()); } - guard = SLOT_FREE.wait(guard).unwrap_or_else(|e| e.into_inner()); + guard = SLOT_FREE.wait(guard).unwrap_or_else(std::sync::PoisonError::into_inner); } } } @@ -191,7 +190,7 @@ pub(crate) fn resolve( recipe_hash: &str, stage_a: &StageA, ) -> Result> { - if !recipe.source_entries.iter().any(|e| e.is_vcs()) { + if !recipe.source_entries.iter().any(super::super::db::model::SourceEntry::is_vcs) { return Ok(None); } let tip_hash = tip_hash(&stage_a.pins); @@ -225,11 +224,11 @@ fn run( continue; } let cache = cfg.vcs_cache_path(&pin.url); - if !cache.exists() { + if cache.exists() { + let _ = git::fetch_and_head(&cache); + } else { git::clone_bare(&pin.url, &cache) .map_err(|e| Error::transient(TransientCause::Upstream(format!("vcs_cache clone {}: {e}", pin.url))))?; - } else { - let _ = git::fetch_and_head(&cache); } if let Ok(local) = git::head(&cache) { if !local.is_empty() && git::has_commit(&cache, &pin.commit) { @@ -251,10 +250,7 @@ fn run( let out = cmd.output()?; let _ = std::fs::remove_dir_all(&scratch); if !out.status.success() { - return Err(Error::transient(format!( - "makepkg --vercheck: {}", - String::from_utf8_lossy(&out.stderr).trim() - ))); + return Err(Error::transient(format!("makepkg --vercheck: {}", String::from_utf8_lossy(&out.stderr).trim()))); } let text = String::from_utf8_lossy(&out.stdout).trim().to_string(); let (pkgver, pkgrel) = match text.rsplit_once('-') { @@ -264,12 +260,7 @@ fn run( if pkgver.is_empty() { return Err(Error::other(format!("makepkg --vercheck produced {text:?}"))); } - Ok(StageB { - epoch: recipe.epoch.clone(), - pkgver, - pkgrel, - pins, - }) + Ok(StageB { epoch: recipe.epoch.clone(), pkgver, pkgrel, pins }) } fn default_branch(cache: &std::path::Path) -> Option { @@ -280,16 +271,15 @@ fn default_branch(cache: &std::path::Path) -> Option { } pub fn tip_hash(pins: &[UpstreamPin]) -> String { - let mut v: Vec = pins - .iter() - .map(|p| format!("{}:{}:{}", p.index, p.url, p.commit)) - .collect(); + let mut v: Vec = pins.iter().map(|p| format!("{}:{}:{}", p.index, p.url, p.commit)).collect(); v.sort(); crate::hash::hex_str(&v.join("\n")) } fn scratch_dir(cfg: &Config, pkgbase: &str, recipe_hash: &str, tip_hash: &str) -> PathBuf { - cfg.staging_dir() - .join("vercheck") - .join(format!("{pkgbase}-{}-{}", &recipe_hash[..8.min(recipe_hash.len())], &tip_hash[..8.min(tip_hash.len())])) + cfg.staging_dir().join("vercheck").join(format!( + "{pkgbase}-{}-{}", + &recipe_hash[..8.min(recipe_hash.len())], + &tip_hash[..8.min(tip_hash.len())] + )) } -- cgit v1.2.3