1
1
use gix_diff:: tree;
2
- use gix_diff:: tree:: recorder:: Location ;
3
2
4
- use crate :: { bstr:: BStr , diff :: Rewrites , Id , Tree } ;
3
+ use crate :: { bstr:: BStr , Id , Tree } ;
5
4
6
5
/// Returned by the `for_each` function to control flow.
7
6
#[ derive( Default , Clone , Copy , PartialOrd , PartialEq , Ord , Eq , Hash ) ]
@@ -18,9 +17,9 @@ pub enum Action {
18
17
pub enum Change < ' a , ' old , ' new > {
19
18
/// An entry was added, like the addition of a file or directory.
20
19
Addition {
21
- /// The location of the file or directory, if [tracking](Platform ::track_path) was enabled.
20
+ /// The location of the file or directory, if [tracking](crate::diff::Options ::track_path) was enabled.
22
21
///
23
- /// It may be empty if neither [file names](Platform:: track_filename()) nor [file paths](Platform ::track_path())
22
+ /// It may be empty if neither [file names](crate::diff::Options:: track_filename()) nor [file paths](crate::diff::Options ::track_path())
24
23
/// are tracked.
25
24
location : & ' a BStr ,
26
25
/// The mode of the added entry.
@@ -33,7 +32,7 @@ pub enum Change<'a, 'old, 'new> {
33
32
} ,
34
33
/// An entry was deleted, like the deletion of a file or directory.
35
34
Deletion {
36
- /// The location of the file or directory, if [tracking](Platform ::track_path) was enabled.
35
+ /// The location of the file or directory, if [tracking](crate::diff::Options ::track_path) was enabled.
37
36
///
38
37
/// Otherwise, this value is always an empty path.
39
38
location : & ' a BStr ,
@@ -48,9 +47,9 @@ pub enum Change<'a, 'old, 'new> {
48
47
/// An entry was modified, e.g. changing the contents of a file adjusts its object id and turning
49
48
/// a file into a symbolic link adjusts its mode.
50
49
Modification {
51
- /// The location of the file or directory, if [tracking](Platform ::track_path) was enabled.
50
+ /// The location of the file or directory, if [tracking](crate::diff::Options ::track_path) was enabled.
52
51
///
53
- /// It may be empty if neither [file names](Platform:: track_filename()) nor [file paths](Platform ::track_path())
52
+ /// It may be empty if neither [file names](crate::diff::Options:: track_filename()) nor [file paths](crate::diff::Options ::track_path())
54
53
/// are tracked.
55
54
location : & ' a BStr ,
56
55
/// The mode of the entry before the modification.
@@ -70,13 +69,13 @@ pub enum Change<'a, 'old, 'new> {
70
69
///
71
70
/// In case of copies, the `copy` flag is true and typically represents a perfect copy of a source was made.
72
71
///
73
- /// This variant can only be encountered if [rewrite tracking](Platform ::track_rewrites()) is enabled.
72
+ /// This variant can only be encountered if [rewrite tracking](crate::diff::Options ::track_rewrites()) is enabled.
74
73
///
75
74
/// Note that mode changes may have occurred as well, i.e. changes from executable to non-executable or vice-versa.
76
75
Rewrite {
77
76
/// The location of the source of the rename operation.
78
77
///
79
- /// It may be empty if neither [file names](Platform:: track_filename()) nor [file paths](Platform ::track_path())
78
+ /// It may be empty if neither [file names](crate::diff::Options:: track_filename()) nor [file paths](crate::diff::Options ::track_path())
80
79
/// are tracked.
81
80
source_location : & ' a BStr ,
82
81
/// Identifies a relationship between the source and another source,
@@ -86,7 +85,7 @@ pub enum Change<'a, 'old, 'new> {
86
85
source_entry_mode : gix_object:: tree:: EntryMode ,
87
86
/// The object id of the entry before the rename.
88
87
///
89
- /// Note that this is the same as `id` if we require the [similarity to be 100%](Rewrites::percentage), but may
88
+ /// Note that this is the same as `id` if we require the [similarity to be 100%](gix_diff:: Rewrites::percentage), but may
90
89
/// be different otherwise.
91
90
source_id : Id < ' old > ,
92
91
/// Information about the diff we performed to detect similarity and match the `source_id` with the current state at `id`.
@@ -95,9 +94,9 @@ pub enum Change<'a, 'old, 'new> {
95
94
/// The mode of the entry after the rename.
96
95
/// It could differ but still be considered a rename as we are concerned only about content.
97
96
entry_mode : gix_object:: tree:: EntryMode ,
98
- /// The location of the destination file or directory, if [tracking](Platform ::track_path) was enabled.
97
+ /// The location of the destination file or directory, if [tracking](crate::diff::Options ::track_path) was enabled.
99
98
///
100
- /// It may be empty if neither [file names](Platform:: track_filename()) nor [file paths](Platform ::track_path())
99
+ /// It may be empty if neither [file names](crate::diff::Options:: track_filename()) nor [file paths](crate::diff::Options ::track_path())
101
100
/// are tracked.
102
101
location : & ' a BStr ,
103
102
/// The object id after the rename.
@@ -126,15 +125,14 @@ impl<'repo> Tree<'repo> {
126
125
///
127
126
/// Note that if a clone with `--filter=blob=none` was created, rename tracking may fail as it might
128
127
/// try to access blobs to compute a similarity metric. Thus, it's more compatible to turn rewrite tracking off
129
- /// using [`Platform ::track_rewrites()`].
128
+ /// using [`Options ::track_rewrites()`](crate::diff::Options::track_rewrites()) .
130
129
#[ allow( clippy:: result_large_err) ]
131
130
#[ doc( alias = "diff_tree_to_tree" , alias = "git2" ) ]
132
- pub fn changes < ' a > ( & ' a self ) -> Result < Platform < ' a , ' repo > , crate :: diff:: new_rewrites :: Error > {
131
+ pub fn changes < ' a > ( & ' a self ) -> Result < Platform < ' a , ' repo > , crate :: diff:: options :: init :: Error > {
133
132
Ok ( Platform {
134
133
state : Default :: default ( ) ,
135
134
lhs : self ,
136
- location : Some ( Location :: Path ) ,
137
- rewrites : self . repo . config . diff_renames ( ) ?. unwrap_or_default ( ) . into ( ) ,
135
+ options : crate :: diff:: Options :: from_configuration ( & self . repo . config ) ?,
138
136
} )
139
137
}
140
138
}
@@ -144,39 +142,13 @@ impl<'repo> Tree<'repo> {
144
142
pub struct Platform < ' a , ' repo > {
145
143
state : gix_diff:: tree:: State ,
146
144
lhs : & ' a Tree < ' repo > ,
147
- location : Option < Location > ,
148
- rewrites : Option < Rewrites > ,
145
+ options : crate :: diff:: Options ,
149
146
}
150
147
151
- /// Configuration
152
148
impl Platform < ' _ , ' _ > {
153
- /// Do not keep track of filepaths at all, which will leave all [`location`][Change::location] fields empty.
154
- pub fn no_locations ( & mut self ) -> & mut Self {
155
- self . location = Some ( Location :: FileName ) ;
156
- self
157
- }
158
-
159
- /// Keep track of file-names, which makes the [`location`][Change::location] field usable with the filename of the changed item.
160
- pub fn track_filename ( & mut self ) -> & mut Self {
161
- self . location = Some ( Location :: FileName ) ;
162
- self
163
- }
164
-
165
- /// Keep track of the entire path of a change, relative to the repository. (default).
166
- ///
167
- /// This makes the [`location`][Change::location] field usable.
168
- pub fn track_path ( & mut self ) -> & mut Self {
169
- self . location = Some ( Location :: Path ) ;
170
- self
171
- }
172
-
173
- /// Provide `None` to disable rewrite tracking entirely, or pass `Some(<configuration>)` to control to
174
- /// what extent rename and copy tracking is performed.
175
- ///
176
- /// Note that by default, the git configuration determines rewrite tracking and git defaults are used
177
- /// if nothing is configured, which turns rename tracking with 50% similarity on, while not tracking copies at all.
178
- pub fn track_rewrites ( & mut self , renames : Option < Rewrites > ) -> & mut Self {
179
- self . rewrites = renames;
149
+ /// Adjust diff options with `change_opts`.
150
+ pub fn options ( & mut self , change_opts : impl FnOnce ( & mut crate :: diff:: Options ) ) -> & mut Self {
151
+ change_opts ( & mut self . options ) ;
180
152
self
181
153
}
182
154
}
@@ -214,7 +186,7 @@ impl Platform<'_, '_> {
214
186
///
215
187
/// ### Performance Notes
216
188
///
217
- /// Be sure to forcefully disable [`track_rewrites(None)`](Self ::track_rewrites) to avoid
189
+ /// Be sure to forcefully disable [`track_rewrites(None)`](crate::diff::Options ::track_rewrites) to avoid
218
190
/// rename tracking, an operation that doesn't affect the statistics currently.
219
191
/// As diffed resources aren't cached, if highly repetitive blobs are expected, performance
220
192
/// may be diminished. In real-world scenarios where blobs are mostly unique, that's not an issue though.
0 commit comments