summaryrefslogtreecommitdiffstats
path: root/src/watch/mirror.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 19:38:09 +0000
committeraur-build <aur-build@localhost>2026-11-19 19:38:09 +0000
commite0960212c1499c76cc4abc8b2112baea97ecf1b4 (patch)
tree4d71ae9e78bdb659673f2d0ef3addc80a5b78641 /src/watch/mirror.rs
parent0a4990bc4dc736d3c10708b6e77670863b2cc9a8 (diff)
downloadaur-build-e0960212c1499c76cc4abc8b2112baea97ecf1b4.tar.gz
aur-build-e0960212c1499c76cc4abc8b2112baea97ecf1b4.zip
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.
Diffstat (limited to 'src/watch/mirror.rs')
-rw-r--r--src/watch/mirror.rs34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/watch/mirror.rs b/src/watch/mirror.rs
index 89c175d..6616bc1 100644
--- a/src/watch/mirror.rs
+++ b/src/watch/mirror.rs
@@ -67,19 +67,33 @@ impl Tree {
}
pub fn read_tree(mirror: &Path, commit: &str) -> Result<Tree> {
- if !git::has_commit(mirror, commit) {
- return Err(Error::fail_closed(format!(
- "commit {commit} is missing from the local mirror; history was rewritten"
- )));
- }
- let blobs = git::ls_tree(mirror, commit)?;
+ // One `ls-tree` and one `cat-file --batch` for the whole tree, so the number
+ // of files a recipe ships does not decide how many processes a read costs.
+ // A commit that is gone from the mirror surfaces here, from `ls-tree`, rather
+ // than from a separate `cat-file -e` probe first.
+ let blobs = match git::ls_tree(mirror, commit) {
+ Ok(blobs) => blobs,
+ Err(e) => {
+ let text = e.to_string().to_lowercase();
+ if text.contains("not a tree object") || text.contains("not a valid object name") {
+ return Err(Error::fail_closed(format!(
+ "commit {commit} is missing from the local mirror; history was rewritten"
+ )));
+ }
+ return Err(e);
+ }
+ };
+ let oids: Vec<String> = blobs.iter().map(|(_, sha)| sha.clone()).collect();
+ let contents = git::cat_file_batch(mirror, &oids)?;
let mut files = BTreeMap::new();
- for (path, _) in &blobs {
- let bytes = git::read_blob(mirror, commit, path)?;
- if bytes.len() > 4 * 1024 * 1024 || !looks_textual(&bytes) {
+ for (path, sha) in &blobs {
+ let bytes = contents
+ .get(sha)
+ .ok_or_else(|| Error::not_found(format!("{path} not in mirror")))?;
+ if bytes.len() > 4 * 1024 * 1024 || !looks_textual(bytes) {
continue;
}
- files.insert(path.clone(), String::from_utf8_lossy(&bytes).into_owned());
+ files.insert(path.clone(), String::from_utf8_lossy(bytes).into_owned());
}
Ok(Tree { blobs, files })
}