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        carry_extra_namespaces: Vec::new(),
22    };
23
24    match brygge_decode_git::decode(std::path::Path::new(&path), &opts) {
25        Ok(ir) => {
26            let bytes = brygge_ir::to_bytes(&ir);
27            println!(
28                "decoded {}: {} atom(s), {} ref(s), {}-byte artifact\n",
29                path,
30                ir.atoms.len(),
31                ir.refs.len(),
32                bytes.len()
33            );
34            print!("{}", brygge_ir::honesty::summary(&ir).render_human());
35            println!("\nfirst atoms (topological order):");
36            for atom in ir.atoms.iter().take(8) {
37                let hex = atom.id.to_hex();
38                let short = hex.get(..12).unwrap_or(hex.as_str());
39                let subject = atom
40                    .metadata
41                    .message
42                    .as_ref()
43                    .and_then(brygge_ir::Text::as_utf8)
44                    .unwrap_or("")
45                    .lines()
46                    .next()
47                    .unwrap_or("");
48                println!("  {short}  {subject}");
49            }
50        }
51        Err(e) => {
52            eprintln!("decode failed: {e}");
53            std::process::exit(1);
54        }
55    }
56}