@@ -51,24 +51,41 @@ impl<'old, 'new> Event<'old, 'new> {
51
51
}
52
52
}
53
53
54
+ ///
55
+ pub mod event {
56
+ ///
57
+ pub mod diff {
58
+ /// The error returned by [`Event::diff()`][super::Event::diff()].
59
+ #[ derive( Debug , thiserror:: Error ) ]
60
+ #[ allow( missing_docs) ]
61
+ pub enum Error {
62
+ #[ error( "Could not find the previous object to diff against" ) ]
63
+ FindPrevious ( #[ from] crate :: object:: find:: existing:: Error ) ,
64
+ #[ error( "Could not obtain diff algorithm from configuration" ) ]
65
+ DiffAlgorithm ( #[ from] crate :: config:: diff:: algorithm:: Error ) ,
66
+ }
67
+ }
68
+ }
69
+
54
70
impl < ' old , ' new > Event < ' old , ' new > {
55
71
/// Produce a platform for performing a line-diff, or `None` if this is not a [`Modification`][Event::Modification]
56
72
/// or one of the entries to compare is not a blob.
57
- pub fn diff ( & self ) -> Option < Result < DiffPlatform < ' old , ' new > , crate :: object:: find:: existing:: Error > > {
58
- // let algo = self.repo().config.diff_algorithm()?;
73
+ pub fn diff ( & self ) -> Option < Result < DiffPlatform < ' old , ' new > , event:: diff:: Error > > {
59
74
match self {
60
75
Event :: Modification {
61
76
previous_entry_mode : EntryMode :: BlobExecutable | EntryMode :: Blob ,
62
77
previous_id,
63
78
entry_mode : EntryMode :: BlobExecutable | EntryMode :: Blob ,
64
79
id,
65
80
} => match previous_id. object ( ) . and_then ( |old| id. object ( ) . map ( |new| ( old, new) ) ) {
66
- Ok ( ( old, new) ) => Some ( Ok ( DiffPlatform {
67
- old,
68
- new,
69
- algo : git_diff:: text:: Algorithm :: Myers ,
70
- } ) ) ,
71
- Err ( err) => Some ( Err ( err) ) ,
81
+ Ok ( ( old, new) ) => {
82
+ let algo = match self . repo ( ) . config . diff_algorithm ( ) {
83
+ Ok ( algo) => algo,
84
+ Err ( err) => return Some ( Err ( err. into ( ) ) ) ,
85
+ } ;
86
+ Some ( Ok ( DiffPlatform { old, new, algo } ) )
87
+ }
88
+ Err ( err) => Some ( Err ( err. into ( ) ) ) ,
72
89
} ,
73
90
_ => None ,
74
91
}
@@ -88,7 +105,7 @@ impl<'old, 'new> DiffPlatform<'old, 'new> {
88
105
git_diff:: text:: with (
89
106
self . old . data . as_bstr ( ) ,
90
107
self . new . data . as_bstr ( ) ,
91
- git_diff :: text :: Algorithm :: Myers , // TODO: use diff.algorithm
108
+ self . algo ,
92
109
// TODO: make use of `core.eol` and/or filters to do line-counting correctly. It's probably
93
110
// OK to just know how these objects are saved to know what constitutes a line.
94
111
git_diff:: text:: imara:: intern:: InternedInput :: new,
0 commit comments