1use crate::tree::visit::Relation;
2use bstr::BStr;
3use gix_hash::ObjectId;
4use gix_object::bstr::BString;
5use std::collections::VecDeque;
67/// The error returned by [`tree()`](super::tree()).
8#[derive(Debug, thiserror::Error)]
9#[allow(missing_docs)]
10pub enum Error {
11#[error(transparent)]
12Find(#[from] gix_object::find::existing_iter::Error),
13#[error("The delegate cancelled the operation")]
14Cancelled,
15#[error(transparent)]
16EntriesDecode(#[from] gix_object::decode::Error),
17}
1819/// A trait to allow responding to a traversal designed to figure out the [changes](visit::Change)
20/// to turn tree A into tree B.
21pub trait Visit {
22/// Sets the full path in front of the queue so future calls to push and pop components affect it instead.
23fn pop_front_tracked_path_and_set_current(&mut self);
24/// Append a `component` to the end of a path, which may be empty.
25fn push_back_tracked_path_component(&mut self, component: &BStr);
26/// Append a `component` to the end of a path, which may be empty.
27fn push_path_component(&mut self, component: &BStr);
28/// Removes the last component from the path, which may leave it empty.
29fn pop_path_component(&mut self);
30/// Record a `change` and return an instruction whether to continue or not.
31 ///
32 /// The implementation may use the current path to lean where in the tree the change is located.
33fn visit(&mut self, change: visit::Change) -> visit::Action;
34}
3536/// The state required to run [tree-diffs](super::tree()).
37#[derive(Default, Clone)]
38pub struct State {
39/// A buffer for object data.
40pub buf1: Vec<u8>,
41/// Another buffer for object data.
42pub buf2: Vec<u8>,
43 trees: VecDeque<TreeInfoTuple>,
44 change_id: visit::ChangeId,
45}
4647type TreeInfoTuple = (Option<ObjectId>, Option<ObjectId>, Option<Relation>);
4849impl State {
50fn clear(&mut self) {
51self.trees.clear();
52self.buf1.clear();
53self.buf2.clear();
54self.change_id = 0;
55 }
56}
5758pub(super) mod function;
5960///
61pub mod visit;
6263/// A [Visit] implementation to record every observed change and keep track of the changed paths.
64#[derive(Clone, Debug)]
65pub struct Recorder {
66 path_deque: VecDeque<BString>,
67 path: BString,
68 location: Option<recorder::Location>,
69/// The observed changes.
70pub records: Vec<recorder::Change>,
71}
7273/// Useful for use as delegate implementing [`Visit`] to keep track of all seen changes. Useful for debugging or printing primarily.
74pub mod recorder;