deploy: Read unsigned size changes
CI / Check (pull_request) Successful in 5m8s
CI / Check (push) Successful in 4m45s

Newer Nix prints a closure growing as a bare size (`129.0 KiB`) without
a sign, and without colour when piped, so the size ended up in the
version column. Recognise a trailing size by its unit and sign it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #10.
This commit is contained in:
jackos1998andClaude Opus 5.5 committed 2026-11-27 18:30:59 +00:00
1 parent c516409f9a
commit 3415f9bb38
1 file changed
+25 -10
+25 -10
View File
@@ -415,26 +415,35 @@ impl Changes {
/// A line of `nix store diff-closures` (`name: 1.0 → 1.1, +3.4 KiB`) as package, version change
/// and size change.
fn package_cells(line: &str) -> [&str; 3] {
let Some((name, rest)) = line.split_once(": ") else { return [line, "", ""] };
fn package_cells(line: &str) -> [String; 3] {
let Some((name, rest)) = line.split_once(": ") else { return [line.into(), String::new(), String::new()] };
if let Some((version, size)) = rest.rsplit_once(", ")
&& let Some(size) = package_size(size)
{
return [name, version, size];
return [name.into(), version.into(), size];
}
if let Some(size) = package_size(rest) {
return [name, "unchanged", size];
return [name.into(), "unchanged".into(), size];
}
[name, rest, ""]
[name.into(), rest.into(), String::new()]
}
fn package_size(value: &str) -> Option<&str> {
// Some Nix versions indicate the direction with colour even on piped output.
value
/// A size change, signed. Nix versions differ: some sign increases, some only colour them (even
/// on piped output), and some do neither; decreases always have a sign.
fn package_size(value: &str) -> Option<String> {
let plain = value
.strip_prefix("\x1b[31;1m")
.or_else(|| value.strip_prefix("\x1b[32;1m"))
.and_then(|size| size.strip_suffix("\x1b[0m"))
.or_else(|| value.starts_with(['+', '-']).then_some(value))
.unwrap_or(value);
let (sign, size) = match plain.strip_prefix(['+', '-']) {
Some(size) => (&plain[..1], size),
None => ("+", plain),
};
let (number, unit) = size.split_once(' ')?;
let sized = number.parse::<f64>().is_ok() && ["B", "KiB", "MiB", "GiB", "TiB"].contains(&unit);
sized.then(|| format!("{sign}{size}"))
}
#[cfg(test)]
@@ -445,7 +454,13 @@ mod tests {
fn splits_package_lines() {
assert_eq!(package_cells("a: 1.0 → 1.1, +3.4 KiB"), ["a", "1.0 → 1.1", "+3.4 KiB"]);
assert_eq!(package_cells("b: -12.0 KiB"), ["b", "unchanged", "-12.0 KiB"]);
assert_eq!(package_cells("b: \x1b[31;1m12.0 KiB\x1b[0m"), ["b", "unchanged", "12.0 KiB"]);
assert_eq!(package_cells("b: \x1b[31;1m12.0 KiB\x1b[0m"), ["b", "unchanged", "+12.0 KiB"]);
assert_eq!(package_cells("b: 12.0 KiB"), ["b", "unchanged", "+12.0 KiB"]);
assert_eq!(
package_cells("slop: 0.1.0, 0.1.0-fish → 0.2.0, 0.2.0-fish, 129.0 KiB"),
["slop", "0.1.0, 0.1.0-fish → 0.2.0, 0.2.0-fish", "+129.0 KiB"]
);
assert_eq!(package_cells("c: 1.0, 2 KiB → 1.1"), ["c", "1.0, 2 KiB → 1.1", ""]);
assert_eq!(package_cells("b: 1.0 → 1.1, \x1b[32;1m-12.0 KiB\x1b[0m"), ["b", "1.0 → 1.1", "-12.0 KiB"]);
assert_eq!(package_cells("c: ∅ → 2.0"), ["c", "∅ → 2.0", ""]);
assert_eq!(package_cells("odd"), ["odd", "", ""]);