1use std::collections::VecDeque;
2
3use bstr::BStr;
4use gix_hash::ObjectId;
5use gix_object::bstr::BString;
6
7use crate::tree::visit::Relation;
8
9#[derive(Debug)]
11#[expect(missing_docs)]
12pub enum Error {
13 Cancelled,
14 Failure(gix_error::Error),
15}
16
17impl std::fmt::Display for Error {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 match self {
20 Error::Cancelled => f.write_str("The delegate cancelled the operation"),
21 Error::Failure(err) => std::fmt::Display::fmt(err, f),
22 }
23 }
24}
25
26impl std::error::Error for Error {
27 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28 match self {
29 Error::Cancelled => None,
30 Error::Failure(err) => Some(err),
31 }
32 }
33}
34
35impl<E> From<gix_error::Exn<E>> for Error
36where
37 E: std::error::Error + Send + Sync + 'static,
38{
39 fn from(err: gix_error::Exn<E>) -> Self {
40 Error::Failure(err.into_error())
41 }
42}
43
44impl From<gix_error::Message> for Error {
45 fn from(err: gix_error::Message) -> Self {
46 Error::Failure(gix_error::Error::from_error(err))
47 }
48}
49
50pub trait Visit {
53 fn pop_front_tracked_path_and_set_current(&mut self);
55 fn push_back_tracked_path_component(&mut self, component: &BStr);
57 fn push_path_component(&mut self, component: &BStr);
59 fn pop_path_component(&mut self);
61 fn visit(&mut self, change: visit::Change) -> visit::Action;
65}
66
67#[derive(Default, Clone)]
69pub struct State {
70 pub buf1: Vec<u8>,
72 pub buf2: Vec<u8>,
74 trees: VecDeque<TreeInfoTuple>,
75 change_id: visit::ChangeId,
76}
77
78type TreeInfoTuple = (Option<ObjectId>, Option<ObjectId>, Option<Relation>);
79
80impl State {
81 fn clear(&mut self) {
82 self.trees.clear();
83 self.buf1.clear();
84 self.buf2.clear();
85 self.change_id = 0;
86 }
87}
88
89pub(super) mod function;
90
91pub mod visit;
93
94#[derive(Clone, Debug)]
96pub struct Recorder {
97 path_deque: VecDeque<BString>,
98 path: BString,
99 location: Option<recorder::Location>,
100 pub records: Vec<recorder::Change>,
102}
103
104pub mod recorder;