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/watch/mirror.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/watch/mirror.rs')
| -rw-r--r-- | src/watch/mirror.rs | 29 |
1 files changed, 13 insertions, 16 deletions
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<Sync return Ok(Sync::Cloned { head }); } - let remote = match git::ls_remote_head(url)? { - Some(h) => 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<Tree> { 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<Vec<u git::read_blob(mirror, commit, path) } - #[cfg(test)] mod tests { use super::*; @@ -125,10 +119,7 @@ mod tests { /// answer for, so the test does not stand up a mirror, a database or a /// config to ask it a question about one tree. fn repo(files: &[(&str, &[u8])]) -> (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}"); |
