From e0960212c1499c76cc4abc8b2112baea97ecf1b4 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 19:38:09 +0000 Subject: git: read a tree with one cat-file --batch instead of one process per file read_tree cost a cat-file -e, an ls-tree and a cat-file blob per file, so the number of processes a detection paid for scaled with how many files a recipe ships. One ls-tree plus one batch read is now constant, and a commit that is gone from the mirror surfaces from ls-tree itself - still fail closed, still the same message. --- tests/detect.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'tests/detect.rs') diff --git a/tests/detect.rs b/tests/detect.rs index 86d1315..ef57121 100644 --- a/tests/detect.rs +++ b/tests/detect.rs @@ -5,7 +5,7 @@ use common::{git_add_commit, make_git_repo, params, Env, P}; use aur_build::db::{self, model::*, ReleaseRow}; use aur_build::review::{approve, candidates}; use aur_build::watch::detect::{check_pkgbase, Outcome}; -use aur_build::watch::mirror::{sync_mirror, Sync}; +use aur_build::watch::mirror::{read_tree, sync_mirror, Sync}; fn aur(env: &Env, name: &str) -> std::path::PathBuf { env.path(&format!("aur/{name}.git")) @@ -403,3 +403,46 @@ fn notices_are_not_duplicated_by_repeated_polling() { ); let _ = P::I(0); } + +#[test] +fn read_tree_returns_every_blob_from_one_batch_read() { + let env = Env::new(); + env.subscribe("foo"); + make_git_repo( + &aur(&env, "foo"), + &[ + ("PKGBUILD", &common::pkgbuild("foo", "1.0", "1", "")), + ("empty.txt", ""), + ("blob.bin", "\u{0}not text"), + ], + "initial", + ); + let url = format!("file://{}", aur(&env, "foo").display()); + sync_mirror(&env.cfg, &env.db, "foo", &url).unwrap(); + let mirror = env.cfg.mirror_path("foo"); + let head = aur_build::git::head(&mirror).unwrap(); + let tree = read_tree(&mirror, &head).unwrap(); + + assert!(tree.files["PKGBUILD"].contains("pkgver=1.0")); + assert_eq!(tree.files["empty.txt"], "", "an empty blob is a file, not a miss"); + assert!( + !tree.files.contains_key("blob.bin"), + "a NUL in the first block means it is not text: {:?}", + tree.files.keys().collect::>() + ); +} + +#[test] +fn read_tree_fails_closed_when_the_commit_is_gone_from_the_mirror() { + let env = Env::new(); + env.subscribe("foo"); + seed(&env, "foo", "1.0", "1", ""); + let url = format!("file://{}", aur(&env, "foo").display()); + sync_mirror(&env.cfg, &env.db, "foo", &url).unwrap(); + let mirror = env.cfg.mirror_path("foo"); + + for gone in ["0123456789012345678901234567890123456789", "deadbeef"] { + let err = read_tree(&mirror, gone).unwrap_err().to_string(); + assert!(err.contains("missing from the local mirror"), "{gone}: {err}"); + } +} -- cgit v1.2.3