summaryrefslogtreecommitdiffstats
path: root/src/db/model.rs
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-19 17:09:59 +0000
committeraur-build <aur-build@localhost>2026-11-19 17:09:59 +0000
commite757979f1a2afdbe7146066345bb9acd19d3b151 (patch)
tree30d5f5fbccd25ea7bf01c5202684af463b74e7d3 /src/db/model.rs
parent94c318f13264bb3c00a9f3057ba2e1aafb57c9e4 (diff)
downloadaur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.tar.gz
aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.zip
comments: say why, not what
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.
Diffstat (limited to 'src/db/model.rs')
-rw-r--r--src/db/model.rs152
1 files changed, 50 insertions, 102 deletions
diff --git a/src/db/model.rs b/src/db/model.rs
index 3fa2840..84701d1 100644
--- a/src/db/model.rs
+++ b/src/db/model.rs
@@ -1,35 +1,25 @@
-//! Row types and small value objects that appear in JSON columns.
-
use serde::{Deserialize, Serialize};
use crate::hash;
-/// One resolved upstream VCS source (DESIGN.md §3, "Three things to pin").
-///
-/// The commit SHA alone is sufficient: a git commit transitively commits to its
-/// tree, and a gitlink in that tree commits to any submodule's commit.
+/// One resolved upstream VCS source (DESIGN.md §3). The commit SHA alone is
+/// sufficient: a git commit transitively commits to its tree, and a gitlink in
+/// that tree commits to any submodule's commit.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UpstreamPin {
- /// Index into the PKGBUILD `source=()` array.
pub index: usize,
pub url: String,
/// The ref we asked for: `HEAD`, a tag, or an explicit commit.
pub ref_: String,
- /// Branch the ref resolved to, when known.
pub branch: Option<String>,
- /// Resolved commit SHA. This is the pin.
+ /// The pin.
pub commit: String,
}
-/// A row of the Stage B cache (§5.2): the version that resolution produced,
-/// with the pins it was computed from.
-///
-/// This lives with the schema because the table lives here — the persistence
-/// layer must not name a type from the module that owns VCS probing, which is
-/// the dependency pointing the wrong way (§6 M-6). `watch::upstream::StageB`
-/// is this plus `cached`, and that extra field is the reason the two are not
-/// the same type: "was this answer a cache hit?" is a fact about the resolution
-/// that just happened, not a column.
+/// A row of the Stage B cache (§5.2): the version resolution produced, with the
+/// pins it was computed from. This lives with the schema because the table does —
+/// the persistence layer must not name a type from the module that owns VCS
+/// probing (§6 M-6).
#[derive(Debug, Clone)]
pub struct StageBCacheRow {
pub epoch: String,
@@ -55,20 +45,16 @@ pub struct SourceDigest {
/// sha256, or the resolved VCS commit for vcs sources.
pub digest: String,
pub size: u64,
- /// True when the PKGBUILD gave us no checksum to trust for this source —
- /// `SKIP`, a malformed digest, or nothing at all.
- ///
- /// It means that and nothing else (m-19). It used to be hardcoded `true` for
- /// VCS entries, where it reads as a warning the recipe never earned: a
- /// `-git` source has no checksum by design because the *pin* is the
- /// integrity. Ask [`SourceDigest::is_vcs`] when you need to know which of
- /// the two mechanisms protects an entry.
+ /// True when the PKGBUILD gave us no checksum to trust — `SKIP`, a malformed
+ /// digest, or nothing at all. It means that and nothing else (m-19): a `-git`
+ /// source has no checksum by design because the *pin* is the integrity. Ask
+ /// [`SourceDigest::is_vcs`] which mechanism protects an entry.
pub skip_declared: bool,
}
impl SourceDigest {
- /// True when this entry's integrity comes from a resolved commit rather than
- /// a content hash.
+ /// True when this entry's integrity comes from a resolved commit rather than a
+ /// content hash.
pub fn is_vcs(&self) -> bool {
matches!(self.kind.as_str(), "vcs" | "git" | "svn" | "hg" | "bzr")
}
@@ -93,35 +79,28 @@ pub struct Identity {
}
impl Identity {
- /// The hash that makes I3 a fact: two byte-identical inputs never produce
- /// two candidates, and any change to what becomes a byte in the artifact
- /// produces a new one.
- ///
- /// A digest of the canonical JSON of the identity tuple. This is the value
- /// an approval must echo: two candidates share an `identity_hash` only if
- /// every pin, digest and version in them is identical. A value that cannot
- /// be serialized is an error rather than a digest — a shared fallback digest
- /// would be the one way two identities could collide by accident.
+ /// The hash that makes I3 a fact: two byte-identical inputs never produce two
+ /// candidates, and any change to what becomes a byte in the artifact produces a
+ /// new one. This is the value an approval must echo; a value that cannot be
+ /// serialized is an error rather than a digest, because a shared fallback
+ /// digest would be the one way two identities could collide by accident.
pub fn hash(&self) -> crate::error::Result<String> {
Ok(format!("sha256:{}", hash::hex(hash::canonical_json(self)?.as_bytes())))
}
}
-/// The review state machine (§7.1).
-///
-/// A candidate is what a human decides on, and the decision is the one thing in
-/// this system that must never be overwritten by accident: an approval that
-/// silently replaced a rejection, or a superseded review resurrected, would
-/// break I2 and I3 without any symptom. So the states are an enum, and
+/// The review state machine (§7.1). A decision must never be overwritten by
+/// accident — an approval that silently replaced a rejection would break I2 and
+/// I3 without any symptom — so the states are an enum and
/// [`crate::db::candidates::resolve_in`] refuses a move the machine forbids.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CandidateState {
- /// Open: nobody has decided yet. The only state a reviewer can act on.
+ /// The only state a reviewer can act on.
PendingReview,
Approved,
Rejected,
- /// Frozen: a newer review of the same pkgbase took its place (§7.1).
+ /// A newer review of the same pkgbase took its place (§7.1).
Superseded,
/// Not approved because something it needs is missing (§10.4).
Blocked,
@@ -150,13 +129,11 @@ impl CandidateState {
CandidateState::ALL.iter().copied().find(|c| c.as_str() == s)
}
- /// The state a reviewer can still act on.
pub fn is_open(&self) -> bool {
*self == CandidateState::PendingReview
}
- /// May a candidate in this state be written to `to`? Re-writing the state it
- /// already has is a no-op, not a move.
+ /// Re-writing the state a row already has is a no-op, not a move.
pub fn can_transition(&self, to: CandidateState) -> bool {
use CandidateState::*;
if *self == to {
@@ -195,7 +172,6 @@ pub mod candidate_kind {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ReleaseState {
- /// In the served index.
Published,
/// Taken out of the index (§9 withdrawal); the row stays (§15).
Withdrawn,
@@ -222,8 +198,7 @@ impl ReleaseState {
ReleaseState::ALL.iter().copied().find(|r| r.as_str() == s)
}
- /// Withdrawal is the only move a release makes on its own; a failed-unbuilt
- /// release is a record of an attempt, and a published one is live.
+ /// Withdrawal is the only move a release makes on its own.
pub fn can_transition(&self, to: ReleaseState) -> bool {
use ReleaseState::*;
if *self == to {
@@ -243,8 +218,8 @@ impl std::fmt::Display for ReleaseState {
}
/// What the state enums below have in common: a closed set of column values,
-/// parsed where a row is read. `db::state_col` uses this to fail a row whose
-/// state the code does not know instead of defaulting it.
+/// parsed where a row is read, so `db::state_col` can fail an unknown state
+/// instead of defaulting it.
pub trait StateEnum: Copy + Sized {
/// The name of the machine, for the error message.
const KIND: &'static str;
@@ -272,17 +247,11 @@ impl_state_enum!(StepState, "build step");
impl_state_enum!(ReleaseState, "release");
impl_state_enum!(SubscriptionState, "subscription");
-/// The build state machine (§7.1, §8.2).
-///
-/// This used to be seven `&str` constants and a `set_state(&str)` that wrote any
-/// string a caller invented, so the machine existed only as `WHERE state IN
-/// (...)` clauses scattered across six modules — nothing could tell you that
-/// `succeeded → running` is nonsense. The enum is the machine: a state is one
-/// of these seven, it is parsed where a row is read, and `can_transition` is
-/// the only way a write happens.
+/// The build state machine (§7.1, §8.2). A state is one of these seven, it is
+/// parsed where a row is read, and `can_transition` is the only way a write
+/// happens.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum BuildState {
- /// Approved and waiting for a worker.
Queued,
/// Claimed by a worker with a lease (§8.2).
Leased,
@@ -306,8 +275,8 @@ impl BuildState {
BuildState::Cancelled,
];
- /// The text in the `state` column. The spelling is part of the schema: the
- /// reaper, the dispatcher and the UI all speak it.
+ /// The text in the `state` column — a spelling the reaper, dispatcher and UI
+ /// all speak.
pub fn as_str(&self) -> &'static str {
match self {
BuildState::Queued => "queued",
@@ -320,17 +289,14 @@ impl BuildState {
}
}
- /// The only way in from the database text. An unrecognised state is `None`,
- /// and the row boundary turns that into an error rather than a silent
- /// fallback: a state we cannot name is a state we must not act on.
+ /// An unrecognised state is `None`, and the row boundary turns that into an
+ /// error: a state we cannot name is one we must not act on.
pub fn parse(s: &str) -> Option<BuildState> {
BuildState::ALL.iter().copied().find(|b| b.as_str() == s)
}
- /// Nothing happens to a finished build by itself. `Succeeded` is final —
- /// the release is published and the row is history (§15). `Failed` and
- /// `Cancelled` end a worker's involvement, and only an explicit human
- /// requeue or resume moves them again ([`BuildState::can_transition`]).
+ /// Nothing happens to a finished build by itself; only an explicit human
+ /// requeue or resume moves it again.
pub fn is_terminal(&self) -> bool {
matches!(
self,
@@ -338,17 +304,11 @@ impl BuildState {
)
}
- /// May a row in this state be written to `to`?
- ///
- /// Writing the state a row already has is always allowed: it is a no-op, not
- /// a move. The step loop re-asserts `Running` at every step boundary (§8.3),
- /// and re-running a finished build must stay harmless rather than turn into
- /// an error.
- ///
- /// Everything else is refused by [`crate::db::builds::set_state`], and the
- /// refusals are the point: nothing revives a `Succeeded` build, and a build
- /// reaped back to `Queued` cannot be completed by the zombie worker that
- /// lost its lease — that refusal is the alarm.
+ /// Writing the state a row already has is always allowed: the step loop
+ /// re-asserts `Running` at every step boundary (§8.3). Everything else is
+ /// refused by [`crate::db::builds::set_state`], and the refusals are the point:
+ /// nothing revives a `Succeeded` build, and a build reaped back to `Queued`
+ /// cannot be completed by the zombie worker that lost its lease.
pub fn can_transition(&self, to: BuildState) -> bool {
use BuildState::*;
if *self == to {
@@ -356,16 +316,13 @@ impl BuildState {
}
match self {
// The dispatcher claims queued builds; `aur-build run <id>` runs one
- // in the foreground without a lease, so `Running` is legal from here
- // too. A dependency can be discovered before a worker ever starts.
+ // in the foreground without a lease.
Queued => matches!(to, Leased | Running | BlockedMissingDep | Cancelled),
Leased => matches!(to, Running | Queued | BlockedMissingDep | Succeeded | Failed | Cancelled),
Running => matches!(to, Queued | BlockedMissingDep | Succeeded | Failed | Cancelled),
BlockedMissingDep => matches!(to, Queued | Cancelled),
- // A failed build is resumed on the same row — that is I5 (the step
- // checkpoints say where to continue) and §8.4's human requeue.
+ // A failed build is resumed on the same row — that is I5 (§8.4).
Failed => matches!(to, Queued | Running),
- // §8.4: requeue is a human decision, not a policy.
Cancelled => to == Queued,
Succeeded => false,
}
@@ -381,7 +338,6 @@ impl BuildState {
.collect()
}
- /// The states the queue considers "in flight" for metrics and the index.
pub fn active() -> &'static [BuildState] {
&[
BuildState::Queued,
@@ -398,11 +354,9 @@ impl std::fmt::Display for BuildState {
}
}
-/// The step checkpoint state machine (§8.3, I5).
-///
-/// The checkpoint row is what a resumed build reads to decide what not to redo,
-/// so the rule that matters is that a completed checkpoint is frozen: a step
-/// recorded `succeeded` or `skipped` is never re-run and never rewritten.
+/// The step checkpoint state machine (§8.3, I5). The checkpoint row is what a
+/// resumed build reads to decide what not to redo, so a completed checkpoint is
+/// frozen.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StepState {
@@ -441,7 +395,7 @@ impl StepState {
}
/// I5: the resume skips a step in one of these two states, so nothing may
- /// move it again — a checkpoint that can be rewritten is not a checkpoint.
+ /// move it again.
pub fn is_done(&self) -> bool {
matches!(self, StepState::Succeeded | StepState::Skipped)
}
@@ -565,13 +519,10 @@ pub struct SourceEntry {
pub url: String,
/// Explicit filename (`::name` / `::` prefix handling).
pub filename: Option<String>,
- /// `#commit=` fragment.
pub commit: Option<String>,
- /// `#tag=` fragment.
pub tag: Option<String>,
- /// `#branch=` fragment.
pub branch: Option<String>,
- /// VCS kind if the url is prefixed `git+`, `svn+`, `hg+`, `bzr+`.
+ /// Set when the url is prefixed `git+`, `svn+`, `hg+`, `bzr+`.
pub vcs: Option<String>,
/// True for files shipped inside the AUR repo (no scheme).
pub local: bool,
@@ -610,21 +561,18 @@ pub struct Recipe {
pub install: Option<String>,
/// Names of the binary packages this pkgbase emits (split pkgbases have N).
pub pkgnames: Vec<String>,
- /// Per-package depends, for split pkgbases.
pub pkg_depends: Vec<(String, Vec<String>)>,
/// Raw PKGBUILD text, for display and diffing.
pub pkgbuild: String,
- /// Raw .SRCINFO text when it was present.
pub srcinfo: Option<String>,
/// True if `--skippgpcheck` appears in the PKGBUILD.
pub skipgpcheck: bool,
- /// Parsed `source=()` entries. Derived from `source`, so not serialized.
+ /// Derived from `source`, so not serialized.
#[serde(skip, default)]
pub source_entries: Vec<SourceEntry>,
}
impl Recipe {
- /// `epoch:pkgver-pkgrel` as displayed to consumers.
pub fn full_version(&self) -> String {
crate::pkgver::full_version(&self.epoch, &self.pkgver, &self.pkgrel)
}