1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
//! Diff rendering (§6).
//!
//! A review is not one diff, it is a panel set, and **every** panel compares what
//! the accepted release recorded against what the candidate records now — never
//! "last seen". The rendered text is hashed into `diff_digest`, which is what
//! makes "we build exactly what was displayed, or nothing" (§7.1a) provable.
use crate::config::Config;
use crate::db::{self, *};
use crate::error::Result;
use crate::git;
#[derive(Debug, Clone)]
pub struct Panel {
pub name: &'static str,
pub title: &'static str,
/// Unified-diff text, or a readable rendering for panels that are not diffs.
pub body: String,
}
/// Everything a reviewer needs for one candidate.
pub fn panels(cfg: &Config, db: &Db, c: &CandidateRow, base: Option<&ReleaseRow>) -> Result<Vec<Panel>> {
let mut out = Vec::new();
let snap = db::snapshot_by_id(db, c.snapshot_id)?;
let mirror = std::path::PathBuf::from(
db::get_pkgbase_by_id(db, c.pkgbase_id)?
.and_then(|p| p.mirror_path)
.unwrap_or_else(|| cfg.mirror_path(&c.pkgbase).display().to_string()),
);
out.push(version_delta(base, c));
if let Some(base) = base {
if let Some(s) = &snap {
let range = format!("{}..{}", base.aur_commit, s.aur_commit);
let body = git::diff(&mirror, &range, &[]).unwrap_or_else(|e| {
format!("(diff unavailable: {e})\n\n--- base {}\n+++ candidate {}", base.aur_commit, s.aur_commit)
});
out.push(Panel { name: "recipe", title: "Recipe diff", body });
}
out.push(digest_delta(base, c));
out.push(pin_delta(base, c));
} else {
// §7.1b first_introduction: no diff pane. The full recipe is rendered
// readably instead, by the template.
out.push(Panel {
name: "recipe_full",
title: "Full recipe",
body: snap
.map(|s| s.srcinfo_json.clone())
.unwrap_or_else(|| "(no snapshot)".into()),
});
}
Ok(out)
}
fn version_delta(base: Option<&ReleaseRow>, c: &CandidateRow) -> Panel {
let mut body = String::new();
match base {
Some(b) => {
let (bv, cv) = (b.version(), c.version());
body.push_str(&format!("{bv} -> {cv}\n"));
let ord = crate::pkgver::vercmp(&bv, &cv);
if b.epoch != c.epoch {
body.push_str(&format!("epoch bump: {} -> {}\n", b.epoch, c.epoch));
}
if b.pkgrel != c.pkgrel && b.pkgver == c.pkgver {
body.push_str(&format!("pkgrel change: {} -> {}\n", b.pkgrel, c.pkgrel));
}
if crate::pkgver::is_downgrade(&bv, &cv) {
body.push_str("DOWNGRADE: AUR now offers a lower version than we serve\n");
}
let _ = ord;
}
None => body.push_str(&format!("first introduction: {}\n", c.version())),
}
Panel { name: "version", title: "Version delta", body }
}
fn digest_delta(base: &ReleaseRow, c: &CandidateRow) -> Panel {
let mut body = String::new();
let old: Vec<SourceDigest> = base.digests();
let new: Vec<SourceDigest> = c.digests();
for n in &new {
match old.iter().find(|o| o.index == n.index) {
Some(o) if o.digest != n.digest => {
body.push_str(&format!(
"! [{}] {} {} -> {}\n",
n.index, n.url, short(&o.digest), short(&n.digest)
));
}
Some(_) => body.push_str(&format!(" [{}] {} unchanged\n", n.index, n.url)),
None => body.push_str(&format!(
"+ [{}] {} NEW ({}{})\n",
n.index,
n.url,
n.kind,
if n.skip_declared { ", sha256sums=SKIP" } else { "" }
)),
}
}
for o in &old {
if !new.iter().any(|n| n.index == o.index) {
body.push_str(&format!("- [{}] {} REMOVED\n", o.index, o.url));
}
}
Panel { name: "digests", title: "Source digest delta", body }
}
fn pin_delta(base: &ReleaseRow, c: &CandidateRow) -> Panel {
let mut body = String::new();
let old: Vec<UpstreamPin> = base.pins();
let new: Vec<UpstreamPin> = c.pins();
if old.is_empty() && new.is_empty() {
body.push_str("no VCS sources\n");
}
for n in &new {
match old.iter().find(|o| o.index == n.index) {
Some(o) if o.commit != n.commit => {
body.push_str(&format!(
"! [{}] {} {} -> {} (branch {})\n",
n.index, n.url, short(&o.commit), short(&n.commit), n.branch.as_deref().unwrap_or("?")
));
}
Some(_) => body.push_str(&format!(" [{}] {} unchanged\n", n.index, n.url)),
None => body.push_str(&format!("+ [{}] {} at {}\n", n.index, n.url, short(&n.commit))),
}
}
Panel { name: "upstream", title: "Upstream delta", body }
}
fn short(s: &str) -> String {
if s.len() > 12 { s[..12].to_string() } else { s.to_string() }
}
/// Flatten the rendered panels into one canonical string.
pub fn render_text(ps: &[Panel]) -> String {
let mut s = String::new();
for p in ps {
s.push_str(&format!("### {}\n{}\n", p.title, p.body));
}
s
}
/// `diff_digest`: hash of the exact rendered diff the human was shown (§7.2).
pub fn diff_digest(ps: &[Panel]) -> String {
crate::hash::hex_str(&render_text(ps))
}
/// The recipe text a reviewer reads for a first introduction (§7.1b).
pub fn full_recipe_text(db: &Db, c: &CandidateRow) -> Result<String> {
let snap = db::snapshot_by_id(db, c.snapshot_id)?;
let snap = snap.ok_or_else(|| crate::error::Error::not_found("snapshot missing"))?;
let r: Recipe = serde_json::from_str(&snap.srcinfo_json).unwrap_or_default();
Ok(r.pkgbuild)
}
|