use std::collections::VecDeque;
use bstr::BStr;
use gix_hash::ObjectId;
use gix_object::bstr::BString;
use crate::tree::visit::Relation;
#[derive(Debug)]
#[expect(missing_docs)]
pub enum Error {
Cancelled,
Failure(gix_error::Error),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Cancelled => f.write_str("The delegate cancelled the operation"),
Error::Failure(err) => std::fmt::Display::fmt(err, f),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Cancelled => None,
Error::Failure(err) => Some(err),
}
}
}
impl<E> From<gix_error::Exn<E>> for Error
where
E: std::error::Error + Send + Sync + 'static,
{
fn from(err: gix_error::Exn<E>) -> Self {
Error::Failure(err.into_error())
}
}
impl From<gix_error::Message> for Error {
fn from(err: gix_error::Message) -> Self {
Error::Failure(gix_error::Error::from_error(err))
}
}
pub trait Visit {
fn pop_front_tracked_path_and_set_current(&mut self);
fn push_back_tracked_path_component(&mut self, component: &BStr);
fn push_path_component(&mut self, component: &BStr);
fn pop_path_component(&mut self);
fn visit(&mut self, change: visit::Change) -> visit::Action;
}
#[derive(Default, Clone)]
pub struct State {
pub buf1: Vec<u8>,
pub buf2: Vec<u8>,
trees: VecDeque<TreeInfoTuple>,
change_id: visit::ChangeId,
}
type TreeInfoTuple = (Option<ObjectId>, Option<ObjectId>, Option<Relation>);
impl State {
fn clear(&mut self) {
self.trees.clear();
self.buf1.clear();
self.buf2.clear();
self.change_id = 0;
}
}
pub(super) mod function;
pub mod visit;
#[derive(Clone, Debug)]
pub struct Recorder {
path_deque: VecDeque<BString>,
path: BString,
location: Option<recorder::Location>,
pub records: Vec<recorder::Change>,
}
pub mod recorder;