brygge_decode_git/lib.rs
1//! brygge's **Git source decoder** (RFC 004): read a local Git object database and produce a
2//! [`brygge_ir::Ir`] — content, ancestry, and messages carried faithfully **as claims**, entirely
3//! *Stated* except opt-in, explicitly-marked *Derived* rename hints (which never replace the literal
4//! delete+create Git recorded).
5//!
6//! This is the **only** crate that links `gix` (RFC 009 D-1): [`brygge_ir`], the encoders, and the
7//! internal-verify path link none of it, so a target checks a brygge import on its own surface. gix is
8//! used with **no network feature** (INV-3) and the decoder executes **no source-provided code** — no
9//! hooks, filters/smudge, or submodule fetch (RFC 009 D-4). Output is byte-deterministic for the same
10//! repository + brygge version + options (`VF-1`), independent of physical packing.
11//!
12//! ```no_run
13//! let ir = brygge_decode_git::decode(
14//! std::path::Path::new("/path/to/repo/.git"),
15//! &brygge_decode_git::Options::default(),
16//! )?;
17//! println!("{}", brygge_ir::honesty::summary(&ir).render_human());
18//! # Ok::<(), brygge_decode_git::Error>(())
19//! ```
20//!
21//! **Public API (CR-20, minimal by design):** [`decode`], [`Options`], [`Error`], and
22//! [`decoder_version`] — everything a caller needs and nothing else; the `gix`-facing internals stay
23//! crate-private.
24
25#![forbid(unsafe_code)]
26#![warn(missing_docs)]
27
28mod decode;
29mod floor;
30mod open;
31mod options;
32
33pub use decode::{decode, decode_with_storage};
34pub use options::Options;
35
36/// The decoder id and version recorded into IR provenance (`PR-6`) and every derivation (`HO-1`).
37#[must_use]
38pub fn decoder_version() -> &'static str {
39 env!("CARGO_PKG_VERSION")
40}
41
42/// Everything the Git decoder can fail with. A refused source feature is a **typed outcome**
43/// ([`Error::FloorRefusal`]), not a panic and not an approximation (`FA-3`).
44#[derive(Debug)]
45#[non_exhaustive]
46pub enum Error {
47 /// The path is not a readable Git repository.
48 Open(String),
49 /// An object could not be read or decoded (a malformed or unreadable repository).
50 Read(String),
51 /// A source feature below the floor was hit; it is refused with a named reason (RFC 004 D-4, `FA-3`).
52 FloorRefusal {
53 /// The refused feature (e.g. `"submodule"`, `"shallow-clone"`).
54 feature: String,
55 /// Why it is refused rather than approximated.
56 reason: String,
57 },
58 /// A resource ceiling was hit (a malformed or hostile repository); refused rather than exhausting
59 /// the host (RFC 010, `brygge-03` T-8/C-2d).
60 ResourceLimit {
61 /// A noun phrase for what exceeded its ceiling (e.g. `"a blob"`, `"the commit count"`).
62 what: String,
63 /// The ceiling's value, with its unit (e.g. `"1073741824 bytes"`, `"256 levels"`).
64 ceiling: String,
65 },
66 /// The assembled IR violated a `brygge-ir` invariant (signals a decoder bug, not bad input).
67 Ir(brygge_ir::Error),
68 /// An [`Options`] field was given a value that cannot mean anything — refused before the repository
69 /// is even opened, rather than silently matching nothing (review 147/148, `carry_extra_namespaces`).
70 InvalidOptions(String),
71}
72
73impl std::fmt::Display for Error {
74 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75 match self {
76 Self::Open(m) => write!(f, "cannot open Git repository: {m}"),
77 Self::Read(m) => write!(f, "cannot read Git repository: {m}"),
78 Self::FloorRefusal { feature, reason } => {
79 write!(
80 f,
81 "refused Git feature '{feature}' below the floor: {reason}"
82 )
83 }
84 Self::ResourceLimit { what, ceiling } => {
85 write!(f, "refused: {what} exceeds brygge's ceiling ({ceiling})")
86 }
87 Self::Ir(e) => write!(f, "IR assembly failed: {e}"),
88 Self::InvalidOptions(m) => write!(f, "invalid options: {m}"),
89 }
90 }
91}
92
93impl std::error::Error for Error {
94 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
95 match self {
96 Self::Ir(e) => Some(e),
97 _ => None,
98 }
99 }
100}
101
102impl From<brygge_ir::Error> for Error {
103 fn from(e: brygge_ir::Error) -> Self {
104 Self::Ir(e)
105 }
106}