1
1
use crate :: bstr:: BStr ;
2
- use gix_object:: tree:: EntryMode ;
3
2
4
3
use crate :: Id ;
5
4
5
+ /// Information about the diff performed to detect similarity of a [Rewrite][Event::Rewrite].
6
+ #[ derive( Debug , Default , Clone , Copy , Eq , PartialEq ) ]
7
+ pub struct DiffLineStats {
8
+ /// The amount of lines to remove from the source to get to the destination.
9
+ pub removals : u32 ,
10
+ /// The amount of lines to add to the source to get to the destination.
11
+ pub insertions : u32 ,
12
+ /// The amount of lines of the previous state, in the source.
13
+ pub before : u32 ,
14
+ /// The amount of lines of the new state, in the destination.
15
+ pub after : u32 ,
16
+ }
17
+
6
18
/// An event emitted when finding differences between two trees.
7
19
#[ derive( Debug , Clone , Copy ) ]
8
20
pub enum Event < ' a , ' old , ' new > {
@@ -33,12 +45,17 @@ pub enum Event<'a, 'old, 'new> {
33
45
/// The object id after the modification.
34
46
id : Id < ' new > ,
35
47
} ,
36
- /// Entries are considered renamed if they are not trees and they, according to some understanding of identity, appeared
37
- /// as [`Deletion`][Event::Deletion] in case of the previous source of the rename as well as [`Addition`][Event::Addition]
38
- /// acting as destination all the while [rename tracking][super::Platform::track_renames()] is enabled.
48
+ /// Entries are considered rewritten if they are not trees and they, according to some understanding of identity, were renamed
49
+ /// or copied.
50
+ /// In case of renames, this means they originally appeared as [`Deletion`][Event::Deletion] signalling their source as well as an
51
+ /// [`Addition`][Event::Addition] acting as destination.
52
+ ///
53
+ /// In case of copies, the `copy` flag is true and typically represents a perfect copy of a source was made.
54
+ ///
55
+ /// This variant can only be encountered if [rewrite tracking][super::Platform::track_rewrites()] is enabled.
39
56
///
40
57
/// Note that mode changes may have occurred as well, i.e. changes from executable to non-executable or vice-versa.
41
- Rename {
58
+ Rewrite {
42
59
/// The location of the source of the rename operation.
43
60
///
44
61
/// It may be empty if neither [file names][super::Platform::track_filename()] nor [file paths][super::Platform::track_path()]
@@ -48,40 +65,20 @@ pub enum Event<'a, 'old, 'new> {
48
65
source_entry_mode : gix_object:: tree:: EntryMode ,
49
66
/// The object id of the entry before the rename.
50
67
///
51
- /// Note that this is the same as `id` if we require the [similarity to be 100%][super::Renames ::percentage], but may
68
+ /// Note that this is the same as `id` if we require the [similarity to be 100%][super::Rewrites ::percentage], but may
52
69
/// be different otherwise.
53
70
source_id : Id < ' old > ,
54
-
71
+ /// Information about the diff we performed to detect similarity and match the `source_id` with the current state at `id`.
72
+ /// It's `None` if `source_id` is equal to `id`, as identity made an actual diff computation unnecessary.
73
+ diff : Option < DiffLineStats > ,
55
74
/// The mode of the entry after the rename.
56
75
/// It could differ but still be considered a rename as we are concerned only about content.
57
76
entry_mode : gix_object:: tree:: EntryMode ,
58
77
/// The object id after the rename.
59
78
id : Id < ' new > ,
60
- } ,
61
- /// This entry is considered to be a copy of another, according to some understanding of identity, as its source still exists.
62
- /// If the source wouldn't exist, it would be considered a [rename][Event::Rename].
63
- ///
64
- /// This variant may only occur if [rename tracking][super::Platform::track_renames()] is enabled, otherwise copies appear to be
65
- /// plain [additions][Event::Addition].
66
- Copy {
67
- /// The location of the source of the copy operation.
68
- ///
69
- /// It may be empty if neither [file names][super::Platform::track_filename()] nor [file paths][super::Platform::track_path()]
70
- /// are tracked.
71
- source_location : & ' a BStr ,
72
- /// The mode of the entry that is considered the source.
73
- source_entry_mode : gix_object:: tree:: EntryMode ,
74
- /// The object id of the source of the copy.
75
- ///
76
- /// Note that this is the same as `id` if we require the [similarity to be 100%][super::Renames::percentage], but may
77
- /// be different otherwise.
78
- source_id : Id < ' old > ,
79
-
80
- /// The mode of the entry after the copy, or the destination of it.
81
- /// It could differ but still be considered a copy as we are concerned only about content.
82
- entry_mode : gix_object:: tree:: EntryMode ,
83
- /// The object id after the copy, or the destination of it.
84
- id : Id < ' new > ,
79
+ /// If true, this rewrite is created by copy, and `source_id` is pointing to its source. Otherwise it's a rename, and `source_id`
80
+ /// points to a deleted object, as renames are tracked as deletions and additions of the same or similar content.
81
+ copy : bool ,
85
82
} ,
86
83
}
87
84
@@ -93,11 +90,13 @@ impl<'a, 'old, 'new> Event<'a, 'old, 'new> {
93
90
) -> Option < Result < crate :: object:: blob:: diff:: Platform < ' old , ' new > , crate :: object:: blob:: diff:: init:: Error > > {
94
91
match self {
95
92
Event :: Modification {
96
- previous_entry_mode : EntryMode :: BlobExecutable | EntryMode :: Blob ,
93
+ previous_entry_mode,
97
94
previous_id,
98
- entry_mode : EntryMode :: BlobExecutable | EntryMode :: Blob ,
95
+ entry_mode,
99
96
id,
100
- } => Some ( crate :: object:: blob:: diff:: Platform :: from_ids ( previous_id, id) ) ,
97
+ } if entry_mode. is_blob ( ) && previous_entry_mode. is_blob ( ) => {
98
+ Some ( crate :: object:: blob:: diff:: Platform :: from_ids ( previous_id, id) )
99
+ }
101
100
_ => None ,
102
101
}
103
102
}
@@ -108,8 +107,7 @@ impl<'a, 'old, 'new> Event<'a, 'old, 'new> {
108
107
Event :: Addition { entry_mode, .. }
109
108
| Event :: Deletion { entry_mode, .. }
110
109
| Event :: Modification { entry_mode, .. }
111
- | Event :: Rename { entry_mode, .. } => * entry_mode,
112
- Event :: Copy { entry_mode, .. } => * entry_mode,
110
+ | Event :: Rewrite { entry_mode, .. } => * entry_mode,
113
111
}
114
112
}
115
113
}
0 commit comments