Showing the changes to git-diff (2 of 2 files). Show all
Unified · Split
| @@ -2,24 +2,8 @@ · 1 unmodified line | ||
| 2 | 2 | #![forbid(unsafe_code, rust_2018_idioms)] |
| 3 | 3 | |
| 4 | 4 | /// |
| 5 | −pub mod tree { | |
| 6 | − use git_hash::{oid, ObjectId}; | |
| 5 | +pub mod visit { | |
| 7 | 6 | use git_object::immutable; |
| 8 | − use quick_error::quick_error; | |
| 9 | − | |
| 10 | − const EMPTY_TREE: immutable::Tree<'static> = immutable::Tree::empty(); | |
| 11 | − | |
| 12 | − quick_error! { | |
| 13 | − #[derive(Debug)] | |
| 14 | − pub enum Error { | |
| 15 | − NotFound(oid: ObjectId) { | |
| 16 | − display("The object {} referenced by the tree was not found in the database", oid) | |
| 17 | − } | |
| 18 | − Cancelled { | |
| 19 | − display("The delegate cancelled the operation") | |
| 20 | − } | |
| 21 | − } | |
| 22 | − } | |
| 23 | 7 | |
| 24 | 8 | #[derive(Default, Clone)] |
| 25 | 9 | pub struct State { |
| @@ -27,35 +11,56 @@ pub mod tree { · 1 unmodified line | ||
| 27 | 11 | buf2: Vec<u8>, |
| 28 | 12 | } |
| 29 | 13 | |
| 30 | − pub struct VisitChanges<'a>(Option<&'a immutable::Tree<'a>>); | |
| 14 | + pub struct Changes<'a>(Option<&'a immutable::Tree<'a>>); | |
| 31 | 15 | |
| 32 | − impl<'a, T> From<T> for VisitChanges<'a> | |
| 16 | + impl<'a, T> From<T> for Changes<'a> | |
| 33 | 17 | where |
| 34 | 18 | T: Into<Option<&'a immutable::Tree<'a>>>, |
| 35 | 19 | { |
| 36 | 20 | fn from(v: T) -> Self { |
| 37 | − VisitChanges(v.into()) | |
| 21 | + Changes(v.into()) | |
| 38 | 22 | } |
| 39 | 23 | } |
| 40 | 24 | |
| 41 | − impl<'a> VisitChanges<'a> { | |
| 42 | − /// Returns the changes that need to be applied to `self` to get `other`. | |
| 43 | − pub fn to_obtain<LocateFn>( | |
| 44 | − &self, | |
| 45 | − _other: &git_object::immutable::Tree<'_>, | |
| 46 | − _state: &mut State, | |
| 47 | − _locate: LocateFn, | |
| 48 | − _delegate: &mut impl Delegate, | |
| 49 | − ) -> Result<(), Error> | |
| 50 | − where | |
| 51 | − LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::Object<'b>>, | |
| 52 | − { | |
| 53 | − let _this = *self.0.as_ref().unwrap_or(&&EMPTY_TREE); | |
| 54 | − todo!("changes tree to tree") | |
| 25 | + mod changes { | |
| 26 | + use crate::visit; | |
| 27 | + use git_hash::{oid, ObjectId}; | |
| 28 | + use git_object::immutable; | |
| 29 | + use quick_error::quick_error; | |
| 30 | + | |
| 31 | + const EMPTY_TREE: immutable::Tree<'static> = immutable::Tree::empty(); | |
| 32 | + | |
| 33 | + quick_error! { | |
| 34 | + #[derive(Debug)] | |
| 35 | + pub enum Error { | |
| 36 | + NotFound(oid: ObjectId) { | |
| 37 | + display("The object {} referenced by the tree was not found in the database", oid) | |
| 38 | + } | |
| 39 | + Cancelled { | |
| 40 | + display("The delegate cancelled the operation") | |
| 41 | + } | |
| 42 | + } | |
| 43 | + } | |
| 44 | + | |
| 45 | + impl<'a> visit::Changes<'a> { | |
| 46 | + /// Returns the changes that need to be applied to `self` to get `other`. | |
| 47 | + pub fn to_obtain_tree<LocateFn>( | |
| 48 | + &self, | |
| 49 | + _other: &git_object::immutable::Tree<'_>, | |
| 50 | + _state: &mut visit::State, | |
| 51 | + _locate: LocateFn, | |
| 52 | + _delegate: &mut impl visit::Record, | |
| 53 | + ) -> Result<(), Error> | |
| 54 | + where | |
| 55 | + LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::Object<'b>>, | |
| 56 | + { | |
| 57 | + let _this = *self.0.as_ref().unwrap_or(&&EMPTY_TREE); | |
| 58 | + todo!("changes tree to tree") | |
| 59 | + } | |
| 55 | 60 | } |
| 56 | 61 | } |
| 57 | 62 | |
| 58 | − pub mod delegate { | |
| 63 | + pub mod record { | |
| 59 | 64 | use git_hash::ObjectId; |
| 60 | 65 | use git_object::{bstr::BStr, tree}; |
| 61 | 66 | |
| @@ -88,29 +93,12 @@ pub mod tree { · 26 unmodified lines | ||
| 88 | 93 | Cancel, |
| 89 | 94 | } |
| 90 | 95 | |
| 91 | − pub trait Delegate { | |
| 96 | + pub trait Record { | |
| 92 | 97 | fn update_path_component(&mut self, component: PathComponent<'_>, mode: PathComponentMode); |
| 93 | 98 | fn pop_path_component(&mut self); |
| 94 | 99 | fn record(change: Change) -> Action; |
| 95 | 100 | } |
| 96 | 101 | |
| 97 | − #[derive(Clone, Default)] | |
| 98 | − pub struct Recorder; | |
| 99 | − | |
| 100 | − impl Delegate for Recorder { | |
| 101 | − fn update_path_component(&mut self, _component: PathComponent<'_>, _mode: PathComponentMode) { | |
| 102 | − todo!() | |
| 103 | − } | |
| 104 | − | |
| 105 | − fn pop_path_component(&mut self) { | |
| 106 | − todo!() | |
| 107 | − } | |
| 108 | − | |
| 109 | − fn record(_change: Change) -> Action { | |
| 110 | − todo!() | |
| 111 | − } | |
| 112 | − } | |
| 113 | − | |
| 114 | 102 | #[cfg(test)] |
| 115 | 103 | mod tests { |
| 116 | 104 | use super::*; |
| @@ -125,5 +113,31 @@ pub mod tree { · 8 unmodified lines | ||
| 125 | 113 | } |
| 126 | 114 | } |
| 127 | 115 | } |
| 128 | − pub use delegate::Delegate; | |
| 116 | + pub use record::Record; | |
| 117 | + | |
| 118 | + pub mod recorder { | |
| 119 | + use crate::visit::record; | |
| 120 | + | |
| 121 | + #[derive(Clone, Default)] | |
| 122 | + pub struct Recorder; | |
| 123 | + | |
| 124 | + impl record::Record for Recorder { | |
| 125 | + fn update_path_component( | |
| 126 | + &mut self, | |
| 127 | + _component: record::PathComponent<'_>, | |
| 128 | + _mode: record::PathComponentMode, | |
| 129 | + ) { | |
| 130 | + todo!() | |
| 131 | + } | |
| 132 | + | |
| 133 | + fn pop_path_component(&mut self) { | |
| 134 | + todo!() | |
| 135 | + } | |
| 136 | + | |
| 137 | + fn record(_change: record::Change) -> record::Action { | |
| 138 | + todo!() | |
| 139 | + } | |
| 140 | + } | |
| 141 | + } | |
| 142 | + pub use recorder::Recorder; | |
| 129 | 143 | } |
| @@ -41,11 +41,11 @@ mod with_tree { · 40 unmodified lines | ||
| 41 | 41 | .and_then(|tree| tree.into_tree()) |
| 42 | 42 | }; |
| 43 | 43 | |
| 44 | − git_diff::tree::VisitChanges::from(previous_tree.as_ref()).to_obtain( | |
| 44 | + git_diff::visit::Changes::from(previous_tree.as_ref()).to_obtain_tree( | |
| 45 | 45 | &main_tree, |
| 46 | − &mut git_diff::tree::State::default(), | |
| 46 | + &mut git_diff::visit::State::default(), | |
| 47 | 47 | |_oid, _buf| todo!("Actual lookup in db"), |
| 48 | − &mut git_diff::tree::delegate::Recorder::default(), | |
| 48 | + &mut git_diff::visit::Recorder::default(), | |
| 49 | 49 | )?; |
| 50 | 50 | Ok(()) |
| 51 | 51 | } |