22#![ forbid( unsafe_code, rust_2018_idioms) ]
33
44///
5- pub mod tree {
6- use git_hash:: { oid, ObjectId } ;
5+ pub mod visit {
76 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- }
237
248 #[ derive( Default , Clone ) ]
259 pub struct State {
2610 buf1 : Vec < u8 > ,
2711 buf2 : Vec < u8 > ,
2812 }
2913
30- pub struct VisitChanges < ' a > ( Option < & ' a immutable:: Tree < ' a > > ) ;
14+ pub struct Changes < ' a > ( Option < & ' a immutable:: Tree < ' a > > ) ;
3115
32- impl < ' a , T > From < T > for VisitChanges < ' a >
16+ impl < ' a , T > From < T > for Changes < ' a >
3317 where
3418 T : Into < Option < & ' a immutable:: Tree < ' a > > > ,
3519 {
3620 fn from ( v : T ) -> Self {
37- VisitChanges ( v. into ( ) )
21+ Changes ( v. into ( ) )
3822 }
3923 }
4024
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+ }
5560 }
5661 }
5762
58- pub mod delegate {
63+ pub mod record {
5964 use git_hash:: ObjectId ;
6065 use git_object:: { bstr:: BStr , tree} ;
6166
@@ -88,29 +93,12 @@ pub mod tree {
8893 Cancel ,
8994 }
9095
91- pub trait Delegate {
96+ pub trait Record {
9297 fn update_path_component ( & mut self , component : PathComponent < ' _ > , mode : PathComponentMode ) ;
9398 fn pop_path_component ( & mut self ) ;
9499 fn record ( change : Change ) -> Action ;
95100 }
96101
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-
114102 #[ cfg( test) ]
115103 mod tests {
116104 use super :: * ;
@@ -125,5 +113,31 @@ pub mod tree {
125113 }
126114 }
127115 }
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 ;
129143}
0 commit comments