diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 07:16:36 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 07:16:36 +0000 |
| commit | 0b3cb443e70b46ec61455255c3ddfc2a26997613 (patch) | |
| tree | 457d5e0bf3b1733b79829de3c146e1cabcc85e8c /src/watch/detect.rs | |
| parent | d7c386a703a9b69211d83854547218d6e1da9a51 (diff) | |
| download | aur-build-0b3cb443e70b46ec61455255c3ddfc2a26997613.tar.gz aur-build-0b3cb443e70b46ec61455255c3ddfc2a26997613.zip | |
watch: two-stage VCS watcher — ls-remote probe, pkgver() resolution, pin capture (§5.2)
Stage A probes every VCS source in source=() with git ls-remote,
respecting #commit/#tag/#branch fragments, and returns one UpstreamPin
per source. If the tip set equals the accepted release's pins, nothing
can have changed and Stage B never runs — the common case costs one
round trip per source and no clone. svn/hg have no cheap universal probe,
so they are reported as unprobed and force Stage B rather than being
silently treated as unchanged.
Stage B runs only on movement: it fetches into a persistent vcs_cache
(rather than re-cloning a multi-gigabyte upstream daily), runs makepkg
--vercheck, and captures the pins from the clone it already has. Results
are cached on (pkgbase, recipe_hash, upstream_tip) with a per-pkgbase
cooldown, and a process-wide slot cap bounds concurrent resolutions.
The resolved epoch:pkgver-pkgrel plus the pins go into identity_hash, so
a different commit is a different thing to approve.
Also fixes a misclassification the new path exposed: a VCS source's
digest is its pin, so upstream movement showed up as an integrity_alert.
Integrity events are now restricted to fixed downloads; VCS movement
under a frozen pkgver is pin_drift, as §5.2 specifies.
New fixtures git-multi (two upstreams) and git-tagged (#tag pin). 10
tests in tests/vcs.rs.
Diffstat (limited to 'src/watch/detect.rs')
| -rw-r--r-- | src/watch/detect.rs | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/src/watch/detect.rs b/src/watch/detect.rs index e00a2f9..d5f5c46 100644 --- a/src/watch/detect.rs +++ b/src/watch/detect.rs @@ -118,14 +118,47 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor let tree = read_tree(&mirror, head)?; let recipe = recipe_from_tree(&tree.files)?; let recipe_hash = tree.recipe_hash(); - let digests = resolve_sources(cfg, db, &mirror, head, &tree, &recipe, &[])?; - let pins: Vec<UpstreamPin> = Vec::new(); // P1 fills this in for VCS sources + + // §5.2, the two-stage funnel. Stage A is one `ls-remote` per VCS source and + // costs no clone; if the tip set is what the accepted release was built + // from, nothing can have changed and Stage B never runs. + let has_vcs = recipe.source_entries.iter().any(|e| e.is_vcs()); + let accepted_pins: Vec<UpstreamPin> = accepted.as_ref().map(|a| a.pins()).unwrap_or_default(); + // A recipe with no VCS sources states its own version; there is nothing to + // probe and nothing to resolve. + let stage_a = if has_vcs { + Some(crate::watch::upstream::probe(&recipe, &accepted_pins)?) + } else { + None + }; + let resolved = if !has_vcs { + None + } else if stage_a.as_ref().unwrap().needs_stage_b() { + crate::watch::upstream::resolve(cfg, db, pb, &recipe, &recipe_hash, stage_a.as_ref().unwrap())? + } else { + // Upstream has not moved. The version we serve is still the answer, and + // reusing its pins is what makes the next pass cheap too. + accepted.as_ref().map(|a| crate::watch::upstream::StageB { + epoch: a.epoch.clone(), + pkgver: a.pkgver.clone(), + pkgrel: a.pkgrel.clone(), + pins: accepted_pins.clone(), + cached: true, + }) + }; + // For a VCS package the literal `pkgver=` is frozen; the resolved one is the + // only version a consumer could actually install. + let (epoch, pkgver, pkgrel, pins) = match &resolved { + Some(r) => (r.epoch.clone(), r.pkgver.clone(), r.pkgrel.clone(), r.pins.clone()), + None => (recipe.epoch.clone(), recipe.pkgver.clone(), recipe.pkgrel.clone(), Vec::new()), + }; + let digests = resolve_sources(cfg, db, &mirror, head, &tree, &recipe, &pins)?; let identity = Identity { aur_commit: head.to_string(), - epoch: recipe.epoch.clone(), - pkgver: recipe.pkgver.clone(), - pkgrel: recipe.pkgrel.clone(), + epoch: epoch.clone(), + pkgver: pkgver.clone(), + pkgrel: pkgrel.clone(), upstream_pins: pins.clone(), source_digests: digests.clone(), }; @@ -141,9 +174,9 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result<CheckRepor let nc = NewCandidate { snapshot_id: snap_id, - epoch: recipe.epoch.clone(), - pkgver: recipe.pkgver.clone(), - pkgrel: recipe.pkgrel.clone(), + epoch: epoch.clone(), + pkgver: pkgver.clone(), + pkgrel: pkgrel.clone(), upstream_pins_json: serde_json::to_string(&pins)?, source_digests_json: serde_json::to_string(&digests)?, identity_hash: identity_hash.clone(), @@ -216,9 +249,19 @@ fn non_publishable( // A local source is part of the recipe: when its bytes move, that *is* the // recipe drift, not an integrity event. The integrity alert is specifically // "the bytes upstream serves no longer match what we built" (§5.3). + // A VCS source's digest *is* its pin, so upstream moving shows up there too + // — but that is ordinary drift, handled by the pin check below, not an + // integrity event. Integrity means "the bytes we built are gone and the + // version says nothing moved", which only applies to fixed downloads. + let vcs_indices: std::collections::BTreeSet<usize> = recipe + .source_entries + .iter() + .filter(|e| e.is_vcs()) + .map(|e| e.index) + .collect(); let changed_remote: Vec<&SourceDigest> = new_digests .iter() - .filter(|n| n.kind != "local") + .filter(|n| n.kind != "local" && !vcs_indices.contains(&n.index)) .filter(|n| match old_digests.iter().find(|o| o.index == n.index) { Some(o) => o.digest != n.digest, None => true, @@ -271,7 +314,6 @@ fn non_publishable( } // The recipe drifted under a static version: the maintainer probably forgot // to bump pkgrel, and the user should know. - let _ = recipe; db::put_notice_once( &db.writer, pb.id, |
