Skip to main content

brygge_decode_git/
options.rs

1//! Decoder options (RFC 004 D-3, CF-01). Every option that can change the output is recorded into the
2//! IR provenance (`PR-5`), so the result stays reproducible and the judgement reviewable.
3
4use std::collections::BTreeMap;
5
6/// How the decoder should behave. The defaults are the maximally-honest ones: **no rename inference**
7/// (RFC 004 D-3), so a default import is entirely source-*Stated*.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub struct Options {
10    /// Infer renames from identical content and mark them **Derived** (RFC 004 D-3). **Off by default.**
11    /// When on, a delete+add of the *same blob* within one commit also emits a marked
12    /// `Derived(InferredRename)` hint — beside, never replacing, the literal delete+add. CLI flag
13    /// `--infer-renames` (handoff `cli-and-verify-handoff-v2.md`).
14    pub infer_renames: bool,
15    /// The similarity percentage recorded as the rename parameter. M1 detects only exact-content moves,
16    /// so this is `100`; it exists so the recorded parameter is explicit and future thresholds fit.
17    pub rename_threshold: u8,
18    /// Ref name prefixes to carry **besides** `refs/heads/*` and `refs/tags/*` (CR-05's own namespace
19    /// policy, otherwise unchanged): each becomes an `Other`-kind IR ref, named by the part of the ref
20    /// name after the prefix, and contributes a walk tip like any other carried ref. **Empty by
21    /// default**, and not exposed on brygge's CLI — this exists for RFC 019 D-6's own check
22    /// (`brygge encode git`'s internal comparison and `verify --against-target git`), which needs to see
23    /// a commit reachable only from `refs/brygge/other/*` (a `--branch-lines` dead/earlier-life root) to
24    /// compare it, not to change what an ordinary `decode git` import carries. A prefix must end with
25    /// `/`, or it matches no ref (never silently widened to a substring match).
26    pub carry_extra_namespaces: Vec<String>,
27}
28
29impl Default for Options {
30    fn default() -> Self {
31        Self {
32            infer_renames: false,
33            rename_threshold: 100,
34            carry_extra_namespaces: Vec::new(),
35        }
36    }
37}
38
39impl Options {
40    /// Render the options as canonical, sorted key→value strings for the IR provenance (`PR-5/CF-01`).
41    #[must_use]
42    pub fn as_params(&self) -> BTreeMap<String, String> {
43        let mut m = BTreeMap::new();
44        m.insert("infer_renames".to_string(), self.infer_renames.to_string());
45        if self.infer_renames {
46            m.insert(
47                "rename_algorithm".to_string(),
48                "exact-content-move".to_string(),
49            );
50            m.insert(
51                "rename_threshold".to_string(),
52                self.rename_threshold.to_string(),
53            );
54        }
55        if !self.carry_extra_namespaces.is_empty() {
56            m.insert(
57                "carry_extra_namespaces".to_string(),
58                self.carry_extra_namespaces.join(","),
59            );
60        }
61        m
62    }
63}