Skip to main content

decode_repo/
decode_repo.rs

1//! Decode a Git repository into a brygge IR and print its fidelity report.
2//!
3//! Usage: `cargo run -p brygge-decode-git --example decode_repo -- [path-to-repo]`
4//! (defaults to the current directory). Add `--infer-renames` to turn on the opt-in, always-marked
5//! rename inference (RFC 004 D-3).
6
7fn main() {
8    let mut path = ".".to_string();
9    let mut infer_renames = false;
10    for arg in std::env::args().skip(1) {
11        if arg == "--infer-renames" {
12            infer_renames = true;
13        } else {
14            path = arg;
15        }
16    }
17
18    let opts = brygge_decode_git::Options {
19        infer_renames,
20        rename_threshold: 100,
21    };
22
23    match brygge_decode_git::decode(std::path::Path::new(&path), &opts) {
24        Ok(ir) => {
25            let bytes = brygge_ir::to_bytes(&ir);
26            println!(
27                "decoded {}: {} atom(s), {} ref(s), {}-byte artifact\n",
28                path,
29                ir.atoms.len(),
30                ir.refs.len(),
31                bytes.len()
32            );
33            print!("{}", brygge_ir::honesty::summary(&ir).render_human());
34            println!("\nfirst atoms (topological order):");
35            for atom in ir.atoms.iter().take(8) {
36                let hex = atom.id.to_hex();
37                let short = hex.get(..12).unwrap_or(hex.as_str());
38                let subject = atom
39                    .metadata
40                    .message
41                    .as_ref()
42                    .and_then(brygge_ir::Text::as_utf8)
43                    .unwrap_or("")
44                    .lines()
45                    .next()
46                    .unwrap_or("");
47                println!("  {short}  {subject}");
48            }
49        }
50        Err(e) => {
51            eprintln!("decode failed: {e}");
52            std::process::exit(1);
53        }
54    }
55}