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::InvalidOptions if an opts field cannot mean anything (checked before the repository is opened); 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 24)
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}