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/mirror.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'src/watch/mirror.rs') diff --git a/src/watch/mirror.rs b/src/watch/mirror.rs index 5b7e2b1..0eb9a77 100644 --- a/src/watch/mirror.rs +++ b/src/watch/mirror.rs @@ -39,10 +39,7 @@ fn sync_mirror_impl(cfg: &Config, db: &Db, name: &str, url: &str) -> Result h, - None => return Ok(Sync::Gone), - }; + let Some(remote) = git::ls_remote_head(url)? else { return Ok(Sync::Gone) }; let local = git::head(&mirror).ok(); if let Some(l) = &local { if *l == remote { @@ -95,9 +92,7 @@ pub(crate) fn read_tree(mirror: &Path, commit: &str) -> Result { let contents = git::cat_file_batch(mirror, &oids)?; let mut files = BTreeMap::new(); for (path, sha) in &blobs { - let bytes = contents - .get(sha) - .ok_or_else(|| Error::not_found(Missing::MirrorPath(path.to_string())))?; + let bytes = contents.get(sha).ok_or_else(|| Error::not_found(Missing::MirrorPath(path.to_string())))?; if bytes.len() > 4 * 1024 * 1024 || !looks_textual(bytes) { continue; } @@ -114,7 +109,6 @@ pub(crate) fn read_file(mirror: &Path, commit: &str, path: &str) -> Result (std::path::PathBuf, String) { - let nonce = std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_nanos(); + let nonce = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(); let dir = std::env::temp_dir().join(format!("aur-read-tree-{}-{}", std::process::id(), nonce)); std::fs::create_dir_all(&dir).unwrap(); let git = |args: &[&str]| { @@ -157,10 +148,13 @@ mod tests { #[test] fn read_tree_returns_every_blob_from_one_batch_read() { let (dir, head) = repo(&[ - ("PKGBUILD", b"pkgbase=foo + ( + "PKGBUILD", + b"pkgbase=foo pkgver=1.0 pkgrel=1 -"), +", + ), ("empty.txt", b""), ("blob.bin", b"\x00not text"), ]); @@ -179,8 +173,11 @@ pkgrel=1 #[test] fn read_tree_fails_closed_when_the_commit_is_gone_from_the_mirror() { - let (dir, _head) = repo(&[("PKGBUILD", b"pkgbase=foo -")]); + let (dir, _head) = repo(&[( + "PKGBUILD", + b"pkgbase=foo +", + )]); for gone in ["0123456789012345678901234567890123456789", "deadbeef"] { let err = read_tree(&dir, gone).unwrap_err().to_string(); assert!(err.contains("missing from the local mirror"), "{gone}: {err}"); -- cgit v1.2.3