| 160 | } |
| 161 | |
| 162 | fn main() -> Result<()> { |
| 163 | let mut args = std::env::args().skip(1); |
| 164 | let source = args |
| 165 | .next() |
| 166 | .context("usage: compact_semantic_codec <change-file-or-directory> [zstd-level:1..19]")?; |
| 167 | let level: i32 = args.next().map_or(Ok(3), |s| s.parse())?; |
| 168 | ensure!( |
| 169 | (1..=19).contains(&level) && args.next().is_none(), |
| 170 | "expected zstd level 1..19" |
| 171 | ); |
| 172 | ensure!(Path::new(&source).exists(), "source does not exist"); |
| 173 | let mut paths = Vec::new(); |
| 174 | collect(Path::new(&source), &mut paths)?; |
| 175 | paths.sort(); |
| 176 | ensure!(!paths.is_empty(), "no .change files found"); |
| 177 | let mut totals = Sizes::default(); |
| 178 | let mut rows = Vec::new(); |
| 179 | let mut failures = Vec::new(); |
| 180 | for path in paths { |
| 181 | match measure(&path, level).with_context(|| path.display().to_string()) { |
| 182 | Ok(row) => { |
| 183 | eprintln!( |
| 184 | "{}: semantic {} -> {} bytes; object {} -> {}; exact round-trip OK", |
| 185 | path.file_name().unwrap().to_string_lossy(), |
| 186 | row.sizes.original_semantic_bytes, |
| 187 | row.sizes.compact_semantic_bytes, |
| 188 | row.sizes.original_object_bytes, |
| 189 | row.sizes.projected_object_bytes |
| 190 | ); |
| 191 | totals.add(&row.sizes); |
| 192 | rows.push(row); |
| 193 | } |
| 194 | Err(error) => { |
| 195 | eprintln!("FAILED: {error:#}"); |
| 196 | failures.push(format!("{error:#}")); |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | println!( |
| 201 | "{}", |
| 202 | serde_json::to_string_pretty(&serde_json::json!({ |
| 203 | "experiment": "compact-semantic-v1-not-production", "zstd_level": level, |
| 204 | "notes": "Projected objects replace only the semantic payload; all graph/content/owner/dependency/signature bytes remain counted. New object hashes/signatures would be required. No Git-pack equivalence claimed.", |
| 205 | "totals": totals, "rows": rows, "failures": failures, |
| 206 | }))? |
| 207 | ); |
| 208 | ensure!( |
| 209 | failures.is_empty(), |
| 210 | "one or more inputs failed; results cover successful inputs only" |
| 211 | ); |
| 212 | Ok(()) |
| 213 | } |