1
1
use gix_hash:: ObjectId ;
2
- use gix_object:: { bstr:: BStr , tree, tree:: EntryMode } ;
2
+ use gix_object:: { tree, tree:: EntryMode } ;
3
+
4
+ /// A way to recognize and associate different [`Change`] instances.
5
+ ///
6
+ /// These are unique only within one diff operation.
7
+ pub type ChangeId = u32 ;
8
+
9
+ /// Identifies a relationship between this instance and another one.
10
+ #[ derive( Debug , Copy , Clone , PartialOrd , PartialEq , Ord , Eq , Hash ) ]
11
+ pub enum Relation {
12
+ /// This is a parent with the given ID, which will always have at least one child
13
+ /// assuming that empty directories are not allowed in valid trees.
14
+ /// It's also always a tree which is the start of a recursive deletion or addition.
15
+ ///
16
+ /// The change with this relation is always emitted first.
17
+ Parent ( ChangeId ) ,
18
+ /// This is a direct or indirect child, tree or not tree, of the parent with the given ID.
19
+ ChildOfParent ( ChangeId ) ,
20
+ }
3
21
4
22
/// Represents any possible change in order to turn one tree into another.
5
23
#[ derive( Debug , Clone , PartialOrd , PartialEq , Ord , Eq , Hash ) ]
@@ -10,13 +28,17 @@ pub enum Change {
10
28
entry_mode : tree:: EntryMode ,
11
29
/// The object id of the added entry.
12
30
oid : ObjectId ,
31
+ /// Possibly associate this change with another for hierarchical rename tracking.
32
+ relation : Option < Relation > ,
13
33
} ,
14
34
/// An entry was deleted, like the deletion of a file or directory.
15
35
Deletion {
16
36
/// The mode of the deleted entry.
17
37
entry_mode : tree:: EntryMode ,
18
38
/// The object id of the deleted entry.
19
39
oid : ObjectId ,
40
+ /// Possibly associate this change with another for hierarchical rename tracking.
41
+ relation : Option < Relation > ,
20
42
} ,
21
43
/// An entry was modified, e.g. changing the contents of a file adjusts its object id and turning
22
44
/// a file into a symbolic link adjusts its mode.
@@ -51,20 +73,28 @@ impl Change {
51
73
/// Return the current object id and tree entry mode of a change.
52
74
pub fn oid_and_entry_mode ( & self ) -> ( & gix_hash:: oid , EntryMode ) {
53
75
match self {
54
- Change :: Addition { oid, entry_mode }
55
- | Change :: Deletion { oid, entry_mode }
76
+ Change :: Addition {
77
+ oid,
78
+ entry_mode,
79
+ relation : _,
80
+ }
81
+ | Change :: Deletion {
82
+ oid,
83
+ entry_mode,
84
+ relation : _,
85
+ }
56
86
| Change :: Modification { oid, entry_mode, .. } => ( oid, * entry_mode) ,
57
87
}
58
88
}
59
89
}
60
90
61
- /// What to do after a [Change] was [recorded][ Visit::visit()] .
91
+ /// What to do after a [Change] was [recorded](super:: Visit::visit()) .
62
92
#[ derive( Default , Clone , Copy , PartialOrd , PartialEq , Ord , Eq , Hash ) ]
63
93
pub enum Action {
64
94
/// Continue the traversal of changes.
65
95
#[ default]
66
96
Continue ,
67
- /// Stop the traversal of changes, making this the last call to [visit(…)][ Visit::visit()] .
97
+ /// Stop the traversal of changes, making this the last call to [visit(…)](super:: Visit::visit()) .
68
98
Cancel ,
69
99
}
70
100
@@ -75,23 +105,6 @@ impl Action {
75
105
}
76
106
}
77
107
78
- /// A trait to allow responding to a traversal designed to figure out the [changes][Change]
79
- /// to turn tree A into tree B.
80
- pub trait Visit {
81
- /// Sets the full path path in front of the queue so future calls to push and pop components affect it instead.
82
- fn pop_front_tracked_path_and_set_current ( & mut self ) ;
83
- /// Append a `component` to the end of a path, which may be empty.
84
- fn push_back_tracked_path_component ( & mut self , component : & BStr ) ;
85
- /// Append a `component` to the end of a path, which may be empty.
86
- fn push_path_component ( & mut self , component : & BStr ) ;
87
- /// Removes the last component from the path, which may leave it empty.
88
- fn pop_path_component ( & mut self ) ;
89
- /// Record a `change` and return an instruction whether to continue or not.
90
- ///
91
- /// The implementation may use the current path to lean where in the tree the change is located.
92
- fn visit ( & mut self , change : Change ) -> Action ;
93
- }
94
-
95
108
#[ cfg( feature = "blob" ) ]
96
109
mod change_impls {
97
110
use gix_hash:: oid;
@@ -140,8 +153,8 @@ mod tests {
140
153
fn size_of_change ( ) {
141
154
let actual = std:: mem:: size_of :: < Change > ( ) ;
142
155
assert ! (
143
- actual <= 46 ,
144
- "{actual} <= 46 : this type shouldn't grow without us knowing"
156
+ actual <= 48 ,
157
+ "{actual} <= 48 : this type shouldn't grow without us knowing"
145
158
) ;
146
159
}
147
160
}
0 commit comments