Skip to main content

decode

Function decode 

Source
pub fn decode(path: &Path, opts: &Options) -> Result<Ir, Error>
Expand description

Decode the Git repository at path into an Ir under opts.

§Errors

Error::Open if the path is not a readable repository; Error::FloorRefusal on a refused source feature (submodule, grafts, shallow, replace ref — RFC 004 D-4); Error::Read on a malformed object; Error::ResourceLimit on a resource ceiling (RFC 010); Error::Ir if the assembled IR violates an invariant.

Examples found in repository?
examples/decode_repo.rs (line 23)
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}