@@ -110,11 +110,25 @@ pub mod resource {
110110 }
111111 }
112112
113- /// Produce an iterator over lines, separated by LF or CRLF, suitable to create tokens using
114- /// [`imara_diff::intern::InternedInput`].
113+ /// Produce an iterator over lines, separated by LF or CRLF and thus keeping newlines.
114+ ///
115+ /// Note that this will cause unusual diffs if a file didn't end in newline but lines were added
116+ /// on the other side.
117+ ///
118+ /// Suitable to create tokens using [`imara_diff::intern::InternedInput`].
115119 pub fn intern_source ( & self ) -> imara_diff:: sources:: ByteLines < ' a , true > {
116120 crate :: blob:: sources:: byte_lines_with_terminator ( self . data . as_slice ( ) . unwrap_or_default ( ) )
117121 }
122+
123+ /// Produce an iterator over lines, but remove LF or CRLF.
124+ ///
125+ /// This produces the expected diffs when lines were added at the end of a file that didn't end
126+ /// with a newline before the change.
127+ ///
128+ /// Suitable to create tokens using [`imara_diff::intern::InternedInput`].
129+ pub fn intern_source_strip_newline_separators ( & self ) -> imara_diff:: sources:: ByteLines < ' a , false > {
130+ crate :: blob:: sources:: byte_lines ( self . data . as_slice ( ) . unwrap_or_default ( ) )
131+ }
118132 }
119133
120134 /// The data of a diffable resource, as it could be determined and computed previously.
@@ -228,8 +242,15 @@ pub mod prepare_diff {
228242
229243 impl < ' a > Outcome < ' a > {
230244 /// Produce an instance of an interner which `git` would use to perform diffs.
245+ ///
246+ /// Note that newline separators will be removed to improve diff quality
247+ /// at the end of files that didn't have a newline, but had lines added
248+ /// past the end.
231249 pub fn interned_input ( & self ) -> imara_diff:: intern:: InternedInput < & ' a [ u8 ] > {
232- crate :: blob:: intern:: InternedInput :: new ( self . old . intern_source ( ) , self . new . intern_source ( ) )
250+ crate :: blob:: intern:: InternedInput :: new (
251+ self . old . intern_source_strip_newline_separators ( ) ,
252+ self . new . intern_source_strip_newline_separators ( ) ,
253+ )
233254 }
234255 }
235256
0 commit comments