11use gix_diff:: tree;
2- use gix_diff:: tree:: recorder:: Location ;
32
4- use crate :: { bstr:: BStr , diff :: Rewrites , Id , Tree } ;
3+ use crate :: { bstr:: BStr , Id , Tree } ;
54
65/// Returned by the `for_each` function to control flow.
76#[ derive( Default , Clone , Copy , PartialOrd , PartialEq , Ord , Eq , Hash ) ]
@@ -18,9 +17,9 @@ pub enum Action {
1817pub enum Change < ' a , ' old , ' new > {
1918 /// An entry was added, like the addition of a file or directory.
2019 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.
2221 ///
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())
2423 /// are tracked.
2524 location : & ' a BStr ,
2625 /// The mode of the added entry.
@@ -33,7 +32,7 @@ pub enum Change<'a, 'old, 'new> {
3332 } ,
3433 /// An entry was deleted, like the deletion of a file or directory.
3534 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.
3736 ///
3837 /// Otherwise, this value is always an empty path.
3938 location : & ' a BStr ,
@@ -48,9 +47,9 @@ pub enum Change<'a, 'old, 'new> {
4847 /// An entry was modified, e.g. changing the contents of a file adjusts its object id and turning
4948 /// a file into a symbolic link adjusts its mode.
5049 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.
5251 ///
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())
5453 /// are tracked.
5554 location : & ' a BStr ,
5655 /// The mode of the entry before the modification.
@@ -70,13 +69,13 @@ pub enum Change<'a, 'old, 'new> {
7069 ///
7170 /// In case of copies, the `copy` flag is true and typically represents a perfect copy of a source was made.
7271 ///
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.
7473 ///
7574 /// Note that mode changes may have occurred as well, i.e. changes from executable to non-executable or vice-versa.
7675 Rewrite {
7776 /// The location of the source of the rename operation.
7877 ///
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())
8079 /// are tracked.
8180 source_location : & ' a BStr ,
8281 /// Identifies a relationship between the source and another source,
@@ -86,7 +85,7 @@ pub enum Change<'a, 'old, 'new> {
8685 source_entry_mode : gix_object:: tree:: EntryMode ,
8786 /// The object id of the entry before the rename.
8887 ///
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
9089 /// be different otherwise.
9190 source_id : Id < ' old > ,
9291 /// 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> {
9594 /// The mode of the entry after the rename.
9695 /// It could differ but still be considered a rename as we are concerned only about content.
9796 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.
9998 ///
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())
101100 /// are tracked.
102101 location : & ' a BStr ,
103102 /// The object id after the rename.
@@ -126,15 +125,14 @@ impl<'repo> Tree<'repo> {
126125 ///
127126 /// Note that if a clone with `--filter=blob=none` was created, rename tracking may fail as it might
128127 /// 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()) .
130129 #[ allow( clippy:: result_large_err) ]
131130 #[ 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 > {
133132 Ok ( Platform {
134133 state : Default :: default ( ) ,
135134 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 ) ?,
138136 } )
139137 }
140138}
@@ -144,39 +142,13 @@ impl<'repo> Tree<'repo> {
144142pub struct Platform < ' a , ' repo > {
145143 state : gix_diff:: tree:: State ,
146144 lhs : & ' a Tree < ' repo > ,
147- location : Option < Location > ,
148- rewrites : Option < Rewrites > ,
145+ options : crate :: diff:: Options ,
149146}
150147
151- /// Configuration
152148impl 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 ) ;
180152 self
181153 }
182154}
@@ -214,7 +186,7 @@ impl Platform<'_, '_> {
214186 ///
215187 /// ### Performance Notes
216188 ///
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
218190 /// rename tracking, an operation that doesn't affect the statistics currently.
219191 /// As diffed resources aren't cached, if highly repetitive blobs are expected, performance
220192 /// may be diminished. In real-world scenarios where blobs are mostly unique, that's not an issue though.
0 commit comments