History

refactor

Sebastian Thiel committed 5 years ago

Commit 3c10d061 parent cbacca02 files · +71 −57Browse files

Showing the changes to git-diff/src (1 of 2 files). Show all

Unified · Split

git-diff/src/lib.rs+68−54
@@ -2,24 +2,8 @@ · 1 unmodified line
2#![forbid(unsafe_code, rust_2018_idioms)]2#![forbid(unsafe_code, rust_2018_idioms)]
3 3
4///4///
5pub mod tree {5pub mod visit {
6 use git_hash::{oid, ObjectId};
7 use git_object::immutable;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 #[derive(Default, Clone)]8 #[derive(Default, Clone)]
25 pub struct State {9 pub struct State {
@@ -27,35 +11,56 @@ pub mod tree { · 1 unmodified line
27 buf2: Vec<u8>,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 where17 where
34 T: Into<Option<&'a immutable::Tree<'a>>>,18 T: Into<Option<&'a immutable::Tree<'a>>>,
35 {19 {
36 fn from(v: T) -> Self {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> {25 mod changes {
42 /// Returns the changes that need to be applied to `self` to get `other`.26 use crate::visit;
43 pub fn to_obtain<LocateFn>(27 use git_hash::{oid, ObjectId};
44 &self,28 use git_object::immutable;
45 _other: &git_object::immutable::Tree<'_>,29 use quick_error::quick_error;
46 _state: &mut State,30
47 _locate: LocateFn,31 const EMPTY_TREE: immutable::Tree<'static> = immutable::Tree::empty();
48 _delegate: &mut impl Delegate,32
49 ) -> Result<(), Error>33 quick_error! {
50 where34 #[derive(Debug)]
51 LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::Object<'b>>,35 pub enum Error {
52 {36 NotFound(oid: ObjectId) {
53 let _this = *self.0.as_ref().unwrap_or(&&EMPTY_TREE);37 display("The object {} referenced by the tree was not found in the database", oid)
54 todo!("changes tree to tree")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 use git_hash::ObjectId;64 use git_hash::ObjectId;
60 use git_object::{bstr::BStr, tree};65 use git_object::{bstr::BStr, tree};
61 66
@@ -88,29 +93,12 @@ pub mod tree { · 26 unmodified lines
88 Cancel,93 Cancel,
89 }94 }
90 95
91 pub trait Delegate {96 pub trait Record {
92 fn update_path_component(&mut self, component: PathComponent<'_>, mode: PathComponentMode);97 fn update_path_component(&mut self, component: PathComponent<'_>, mode: PathComponentMode);
93 fn pop_path_component(&mut self);98 fn pop_path_component(&mut self);
94 fn record(change: Change) -> Action;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 #[cfg(test)]102 #[cfg(test)]
115 mod tests {103 mod tests {
116 use super::*;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}