@@ -51,24 +51,41 @@ impl<'old, 'new> Event<'old, 'new> {
5151 }
5252}
5353
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+
5470impl < ' old , ' new > Event < ' old , ' new > {
5571 /// Produce a platform for performing a line-diff, or `None` if this is not a [`Modification`][Event::Modification]
5672 /// 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 > > {
5974 match self {
6075 Event :: Modification {
6176 previous_entry_mode : EntryMode :: BlobExecutable | EntryMode :: Blob ,
6277 previous_id,
6378 entry_mode : EntryMode :: BlobExecutable | EntryMode :: Blob ,
6479 id,
6580 } => 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 ( ) ) ) ,
7289 } ,
7390 _ => None ,
7491 }
@@ -88,7 +105,7 @@ impl<'old, 'new> DiffPlatform<'old, 'new> {
88105 git_diff:: text:: with (
89106 self . old . data . as_bstr ( ) ,
90107 self . new . data . as_bstr ( ) ,
91- git_diff :: text :: Algorithm :: Myers , // TODO: use diff.algorithm
108+ self . algo ,
92109 // TODO: make use of `core.eol` and/or filters to do line-counting correctly. It's probably
93110 // OK to just know how these objects are saved to know what constitutes a line.
94111 git_diff:: text:: imara:: intern:: InternedInput :: new,
0 commit comments