From e757979f1a2afdbe7146066345bb9acd19d3b151 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 17:09:59 +0000 Subject: comments: say why, not what MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every module-level `//!` header is gone, and the comments that remained either re-explained the line below them or had grown into paragraphs. Density went from one comment line per 6.7 lines of code to one per 10. 827 insertions against 2194 deletions across 86 files. What survived: the invariants (I1-I12), the design cross-references into DESIGN.md, and the notes recording a bug that was found and fixed — those are the comments that carry weight, because they answer a question the code cannot answer about itself. What did not: restating a function signature in prose, and narration of the statement underneath. --- src/watch/detect.rs | 82 ++++++++++++++++------------------------------------- 1 file changed, 24 insertions(+), 58 deletions(-) (limited to 'src/watch/detect.rs') diff --git a/src/watch/detect.rs b/src/watch/detect.rs index 6271dae..de1285e 100644 --- a/src/watch/detect.rs +++ b/src/watch/detect.rs @@ -1,11 +1,3 @@ -//! Detection: the recipe watcher pass for one pkgbase (§5.1, §5.2, §5.3). -//! -//! The decision that matters is *what counts as a change*. A candidate exists -//! only if something **publishable** changed — if the version string is -//! unchanged, `pacman` cannot offer an upgrade, so there is nothing to approve. -//! Those events become `notice` rows instead, and are never silently dropped -//! (I11). - use crate::config::Config; use crate::db::{self, *}; use crate::error::Result; @@ -18,19 +10,10 @@ use crate::watch::mirror::{read_tree, sync_mirror, Sync}; /// What one check of one pkgbase resulted in. /// -/// Four variants mirror [`Upsert`], and that is deliberate rather than lazy -/// duplication (n-2). `Upsert` answers a storage question — what did the -/// candidate write do — and belongs to `review::candidates`; `Outcome` answers -/// the watcher's question — what should happen next, including the cases that -/// never reach the candidate table at all (paused, gone, blocked, a -/// non-publishable notice). Folding them into one enum would put -/// `Paused`/`Blocked` next to `Collapsed` in the review module, where they mean -/// nothing, and would make every caller in the scheduler match on storage -/// vocabulary. `outcome_of` is the total, compiler-checked translation between -/// the two, and it is the only place that knows both. +/// Four variants mirror [`Upsert`] deliberately (n-2): `Upsert` answers the storage +/// question, `Outcome` the watcher's. `outcome_of` is the only place that knows both. #[derive(Debug, Clone)] pub enum Outcome { - /// Nothing moved at all. NoChange, /// The subscription is paused: we look at nothing and change nothing. Paused, @@ -61,11 +44,9 @@ pub struct CheckReport { pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result { let pb = get_pkgbase(db, name)? .ok_or_else(|| crate::error::Error::not_found(format!("pkgbase {name}")))?; - // A paused subscription is not observed at all. Pausing because a package is - // broken must not keep opening reviews nobody is going to act on, and it - // must not keep polling AUR either. The pause lives on the subscription, so - // that is what we consult. - let sub = db::get_subscription(db, name)?; + // A paused subscription is not observed at all: pausing must not keep opening + // reviews nobody will act on, nor keep polling AUR. + let sub = db::get_subscription(db, name)?;; let paused = sub.as_ref().map(|s| s.state == SubscriptionState::Paused).unwrap_or(false); if paused { return Ok(CheckReport { pkgbase: name.into(), head: String::new(), outcome: Outcome::Paused }); @@ -83,9 +64,8 @@ pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result { db::set_subscription_state(&db.writer, name, SubscriptionState::Orphaned)?; return Ok(CheckReport { pkgbase: name.into(), head: String::new(), outcome: Outcome::Gone }); } - // The cheap poll saved us a fetch, but we still have to look: a source - // can change its bytes without the recipe moving at all, and that is the - // digest-drift case §5.3 calls the single most valuable detection. + // The cheap poll saved a fetch, but we still have to look: a source can + // change its bytes without the recipe moving (§5.3). Sync::Unchanged { head } => head.clone(), Sync::Fetched { head, .. } | Sync::Cloned { head } => head.clone(), }; @@ -95,18 +75,13 @@ pub fn check_pkgbase(cfg: &Config, db: &Db, name: &str) -> Result { } /// When to look at this pkgbase again: its own interval if the subscription -/// carries one, otherwise the global default. -/// -/// The interval arrives as an argument because the caller read the subscription -/// row a moment ago to decide whether this pkgbase is paused (m-11); going back -/// to the database for a number the caller was holding was both a second query -/// and a second, possibly different, answer. +/// carries one, otherwise the global default. The interval is an argument because +/// the caller already read the subscription row (m-11). fn schedule_next(db: &Db, name: &str, poll_interval: Option) { let interval = poll_interval.unwrap_or_else(|| crate::db::setting_i64(db, "poll_interval", 86400)); let next = time::secs_ahead(interval); - // Best-effort: a missed "next check" stamp means the scheduler looks again - // a tick early, not that a change goes unnoticed — the tick re-selects by - // `next_check_at` and a NULL is due immediately. + // Best-effort: a missed stamp means the scheduler looks again a tick early, + // not that a change goes unnoticed. let _ = db::note_check(&db.writer, name, &next, None); } @@ -139,12 +114,11 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result = 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. + // A recipe with no VCS sources states its own version. let stage_a = if has_vcs { Some(crate::watch::upstream::probe(&recipe, &accepted_pins)?) } else { @@ -155,8 +129,8 @@ fn analyse(cfg: &Config, db: &Db, pb: &Pkgbase, head: &str) -> Result Result (r.epoch.clone(), r.pkgver.clone(), r.pkgrel.clone(), r.pins.clone()), None => (recipe.epoch.clone(), recipe.pkgver.clone(), recipe.pkgrel.clone(), Vec::new()), @@ -266,9 +240,7 @@ fn score( let _ = crate::review::candidates::set_risk(db, id, &a.level, &a.signals); } // Record now what would block the build later, using the same rule the plan - // step uses. A reviewer approving a package whose dependencies we have not - // published yet should see that before they approve it, not as a blocked - // build afterwards (§10.4). + // step uses, so a reviewer sees it before approving (§10.4). let missing = missing_deps(db, pb, recipe); let _ = crate::review::candidates::set_missing_deps(db, id, &missing); } @@ -306,9 +278,8 @@ fn outcome_of(up: Upsert) -> Outcome { } } -/// The version string did not move, so there is no review to open — but the -/// change is recorded, because a silently drifting tarball is exactly the kind -/// of thing that must not be invisible (§5.3). +/// The version string did not move, so there is no review to open — but the change +/// is recorded, because a silently drifting tarball must not be invisible (§5.3). fn non_publishable( db: &Db, pb: &Pkgbase, @@ -319,12 +290,8 @@ fn non_publishable( let old_digests: Vec = base.digests(); let new_digests: Vec = serde_json::from_str(&nc.source_digests_json).unwrap_or_default(); // 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. + // recipe drift. A VCS source's digest is its pin, so upstream moving shows up + // there too, but that is ordinary drift (§5.3). let vcs_indices: std::collections::BTreeSet = recipe .source_entries .iter() @@ -346,9 +313,8 @@ fn non_publishable( if digest_changed { // The single most valuable detection in the system: the artifact in the - // index was built from bytes upstream no longer serves, and the version - // string is unchanged. An approval would be useless (approving it would - // not let us publish anything), so this is an alert, not a review. + // index was built from bytes upstream no longer serves, and the version is + // unchanged. An approval would be useless, so this is an alert. let changed: Vec = changed_remote .iter() .map(|n| { -- cgit v1.2.3